gopkg.in/dedis/onet.v2@v2.0.0-20181115163211-c8f3724038a7/simul/manage/count_test.go (about) 1 package manage 2 3 import ( 4 "testing" 5 "time" 6 7 "gopkg.in/dedis/onet.v2" 8 "gopkg.in/dedis/onet.v2/log" 9 "gopkg.in/dedis/onet.v2/network" 10 ) 11 12 // Tests a 2-node system 13 func TestCount(t *testing.T) { 14 local := onet.NewLocalTest(tSuite) 15 nbrNodes := 2 16 _, _, tree := local.GenTree(nbrNodes, true) 17 defer local.CloseAll() 18 19 pi, err := local.StartProtocol("Count", tree) 20 if err != nil { 21 t.Fatal("Couldn't start protocol:", err) 22 } 23 protocol := pi.(*ProtocolCount) 24 // https://stackoverflow.com/questions/17573190/how-to-multiply-duration-by-integer 25 // "You really have to do Duration * Duration which is horrible." 26 timeout := network.WaitRetry * time.Duration(network.MaxRetryConnect*nbrNodes*2) 27 select { 28 case children := <-protocol.Count: 29 log.Lvl2("Instance 1 is done") 30 if children != nbrNodes { 31 t.Fatal("Didn't get a child-cound of", nbrNodes) 32 } 33 case <-time.After(timeout): 34 t.Fatal("Didn't finish in time") 35 } 36 }