idle_test.go raw

   1  package bridge
   2  
   3  import (
   4  	"testing"
   5  	"time"
   6  )
   7  
   8  // TestNodeDataIdle: the idle bound is measured on data the node produced for the client, not
   9  // on frames from the node. A ping every couple of minutes otherwise keeps a wedged session
  10  // looking alive for ever, which is exactly how a silent node was mistaken for a slow one.
  11  func TestNodeDataIdle(t *testing.T) {
  12  	now := time.Now()
  13  
  14  	if nodeDataIdle(now.Add(-3*time.Minute).UnixNano(), now, 2*time.Minute) != true {
  15  		t.Fatal("three minutes without data, a two-minute bound: not idle")
  16  	}
  17  
  18  	if nodeDataIdle(now.Add(-time.Minute).UnixNano(), now, 2*time.Minute) != false {
  19  		t.Fatal("one minute without data, a two-minute bound: idle")
  20  	}
  21  
  22  	if nodeDataIdle(now.Add(-time.Hour).UnixNano(), now, 0) != false {
  23  		t.Fatal("a zero bound expired")
  24  	}
  25  }
  26