Skip to content

Commit 8da80c7

Browse files
[Service Bus] Simplifying "disconnect" during drain test - for non-sessions (Azure#13930)
Was looking at this test to compare the scenario during sessions as part of Azure#8875. Talked to @richardpark-msft and we agreed to simplify it as shown in the PR with slightly more meaningful comments.
1 parent 39d7184 commit 8da80c7

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

sdk/servicebus/service-bus/test/internal/batchReceiver.spec.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -957,24 +957,15 @@ describe("Batching Receiver", () => {
957957
// Send a message so we have something to receive.
958958
await sender.sendMessages(TestMessage.getSample());
959959

960-
// Since the receiver has already been initialized,
961-
// the `receiver_drained` handler is attached as soon
962-
// as receiveMessages is invoked.
963-
// We remove the `receiver_drained` timeout after `receiveMessages`
964-
// does it's initial setup by wrapping it in a `setTimeout`.
965-
// This triggers the `receiver_drained` handler removal on the next
966-
// tick of the event loop; after the handler has been attached.
967-
setTimeout(() => {
968-
// remove `receiver_drained` event
969-
batchingReceiver["link"]!.removeAllListeners(ReceiverEvents.receiverDrained);
970-
}, 0);
971-
972960
// We want to simulate a disconnect once the batching receiver is draining.
973961
// We can detect when the receiver enters a draining state when `addCredit` is
974962
// called while `drain` is set to true.
975963
let didRequestDrain = false;
976964
const addCredit = batchingReceiver["link"]!.addCredit;
977965
batchingReceiver["link"]!.addCredit = function(credits) {
966+
// This makes sure the receiveMessages doesn't end because of draining before the disconnect is triggered
967+
// Meaning.. the "resolving the messages" can only happen through the onDetached triggered by disconnect
968+
batchingReceiver["link"]!.removeAllListeners(ReceiverEvents.receiverDrained);
978969
addCredit.call(this, credits);
979970
if (batchingReceiver["link"]!.drain) {
980971
didRequestDrain = true;

0 commit comments

Comments
 (0)