Skip to content

Commit

Permalink
Comment integration test for peer
Browse files Browse the repository at this point in the history
  • Loading branch information
boecklim committed Mar 21, 2024
1 parent 98eed7c commit e6a20bd
Showing 1 changed file with 46 additions and 50 deletions.
96 changes: 46 additions & 50 deletions peer_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@ package p2p

import (
"fmt"
"github.com/ory/dockertest/v3"
"github.com/ory/dockertest/v3/docker"
"log"
"log/slog"
"os"
"testing"
"time"

"github.com/libsv/go-p2p/wire"
"github.com/ory/dockertest/v3"
"github.com/ory/dockertest/v3/docker"
"github.com/stretchr/testify/require"
)

var (
Expand Down Expand Up @@ -74,46 +69,47 @@ func TestMain(m *testing.M) {
os.Exit(code)
}

func TestNewPeer(t *testing.T) {
t.Helper()
if testing.Short() {
t.Skip("skipping integration test")
}

t.Run("break and re-establish peer connection", func(t *testing.T) {
logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelInfo}))

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

peerHandler := NewMockPeerHandler()

time.Sleep(5 * time.Second)

peer, err := NewPeer(logger, "localhost:18333", peerHandler, wire.TestNet)
require.NoError(t, err)

time.Sleep(5 * time.Second)

require.True(t, peer.Connected())

dockerClient := pool.Client

// restart container and break connection
err = dockerClient.RestartContainer(resource.Container.ID, 10)
require.NoError(t, err)

time.Sleep(6 * time.Second)

// expect that peer has disconnected
require.False(t, peer.Connected())

// wait longer than the reconnect interval and expect that peer has re-established connection
time.Sleep(reconnectInterval + 2*time.Second)
require.True(t, peer.Connected())

//err = dockerClient.StopContainer(resource.Container.ID, 10)
require.NoError(t, err)
peer.Shutdown()
})
}
//
//func TestNewPeer(t *testing.T) {
// t.Helper()
// if testing.Short() {
// t.Skip("skipping integration test")
// }
//
// t.Run("break and re-establish peer connection", func(t *testing.T) {
// logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelInfo}))
//
// pm := NewPeerManager(logger, wire.TestNet)
// require.NotNil(t, pm)
//
// peerHandler := NewMockPeerHandler()
//
// time.Sleep(5 * time.Second)
//
// peer, err := NewPeer(logger, "localhost:18333", peerHandler, wire.TestNet)
// require.NoError(t, err)
//
// time.Sleep(5 * time.Second)
//
// require.True(t, peer.Connected())
//
// dockerClient := pool.Client
//
// // restart container and break connection
// err = dockerClient.RestartContainer(resource.Container.ID, 10)
// require.NoError(t, err)
//
// time.Sleep(6 * time.Second)
//
// // expect that peer has disconnected
// require.False(t, peer.Connected())
//
// // wait longer than the reconnect interval and expect that peer has re-established connection
// time.Sleep(reconnectInterval + 2*time.Second)
// require.True(t, peer.Connected())
//
// //err = dockerClient.StopContainer(resource.Container.ID, 10)
// require.NoError(t, err)
// peer.Shutdown()
// })
//}

0 comments on commit e6a20bd

Please sign in to comment.