Skip to content

Commit

Permalink
ARCO-105: Integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
boecklim committed Jul 22, 2024
1 parent 97323c3 commit 4fe767d
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions test/peer_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,47 @@ func TestNewPeer(t *testing.T) {
t.Log("shutdown finished")
})

t.Run("restart", func(t *testing.T) {
logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug}))

peerHandler := p2p.NewMockPeerHandler()

peer, err := p2p.NewPeer(logger, "localhost:"+p2pPortBinding, peerHandler, wire.TestNet, p2p.WithUserAgent("agent", "0.0.1"))
require.NoError(t, err)

t.Log("expect that peer has connected")
connectLoop:
for {
select {
case <-time.NewTicker(200 * time.Millisecond).C:
if peer.Connected() {
break connectLoop
}
case <-time.NewTimer(5 * time.Second).C:
t.Fatal("peer did not connect")
}
}

t.Log("restart peer")
peer.Restart()

t.Log("expect that peer has re-established connection")
reconnectLoop:
for {
select {
case <-time.NewTicker(200 * time.Millisecond).C:
if peer.Connected() {
break reconnectLoop
}
case <-time.NewTimer(2 * time.Second).C:
t.Fatal("peer did not reconnect")
}
}

require.NoError(t, err)

t.Log("shutdown")
peer.Shutdown()
t.Log("shutdown finished")
})
}

0 comments on commit 4fe767d

Please sign in to comment.