forked from Azure/azure-sdk-for-js
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace unreliable live test (too timing dependent) with unit test th…
…at tests the same logic and should be more reliable. (Azure#14916) There were two live tests that were basically exercising a small segment of validation code to make sure you can't try to receiveMessages() and subscribe() at the same time. These tests have been flaky in the past, and were really only testing logic so I just migrated them to unit tests instead.
- Loading branch information
1 parent
d7e41a5
commit 343f07e
Showing
3 changed files
with
84 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
sdk/servicebus/service-bus/test/internal/unit/serviceBusReceiverUnitTests.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { BatchingReceiver } from "../../../src/core/batchingReceiver"; | ||
import { ServiceBusReceiverImpl } from "../../../src/receivers/receiver"; | ||
import { assertThrows } from "../../public/utils/testUtils"; | ||
import { createConnectionContextForTests, getPromiseResolverForTest } from "./unittestUtils"; | ||
import chai from "chai"; | ||
import { InternalMessageHandlers } from "../../../src/models"; | ||
const assert = chai.assert; | ||
|
||
describe("ServiceBusReceiver unit tests", () => { | ||
let receiver: ServiceBusReceiverImpl; | ||
|
||
beforeEach(() => { | ||
receiver = new ServiceBusReceiverImpl( | ||
createConnectionContextForTests(), | ||
"entityPath", | ||
"peekLock", | ||
0 | ||
); | ||
}); | ||
|
||
afterEach(() => receiver.close()); | ||
|
||
const expectedError: Record<string, any> = { | ||
name: "Error", | ||
message: 'The receiver for "entityPath" is already receiving messages.' | ||
}; | ||
|
||
it("isAlreadyReceiving (batching first, then streaming)", async () => { | ||
assert.isFalse(receiver["_isReceivingMessages"](), "Nothing should be receiving messages"); | ||
|
||
receiver["_batchingReceiver"] = { | ||
isOpen: () => true, | ||
isReceivingMessages: true, | ||
close: async () => {} | ||
} as BatchingReceiver; | ||
|
||
assert.isTrue(receiver["_isReceivingMessages"](), "Batching receiver is receiving messages"); | ||
|
||
const subscribeFn = async () => { | ||
receiver.subscribe({ | ||
processError: async (_errArgs) => {}, | ||
processMessage: async (_msg) => {} | ||
}); | ||
}; | ||
|
||
await assertThrows( | ||
subscribeFn, | ||
expectedError, | ||
"Trying to receive a separate way, in parallel, should throw" | ||
); | ||
}); | ||
|
||
it("isAlreadyReceiving (streaming first, then batching)", async () => { | ||
assert.isFalse(receiver["_isReceivingMessages"](), "Nothing should be receiving messages"); | ||
|
||
const { promise: subscriberInitializedPromise, resolve } = getPromiseResolverForTest(); | ||
|
||
receiver.subscribe({ | ||
processInitialize: async () => { | ||
resolve(); | ||
}, | ||
processError: async (_errArgs) => {}, | ||
processMessage: async (_msg) => {} | ||
} as InternalMessageHandlers); | ||
|
||
await subscriberInitializedPromise; | ||
|
||
assert.isTrue(receiver["_isReceivingMessages"](), "Streaming receiver is receiving messages"); | ||
|
||
await assertThrows( | ||
() => receiver.receiveMessages(1), | ||
expectedError, | ||
"Trying to receive a separate way, in parallel, should throw" | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters