mirror of
https://github.com/cloudflare/cloudflared.git
synced 2025-07-27 18:39:58 +00:00
TUN-1562: Refactor connectedSignal to be safe to close multiple times
This commit is contained in:
25
signal/safe_signal_test.go
Normal file
25
signal/safe_signal_test.go
Normal 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()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user