diff --git a/splitter/simple/impl.go b/splitter/simple/impl.go index 11fd0e9..fea1db2 100644 --- a/splitter/simple/impl.go +++ b/splitter/simple/impl.go @@ -315,6 +315,9 @@ func (m *SimpleMapper) OnJob(job proxy.Job) { } m.mu.Lock() m.prevJob = m.currentJob + if m.prevJob.ClientID != job.ClientID { + m.prevJob = proxy.Job{} + } m.currentJob = job m.stopped = false m.idleAt = time.Time{} diff --git a/splitter/simple/impl_test.go b/splitter/simple/impl_test.go index 2f47e44..e703217 100644 --- a/splitter/simple/impl_test.go +++ b/splitter/simple/impl_test.go @@ -293,6 +293,37 @@ func TestSimpleMapper_OnResultAccepted_CustomDiffUsesEffectiveDifficulty(t *test } } +func TestSimpleMapper_OnJob_PreservesPreviousJobForSamePoolSession_Good(t *testing.T) { + mapper := &SimpleMapper{ + currentJob: proxy.Job{JobID: "job-1", Blob: "blob-1", ClientID: "session-a"}, + } + + mapper.OnJob(proxy.Job{JobID: "job-2", Blob: "blob-2", ClientID: "session-a"}) + + if mapper.currentJob.JobID != "job-2" { + t.Fatalf("expected current job to roll forward, got %q", mapper.currentJob.JobID) + } + if mapper.prevJob.JobID != "job-1" { + t.Fatalf("expected previous job to remain available within one pool session, got %q", mapper.prevJob.JobID) + } +} + +func TestSimpleMapper_OnJob_ResetsPreviousJobAcrossPoolSessions_Ugly(t *testing.T) { + mapper := &SimpleMapper{ + currentJob: proxy.Job{JobID: "job-1", Blob: "blob-1", ClientID: "session-a"}, + prevJob: proxy.Job{JobID: "job-0", Blob: "blob-0", ClientID: "session-a"}, + } + + mapper.OnJob(proxy.Job{JobID: "job-2", Blob: "blob-2", ClientID: "session-b"}) + + if mapper.currentJob.JobID != "job-2" { + t.Fatalf("expected current job to advance after session change, got %q", mapper.currentJob.JobID) + } + if mapper.prevJob.JobID != "" { + t.Fatalf("expected previous job history to reset on new pool session, got %q", mapper.prevJob.JobID) + } +} + func TestSimpleMapper_Submit_InvalidJob_Good(t *testing.T) { minerConn, clientConn := net.Pipe() defer minerConn.Close()