@@ -33,19 +33,22 @@ func (pe fakeNetError) Timeout() bool { return pe.timeout }
3333func (pe fakeNetError ) Temporary () bool { return pe .temp }
3434func (pe fakeNetError ) Error () string { return "Fake but very permanent error" }
3535
36- func assertFailedLinks (t * testing.T , lwid * LinksWithID , expectedErr error , expectedRPCError error ) {
36+ func assertFailedLinks [ T error , T2 error ] (t * testing.T , lwid * LinksWithID , expectedErr T , expectedRPCError T2 ) {
3737 err := lwid .Sender .Send (context .TODO (), & amqp.Message {
3838 Data : [][]byte {
3939 {0 },
4040 },
4141 })
42+
43+ require .True (t , errors .Is (err , expectedErr ) || errors .As (err , & expectedErr ))
4244 require .ErrorIs (t , err , expectedErr )
4345
4446 _ , err = PeekMessages (context .TODO (), lwid .RPC , lwid .Receiver .LinkName (), 0 , 1 )
45- require .ErrorIs (t , err , expectedRPCError )
47+ require .True (t , errors . Is ( err , expectedRPCError ) || errors . As ( err , & expectedRPCError ) )
4648
4749 msg , err := lwid .Receiver .Receive (context .TODO ())
4850 require .ErrorIs (t , err , expectedErr )
51+ require .True (t , errors .Is (err , expectedErr ) || errors .As (err , & expectedErr ))
4952 require .Nil (t , msg )
5053
5154}
@@ -126,7 +129,7 @@ func TestAMQPLinksLive(t *testing.T) {
126129 }()
127130
128131 require .EqualValues (t , 0 , createLinksCalled )
129- require .NoError (t , links .RecoverIfNeeded (context .Background (), LinkID {}, amqp .ErrConnClosed ))
132+ require .NoError (t , links .RecoverIfNeeded (context .Background (), LinkID {}, & amqp.ConnectionError {} ))
130133 require .EqualValues (t , 1 , createLinksCalled )
131134
132135 lwr , err := links .Get (context .Background ())
@@ -138,10 +141,10 @@ func TestAMQPLinksLive(t *testing.T) {
138141 require .NoError (t , amqpClient .Close ())
139142
140143 // all the links are dead because the connection is dead.
141- assertFailedLinks (t , lwr , amqp .ErrConnClosed , amqp .ErrConnClosed )
144+ assertFailedLinks (t , lwr , & amqp.ConnectionError {}, & amqp.ConnectionError {} )
142145
143146 // now we'll recover, which should recreate everything
144- require .NoError (t , links .RecoverIfNeeded (context .Background (), lwr .ID , amqp .ErrConnClosed ))
147+ require .NoError (t , links .RecoverIfNeeded (context .Background (), lwr .ID , & amqp.ConnectionError {} ))
145148 require .EqualValues (t , 2 , createLinksCalled )
146149
147150 lwr , err = links .Get (context .Background ())
@@ -199,7 +202,7 @@ func TestAMQPLinksLiveRecoverLink(t *testing.T) {
199202 }()
200203
201204 require .EqualValues (t , 0 , createLinksCalled )
202- require .NoError (t , links .RecoverIfNeeded (context .Background (), LinkID {}, amqp .ErrConnClosed ))
205+ require .NoError (t , links .RecoverIfNeeded (context .Background (), LinkID {}, & amqp.ConnectionError {} ))
203206 require .EqualValues (t , 1 , createLinksCalled )
204207
205208 lwr , err := links .Get (context .Background ())
@@ -242,7 +245,7 @@ func TestAMQPLinksLiveRace(t *testing.T) {
242245 wg .Add (1 )
243246 go func () {
244247 defer wg .Done ()
245- err := links .RecoverIfNeeded (context .Background (), LinkID {}, amqp .ErrConnClosed )
248+ err := links .RecoverIfNeeded (context .Background (), LinkID {}, & amqp.ConnectionError {} )
246249 require .NoError (t , err )
247250 }()
248251 }
@@ -334,7 +337,7 @@ func TestAMQPLinksRetry(t *testing.T) {
334337
335338 err = links .Retry (context .Background (), log .Event ("NotUsed" ), "NotUsed" , func (ctx context.Context , lwid * LinksWithID , args * utils.RetryFnArgs ) error {
336339 // force recoveries
337- return amqp .ErrConnClosed
340+ return & amqp.ConnectionError {}
338341 }, exported.RetryOptions {
339342 MaxRetries : 2 ,
340343 // note: omitting MaxRetries just to give a sanity check that
@@ -343,7 +346,8 @@ func TestAMQPLinksRetry(t *testing.T) {
343346 MaxRetryDelay : time .Millisecond ,
344347 })
345348
346- require .ErrorIs (t , err , amqp .ErrConnClosed )
349+ var connErr * amqp.ConnectionError
350+ require .ErrorAs (t , err , & connErr )
347351 require .EqualValues (t , 3 , createLinksCalled )
348352}
349353
@@ -530,7 +534,7 @@ func TestAMQPLinksCloseIfNeeded(t *testing.T) {
530534 _ , err := links .Get (context .Background ())
531535 require .NoError (t , err )
532536
533- rk := links .CloseIfNeeded (context .Background (), amqp .ErrConnClosed )
537+ rk := links .CloseIfNeeded (context .Background (), & amqp.ConnectionError {} )
534538 require .Equal (t , RecoveryKindConn , rk )
535539 require .Equal (t , 1 , receiver .Closed )
536540 require .Equal (t , 1 , sender .Closed )
@@ -577,7 +581,7 @@ func TestAMQPLinksRetriesUnit(t *testing.T) {
577581 {Err : nil , Attempts : []int32 {0 }},
578582
579583 // connection related or unknown failures happen, all attempts exhausted
580- {Err : amqp .ErrConnClosed , Attempts : []int32 {0 , 1 , 2 , 3 }},
584+ {Err : & amqp.ConnectionError {} , Attempts : []int32 {0 , 1 , 2 , 3 }},
581585 {Err : errors .New ("unknown error" ), Attempts : []int32 {0 , 1 , 2 , 3 }},
582586
583587 // fatal errors don't retry at all.
@@ -698,7 +702,7 @@ func TestAMQPLinks_Logging(t *testing.T) {
698702 endCapture := test .CaptureLogsForTest ()
699703 defer endCapture ()
700704
701- err := links .RecoverIfNeeded (context .Background (), LinkID {}, amqp .ErrConnClosed )
705+ err := links .RecoverIfNeeded (context .Background (), LinkID {}, & amqp.ConnectionError {} )
702706 require .NoError (t , err )
703707
704708 messages := endCapture ()
0 commit comments