Add project documentation and licensing
[go-signalcontext.git] / context_test.go
index a7b30a4..bc755a4 100644 (file)
@@ -64,7 +64,7 @@ func TestCancelAfterSignal(t *testing.T) {
        assert.Equal(t, Error{syscall.SIGUSR2}, ctx.Err())
 }
 
-func TestImmediateCompletion(t *testing.T) {
+func TestPrecanceled(t *testing.T) {
        parent, cancel := context.WithCancel(context.Background())
        cancel()
        <-parent.Done()
@@ -75,7 +75,7 @@ func TestImmediateCompletion(t *testing.T) {
        case _, ok := <-ctx.Done():
                assert.False(t, ok, "Done() should be closed")
        default:
-               assert.False(t, true, "context should be complete")
+               assert.False(t, true, "Done() should be closed")
        }
        assert.Equal(t, context.Canceled, ctx.Err())
 }
@@ -120,3 +120,14 @@ func BenchmarkCanceledAsChild(b *testing.B) {
                <-children[i].Done()
        }
 }
+
+func BenchmarkPrecanceled(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()
+       }
+}