Skip to content

Commit

Permalink
ARCO-105: Unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
boecklim committed Jul 25, 2024
1 parent 7a44186 commit c7d4fc8
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions peer_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,45 @@ func TestAnnounceNewTransaction(t *testing.T) {
assert.GreaterOrEqual(t, peersMessaged, len(peers)/2)
})
}

func TestMonitorPeerHealth(t *testing.T) {

logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug}))
tt := []struct {
name string
restartUnhealthyPeers bool
}{
{
name: "restart unhealthy peers",
restartUnhealthyPeers: true,
},
{
name: "do not restart unhealthy peers",
restartUnhealthyPeers: false,
},
}

for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
var opts []PeerManagerOptions

if tc.restartUnhealthyPeers {
opts = append(opts, WithRestartUnhealthyPeers())
}

pm := NewPeerManager(logger, wire.TestNet, opts...)
require.NotNil(t, pm)

peerHandler := NewMockPeerHandler()

peer, err := NewPeer(logger, "localhost:18333", peerHandler, wire.TestNet, WithPingInterval(100*time.Millisecond, 200*time.Millisecond))
require.NoError(t, err)

err = pm.AddPeer(peer)
require.NoError(t, err)
assert.Len(t, pm.GetPeers(), 1)
time.Sleep(1 * time.Second)
pm.Shutdown()
})
}
}

0 comments on commit c7d4fc8

Please sign in to comment.