X-Git-Url: https://git.korewanetadesu.com/?p=go-signalcontext.git;a=blobdiff_plain;f=context_test.go;h=0fa10d79e8606da743a75df491607544c39e1618;hp=a7b30a480a1e854edf6501e455a2a6006103de05;hb=6d43b73af18d23a4cab88dccf8d93a8eb423d2ed;hpb=8cf685c73e37c718d1dcfe057caad080196f3e18 diff --git a/context_test.go b/context_test.go index a7b30a4..0fa10d7 100644 --- a/context_test.go +++ b/context_test.go @@ -64,7 +64,7 @@ func TestCancelAfterSignal(t *testing.T) { assert.Equal(t, Error{syscall.SIGUSR2}, ctx.Err()) } -func TestImmediateCompletion(t *testing.T) { +func TestPrecompleted(t *testing.T) { parent, cancel := context.WithCancel(context.Background()) cancel() <-parent.Done() @@ -120,3 +120,14 @@ func BenchmarkCanceledAsChild(b *testing.B) { <-children[i].Done() } } + +func BenchmarkPrecompleted(b *testing.B) { + parent, cancel := context.WithCancel(context.Background()) + cancel() + <-parent.Done() + b.ResetTimer() + for i := 0; i < b.N; i++ { + ctx := UntilSignal(parent, syscall.SIGUSR2) + <-ctx.Done() + } +}