fork/gdu
git clone https://git.julia.blue/fork/gdu
fb46b4f
subvolume
1package common 2 3import ( 4"testing" 5"time" 6 7"github.com/stretchr/testify/assert" 8) 9 10func TestSignalGroupWait (t * testing.T ) { 11sg := make (SignalGroup ) 12done := make (chan struct {}) 13 14go func () { 15sg .Wait () 16done <- struct {}{} 17 }() 18 19// Give the goroutine time to block on Wait() 20time .Sleep (10 * time .Millisecond ) 21 22// Broadcast should unblock the Wait 23sg .Broadcast () 24 25// Verify goroutine exited 26select { 27case <- done : 28// Success 29case <- time .After (100 * time .Millisecond ): 30t .Fatal ("Wait() did not unblock after Broadcast()" ) 31 } 32} 33 34func TestSignalGroupBroadcast (t * testing.T ) { 35sg := make (SignalGroup ) 36 37// Broadcast should not panic on a fresh channel 38assert .NotPanics (t ,func () { 39sg .Broadcast () 40 }) 41} 42 43func TestSignalGroupWaitAfterBroadcast (t * testing.T ) { 44sg := make (SignalGroup ) 45sg .Broadcast () 46 47// Wait on already-closed channel should return immediately 48done := make (chan struct {}) 49go func () { 50sg .Wait () 51done <- struct {}{} 52 }() 53 54select { 55case <- done : 56// Success 57case <- time .After (100 * time .Millisecond ): 58t .Fatal ("Wait() did not return after already-broadcast channel" ) 59 } 60}