TUN-1562: Refactor connectedSignal to be safe to close multiple times

This commit is contained in:
Adam Chalmers
2019-03-04 13:48:56 -06:00
parent fea3569956
commit 073c5bfdaa
7 changed files with 85 additions and 25 deletions

View File

@@ -0,0 +1,25 @@
package signal
import (
"testing"
)
func TestMultiNotifyDoesntCrash(t *testing.T) {
sig := New(make(chan struct{}))
sig.Notify()
sig.Notify()
// If code has reached here without crashing, the test has passed.
}
func TestWait(t *testing.T) {
sig := New(make(chan struct{}))
sig.Notify()
select {
case <-sig.Wait():
// Test succeeds
return
default:
// sig.Wait() should have been read from, because sig.Notify() wrote to it.
t.Fail()
}
}