Skip to content

Commit 8594056

Browse files
[azservicebus] Making a unit test more reliable by blocking instead of relying on "hopeful" timing. (Azure#18215)
Making a unit test more reliable by blocking instead of relying on "hopeful" timing. Fixes Azure#18174
1 parent 6015c3d commit 8594056

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

sdk/messaging/azservicebus/receiver_unit_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,19 +311,32 @@ func TestReceiver_CanCancelLinkCreation(t *testing.T) {
311311
},
312312
}
313313

314+
done := make(chan struct{})
315+
314316
session := &internal.FakeAMQPSession{
315317
NewReceiverFn: func(opts ...amqp.LinkOption) (internal.AMQPReceiverCloser, error) {
316318
// simulate the client cancelling while we're stuck attempting to get the
317319
// session receiver link.
318320
cancel()
321+
322+
// "block" here. Basically what we're trying to simulate is that there's an
323+
// active NewReceiver() and then we cancel.
324+
select {
325+
case <-done:
326+
case <-time.After(5 * time.Second):
327+
require.Fail(t, "Timed out waiting for the cancellation token to be respected.")
328+
}
319329
return fakeReceiver, nil
320330
},
321331
}
322332

323333
receiver, err := createReceiverLink(ctx, session, []amqp.LinkOption{})
324334
require.Nil(t, receiver)
335+
require.NotNil(t, err)
325336
require.ErrorIs(t, err, context.Canceled, fmt.Sprintf("%s is context.Cancelled", err.Error()))
326337

338+
close(done)
339+
327340
// also, the receiver we returned should be closed as part of the gourtine
328341
// unwinding.
329342
<-receiverWasClosedCh

0 commit comments

Comments
 (0)