@@ -51,7 +51,7 @@ func TestConnectionManagerConnError(t *testing.T) {
5151 doneChan := make (chan any )
5252 connManager := ouroboros .NewConnectionManager (
5353 ouroboros.ConnectionManagerConfig {
54- ErrorFunc : func (connId int , err error ) {
54+ ConnClosedFunc : func (connId int , err error ) {
5555 if connId != expectedConnId {
5656 t .Fatalf ("did not receive error from expected connection: got %d, wanted %d" , connId , expectedConnId )
5757 }
@@ -96,3 +96,50 @@ func TestConnectionManagerConnError(t *testing.T) {
9696 t .Fatalf ("did not receive error within timeout" )
9797 }
9898}
99+
100+ func TestConnectionManagerConnClosed (t * testing.T ) {
101+ expectedConnId := 42
102+ doneChan := make (chan any )
103+ connManager := ouroboros .NewConnectionManager (
104+ ouroboros.ConnectionManagerConfig {
105+ ConnClosedFunc : func (connId int , err error ) {
106+ if connId != expectedConnId {
107+ t .Fatalf ("did not receive closed signal from expected connection: got %d, wanted %d" , connId , expectedConnId )
108+ }
109+ if err != nil {
110+ t .Fatalf ("received unexpected error: %s" , err )
111+ }
112+ close (doneChan )
113+ },
114+ },
115+ )
116+ mockConn := ouroboros_mock .NewConnection (
117+ ouroboros_mock .ProtocolRoleClient ,
118+ []ouroboros_mock.ConversationEntry {
119+ ouroboros_mock .ConversationEntryHandshakeRequestGeneric ,
120+ ouroboros_mock .ConversationEntryHandshakeNtNResponse ,
121+ },
122+ )
123+ oConn , err := ouroboros .New (
124+ ouroboros .WithConnection (mockConn ),
125+ ouroboros .WithNetworkMagic (ouroboros_mock .MockNetworkMagic ),
126+ ouroboros .WithNodeToNode (true ),
127+ ouroboros .WithKeepAlive (false ),
128+ )
129+ if err != nil {
130+ t .Fatalf ("unexpected error when creating Ouroboros object: %s" , err )
131+ }
132+ connManager .AddConnection (expectedConnId , oConn )
133+ time .AfterFunc (
134+ 1 * time .Second ,
135+ func () {
136+ oConn .Close ()
137+ },
138+ )
139+ select {
140+ case <- doneChan :
141+ return
142+ case <- time .After (10 * time .Second ):
143+ t .Fatalf ("did not receive error within timeout" )
144+ }
145+ }
0 commit comments