helper/signalwrapper: more tests

This commit is contained in:
Mitchell Hashimoto 2016-08-15 20:58:48 -07:00
parent bdcea55117
commit d8337920f9
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
1 changed files with 26 additions and 0 deletions

View File

@ -66,3 +66,29 @@ func TestWrapped_cancel(t *testing.T) {
}
}
}
func TestWrapped_waitAndCancel(t *testing.T) {
errVal := errors.New("hi")
readyCh := make(chan struct{})
f := func(ch <-chan struct{}) error {
<-ch
<-readyCh
return errVal
}
wrapped := Run(f)
// Run both cancel and wait and wait some time to hope they're
// scheduled. We could _ensure_ both are scheduled by using some
// more lines of code but this is probably just good enough.
go wrapped.Cancel()
go wrapped.Wait()
close(readyCh)
time.Sleep(10 * time.Millisecond)
// Check it by calling Cancel again
err := wrapped.Cancel()
if err != errVal {
t.Fatalf("bad: %#v", err)
}
}