// NewTest creates a new Waker to be used in tests, returning it and a function to trigger a wakeup.  The constructor parameter says how many wakees are expected in the first pass.
NewTest creates a new Waker to be used in tests, returning it and a function to trigger a wakeup.  The constructor parameter says how many wakees are expected in the first pass.
// NewTest creates a new Waker to be used in tests returning it and a function to trigger a wakeup . The constructor parameter says how many wakees are expected in the first pass .
func NewTest(ctx context.Context, n int) (Waker, WakeFunc) {
	t := &testWaker{
		ctx:        ctx,
		n:          n,
		wakeeReady: make(chan struct{}),
		wakeeDone:  make(chan struct{}),
		wait:       make(chan struct{}),
		wake:       make(chan struct{}),
	}
	initDone := make(chan struct{})
	go func() {
		defer close(initDone)
		for i := 0; i < t.n; i++ {
			<-t.wakeeDone
		}
	}()
	wakeFunc := func(after int) {
		<-initDone
		glog.InfoDepth(1, "TestWaker yielding to Wakee")
		for i := 0; i < t.n; i++ {
			t.wait <- struct{}{}
		}
		glog.Infof("waiting for %d wakees to get the wake chan", t.n)
		for i := 0; i < t.n; i++ {
			<-t.wakeeReady
		}
		t.broadcastWakeAndReset()
		glog.Infof("waiting for %d wakees to return to Wake", after)
		for i := 0; i < after; i++ {
			<-t.wakeeDone
		}
		t.n = after
		glog.InfoDepth(1, "Wakee yielding to TestWaker")
	}
	return t, wakeFunc
}
func NewTest ( ctx context . Context , n int ) ( Waker , WakeFunc ) { t := & testWaker { ctx : ctx , n : n , wakeeReady : make ( chan struct { } ) , wakeeDone : make ( chan struct { } ) , wait : make ( chan struct { } ) , wake : make ( chan struct { } ) , } initDone := make ( chan struct { } ) go func ( ) { defer close ( initDone ) for i := 0 ; i < t . n ; i ++ { <- t . wakeeDone } } ( ) wakeFunc := func ( after int ) { <- initDone glog . InfoDepth ( 1 , " " ) for i := 0 ; i < t . n ; i ++ { t . wait <- struct { } { } } glog . Infof ( " " , t . n ) for i := 0 ; i < t . n ; i ++ { <- t . wakeeReady } t . broadcastWakeAndReset ( ) glog . Infof ( " " , after ) for i := 0 ; i < after ; i ++ { <- t . wakeeDone } t . n = after glog . InfoDepth ( 1 , " " ) } return t , wakeFunc }
NewTest creates a new Waker to be used in tests, returning it and a function to trigger a wakeup.
NewTest creates a new Waker to be used in tests returning it and a function to trigger a wakeup .
// Now wakeFunc blocks here