github.com/justinjmoses/evergreen@v0.0.0-20170530173719-1d50e381ff0d/agent/comm/timeout_test.go (about)

     1  package comm
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	. "github.com/smartystreets/goconvey/convey"
     8  )
     9  
    10  func TestTimeoutWatcher(t *testing.T) {
    11  	Convey("With a timeout watcher at a set interval", t, func() {
    12  		tw := TimeoutWatcher{}
    13  		tw.duration = time.Second
    14  		signalChan := make(chan Signal)
    15  		Convey("timeout should only get sent after Checkin() is not called "+
    16  			"within threshold", func() {
    17  			started := time.Now()
    18  			go tw.NotifyTimeouts(signalChan)
    19  			go func() {
    20  				for i := 0; i <= 40; i++ {
    21  					time.Sleep(100 * time.Millisecond)
    22  					tw.CheckIn()
    23  				}
    24  			}()
    25  			outSignal := <-signalChan
    26  			ended := time.Now()
    27  			So(outSignal, ShouldEqual, IdleTimeout)
    28  			So(ended, ShouldNotHappenWithin, 3900*time.Millisecond, started)
    29  		})
    30  	})
    31  }