@@ -51,7 +51,7 @@ func TestConnectionManagerConnError(t *testing.T) {
51
51
doneChan := make (chan any )
52
52
connManager := ouroboros .NewConnectionManager (
53
53
ouroboros.ConnectionManagerConfig {
54
- ErrorFunc : func (connId int , err error ) {
54
+ ConnClosedFunc : func (connId int , err error ) {
55
55
if connId != expectedConnId {
56
56
t .Fatalf ("did not receive error from expected connection: got %d, wanted %d" , connId , expectedConnId )
57
57
}
@@ -96,3 +96,50 @@ func TestConnectionManagerConnError(t *testing.T) {
96
96
t .Fatalf ("did not receive error within timeout" )
97
97
}
98
98
}
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