projects
/
go-signalcontext.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
6a94085
)
Add a benchmark for precompleted context creation
author
Joe Wreschnig
<joe.wreschnig@gmail.com>
Sat, 13 Jun 2020 15:45:28 +0000
(17:45 +0200)
committer
Joe Wreschnig
<joe.wreschnig@gmail.com>
Sun, 14 Jun 2020 13:50:00 +0000
(15:50 +0200)
context_test.go
patch
|
blob
|
history
diff --git
a/context_test.go
b/context_test.go
index
a7b30a4
..
0fa10d7
100644
(file)
--- 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())
}
assert.Equal(t, Error{syscall.SIGUSR2}, ctx.Err())
}
-func Test
ImmediateCompletion
(t *testing.T) {
+func Test
Precompleted
(t *testing.T) {
parent, cancel := context.WithCancel(context.Background())
cancel()
<-parent.Done()
parent, cancel := context.WithCancel(context.Background())
cancel()
<-parent.Done()
@@
-120,3
+120,14
@@
func BenchmarkCanceledAsChild(b *testing.B) {
<-children[i].Done()
}
}
<-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()
+ }
+}