@@ -22,6 +22,7 @@ import (
2222 ouroboros "github.com/blinklabs-io/gouroboros"
2323 "github.com/blinklabs-io/gouroboros/internal/test/ouroboros_mock"
2424 "github.com/blinklabs-io/gouroboros/protocol/keepalive"
25+ "go.uber.org/goleak"
2526)
2627
2728func TestConnectionManagerTagString (t * testing.T ) {
@@ -46,19 +47,22 @@ func TestConnectionManagerTagString(t *testing.T) {
4647}
4748
4849func TestConnectionManagerConnError (t * testing.T ) {
50+ defer goleak .VerifyNone (t )
4951 expectedConnId := 2
5052 expectedErr := io .EOF
5153 doneChan := make (chan any )
5254 connManager := ouroboros .NewConnectionManager (
5355 ouroboros.ConnectionManagerConfig {
5456 ConnClosedFunc : func (connId int , err error ) {
55- if connId != expectedConnId {
56- t .Fatalf ("did not receive error from expected connection: got %d, wanted %d" , connId , expectedConnId )
57- }
58- if err != expectedErr {
59- t .Fatalf ("did not receive expected error: got: %s, expected: %s" , err , expectedErr )
57+ if err != nil {
58+ if connId != expectedConnId {
59+ t .Fatalf ("did not receive error from expected connection: got %d, wanted %d" , connId , expectedConnId )
60+ }
61+ if err != expectedErr {
62+ t .Fatalf ("did not receive expected error: got: %s, expected: %s" , err , expectedErr )
63+ }
64+ close (doneChan )
6065 }
61- close (doneChan )
6266 },
6367 },
6468 )
@@ -91,13 +95,22 @@ func TestConnectionManagerConnError(t *testing.T) {
9195 }
9296 select {
9397 case <- doneChan :
98+ // Shutdown other connections
99+ for _ , tmpConn := range connManager .GetConnectionsByTags () {
100+ if tmpConn .Id != expectedConnId {
101+ tmpConn .Conn .Close ()
102+ }
103+ }
104+ // TODO: actually wait for shutdown
105+ time .Sleep (5 * time .Second )
94106 return
95107 case <- time .After (10 * time .Second ):
96108 t .Fatalf ("did not receive error within timeout" )
97109 }
98110}
99111
100112func TestConnectionManagerConnClosed (t * testing.T ) {
113+ defer goleak .VerifyNone (t )
101114 expectedConnId := 42
102115 doneChan := make (chan any )
103116 connManager := ouroboros .NewConnectionManager (
@@ -138,6 +151,8 @@ func TestConnectionManagerConnClosed(t *testing.T) {
138151 )
139152 select {
140153 case <- doneChan :
154+ // TODO: actually wait for shutdown
155+ time .Sleep (5 * time .Second )
141156 return
142157 case <- time .After (10 * time .Second ):
143158 t .Fatalf ("did not receive error within timeout" )
0 commit comments