Skip to content

Commit

Permalink
test: test SerializePerf with cancelled context
Browse files Browse the repository at this point in the history
Test that pipestance.SerializePerf and SerializeState do not panic when
their context is canceled.
  • Loading branch information
adam-azarchs committed Aug 18, 2023
1 parent 541bc9f commit 61fafb1
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions martian/core/runloop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ func TestPipestanceRun(t *testing.T) {
for {
flushChannel(rt.LocalJobManager.Done())
done, hadProgress := loopBody(t, pipestance)

if done {
break
}
Expand All @@ -150,6 +151,20 @@ func TestPipestanceRun(t *testing.T) {
}
}
}

// Test that serializing the state works correctly with a canceled context.
// Coverage from this call is going to be racy, of course, but it's very
// difficult to get coverage more reliably here.
// This essentially simulates the effect of an API client querying the
// state while the pipestance is running.
ch := make(chan interface{}, 2)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Microsecond)
go func() { ch <- pipestance.SerializePerf(ctx) }()
go func() { ch <- pipestance.SerializeState(ctx) }()
<-ch
<-ch
cancel()

nodeInfos := pipestance.SerializeState(context.Background())
if len(nodeInfos) != 22 {
t.Errorf("node count %d != 22", len(nodeInfos))
Expand Down

0 comments on commit 61fafb1

Please sign in to comment.