Skip to content

Instantly share code, notes, and snippets.

@alxhub
Created December 1, 2015 17:39
Show Gist options
  • Save alxhub/1acbbaf30af9b9d06cac to your computer and use it in GitHub Desktop.
Save alxhub/1acbbaf30af9b9d06cac to your computer and use it in GitHub Desktop.
link_test.go
func TestNickCollisionDuringLink(t *testing.T) {
wg := &sync.WaitGroup{}
tn, hubA := newTestNetwork(t, "hub.a", wg)
hubB := tn.NewServer("hub.b")
// Add 3 clients on A and the same 3 clients on B.
// The first has an older timestamp on A, the last on B, and the middle
// is tied.
hubA.SetTS(1)
hubB.SetTS(3)
alphaA := hubA.NewClient("alpha")
alphaB := hubB.NewClient("alpha")
hubA.SetTS(2)
hubB.SetTS(2)
betaA := hubA.NewClient("beta")
betaB := hubB.NewClient("beta")
hubA.SetTS(3)
hubB.SetTS(1)
gammaA := hubA.NewClient("gamma")
gammaB := hubB.NewClient("gamma")
hubA.Link(hubB)
tn.ExpectAll(alphaA.Exists())
tn.ExpectAll(alphaB.Exists().Not())
tn.ExpectAll(betaA.Exists().Not())
tn.ExpectAll(betaB.Exists().Not())
tn.ExpectAll(gammaA.Exists().Not())
tn.ExpectAll(gammaB.Exists())
tn.Shutdown()
wg.Wait()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment