safe_signal_test.go 458 B

1234567891011121314151617181920212223242526
  1. package signal
  2. import (
  3. "testing"
  4. )
  5. func TestMultiNotifyDoesntCrash(t *testing.T) {
  6. sig := New(make(chan struct{}))
  7. sig.Notify()
  8. sig.Notify()
  9. // If code has reached here without crashing, the test has passed.
  10. }
  11. func TestWait(t *testing.T) {
  12. sig := New(make(chan struct{}))
  13. sig.Notify()
  14. select {
  15. case <-sig.Wait():
  16. // Test succeeds
  17. return
  18. default:
  19. // sig.Wait() should have been read from, because sig.Notify() wrote to it.
  20. t.Fail()
  21. }
  22. }