Skip to content

Commit

Permalink
add test for a peer that joins late
Browse files Browse the repository at this point in the history
  • Loading branch information
mreiferson committed Mar 5, 2013
1 parent a38b22b commit 126725f
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions peer/peer_test.go
Expand Up @@ -7,6 +7,7 @@ import (
"os/exec"

"testing"
"time"
)

func TestDoozerNop(t *testing.T) {
Expand Down Expand Up @@ -325,6 +326,42 @@ func TestPeerShun(t *testing.T) {
}
}

func TestPeerLateJoin(t *testing.T) {
l0 := mustListen()
defer l0.Close()
a0 := l0.Addr().String()
u0 := mustListenUDP(a0)
defer u0.Close()

l1 := mustListen()
defer l1.Close()
u1 := mustListenUDP(l1.Addr().String())
defer u1.Close()

go Main("a", "X", "", "", "", nil, u0, l0, nil, 1e8, 1e7, 1e9, 60)

cl := dial(l0.Addr().String())
waitFor(cl, "/ctl/node/X/writable")

// TODO: this is set slightly higher than the hardcoded interval
// at which a store is cleaned. Refactor that to be configurable
// so we can drop this down to something reasonable
time.Sleep(1100 * time.Millisecond)

go Main("a", "Y", "", "", "", dial(a0), u1, l1, nil, 1e8, 1e7, 1e9, 60)
rev, _ := cl.Set("/ctl/cal/1", store.Missing, nil)
for {
ev, err := cl.Wait("/ctl/node/Y/writable", rev)
if err != nil {
panic(err)
}
if ev.IsSet() && len(ev.Body) == 4 {
break
}
rev = ev.Rev + 1
}
}

func assertDenied(t *testing.T, err error) {
assert.NotEqual(t, nil, err)
assert.Equal(t, doozer.ErrOther, err.(*doozer.Error).Err)
Expand Down

0 comments on commit 126725f

Please sign in to comment.