Skip to content

Commit 77e9e97

Browse files
PR comments
1 parent 1e61c8b commit 77e9e97

File tree

4 files changed

+35
-9
lines changed

4 files changed

+35
-9
lines changed

docs/modules/azureservicebus.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ These examples use the following libraries:
1414

1515
npm install @azure/service-bus
1616

17-
Choose an image from the [container registry](https://hub.docker.com/r/microsoft/azure-messaging-servicebus-emulator) and substitute `IMAGE`.
17+
Choose an image from the [container registry](https://mcr.microsoft.com/en-us/artifact/mar/azure-messaging/servicebus-emulator) and substitute `IMAGE`.
1818

1919
### Send/receive queue messages
2020

mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ nav:
5454
- Advanced: features/advanced.md
5555
- Modules:
5656
- ArangoDB: modules/arangodb.md
57-
- AzureServiceBusEmulator: modules/azureservicebus.md
57+
- Azure Service Bus: modules/azureservicebus.md
5858
- Azurite: modules/azurite.md
5959
- Cassandra: modules/cassandra.md
6060
- ChromaDB: modules/chromadb.md

packages/modules/azureservicebus/src/azureservicebus-container.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { ServiceBusContainer } from "./azureservicebus-container";
55

66
const IMAGE = getImage(__dirname);
77

8-
describe("ServiceBusContainer", { timeout: 180_000 }, () => {
8+
describe("Azure Service Bus", { timeout: 180_000 }, () => {
99
it("should connect and queue a message", async () => {
1010
// serviceBusConnect {
1111
await using container = await new ServiceBusContainer(IMAGE).acceptLicense().start();
@@ -89,6 +89,7 @@ describe("ServiceBusContainer", { timeout: 180_000 }, () => {
8989
ACCEPT_EULA: "Y",
9090
MSSQL_SA_PASSWORD: customPassword,
9191
})
92+
.withNetworkAliases("your-network-alias")
9293
.withWaitStrategy(Wait.forLogMessage(/.*Recovery is complete.*/, 1).withStartupTimeout(120_000));
9394

9495
await using container = await new ServiceBusContainer(IMAGE)

packages/modules/azureservicebus/src/azureservicebus-container.ts

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const DEFAULT_SHARED_ACCESS_KEY_NAME = "RootManageSharedAccessKey";
1414
const DEFAULT_SHARED_ACCESS_KEY = "SAS_KEY_VALUE";
1515
const DEFAULT_MSSQL_ALIAS = "mssql";
1616
const DEFAULT_MSSQL_IMAGE = "mcr.microsoft.com/mssql/server:2022-CU14-ubuntu-22.04";
17-
const DEFAULT_MSSQL_PASSWORD = "P@ssword1!";
17+
const DEFAULT_MSSQL_PASSWORD = "P@ssword1!d3adb33f#";
1818
const CONTAINER_CONFIG_FILE = "/ServiceBus_Emulator/ConfigFiles/Config.json";
1919

2020
export class ServiceBusContainer extends GenericContainer {
@@ -28,6 +28,8 @@ export class ServiceBusContainer extends GenericContainer {
2828
super(image);
2929

3030
this.withExposedPorts(DEFAULT_PORT, DEFAULT_HTTP_PORT)
31+
// The emulator image is minimal and does not include a shell, so the internal port checks will fail.
32+
// The HTTP health check should be sufficient to determine when the emulator is ready.
3133
.withWaitStrategy(Wait.forHttp("/health", DEFAULT_HTTP_PORT).forStatusCode(200))
3234
.withEnvironment({
3335
SQL_WAIT_INTERVAL: "0", // We start the MSSQL container before the emulator
@@ -40,16 +42,28 @@ export class ServiceBusContainer extends GenericContainer {
4042
}
4143

4244
public withMssqlContainer(container: GenericContainer): this {
45+
if (this.mssqlImage !== DEFAULT_MSSQL_IMAGE) {
46+
throw new Error("Cannot use both withMssqlImage() and withMssqlContainer()");
47+
}
48+
4349
this.mssqlContainer = container;
4450
return this;
4551
}
4652

4753
public withMssqlImage(image: string): this {
54+
if (this.mssqlContainer) {
55+
throw new Error("Cannot use both withMssqlImage() and withMssqlContainer()");
56+
}
57+
4858
this.mssqlImage = image;
4959
return this;
5060
}
5161

5262
public withMssqlPassword(password: string): this {
63+
if (this.mssqlPassword !== DEFAULT_MSSQL_PASSWORD) {
64+
throw new Error("Cannot use both withMssqlPassword() and withMssqlContainer()");
65+
}
66+
5367
this.mssqlPassword = password;
5468
return this;
5569
}
@@ -67,7 +81,6 @@ export class ServiceBusContainer extends GenericContainer {
6781
// This should match the behaviour of @testcontainers/mssqlserver, we
6882
// create the container manually here to avoid module dependencies.
6983
this.mssqlContainer = new GenericContainer(this.mssqlImage)
70-
.withNetworkAliases(DEFAULT_MSSQL_ALIAS)
7184
.withEnvironment({
7285
ACCEPT_EULA: "Y",
7386
MSSQL_SA_PASSWORD: this.mssqlPassword,
@@ -76,7 +89,7 @@ export class ServiceBusContainer extends GenericContainer {
7689
.withWaitStrategy(Wait.forLogMessage(/.*Recovery is complete.*/, 1).withStartupTimeout(120_000));
7790
}
7891

79-
const mssql = await this.mssqlContainer.withNetwork(network).start();
92+
const mssql = await this.mssqlContainer.withNetworkAliases(DEFAULT_MSSQL_ALIAS).withNetwork(network).start();
8093

8194
if (this.config) {
8295
this.withCopyContentToContainer([
@@ -94,7 +107,16 @@ export class ServiceBusContainer extends GenericContainer {
94107
MSSQL_SA_PASSWORD: this.mssqlPassword,
95108
});
96109

97-
return new StartedServiceBusContainer(await super.start(), mssql, network);
110+
try {
111+
const serviceBus = await super.start();
112+
113+
return new StartedServiceBusContainer(serviceBus, mssql, network);
114+
} catch (err) {
115+
await mssql.stop();
116+
await network.stop();
117+
118+
throw err;
119+
}
98120
}
99121
}
100122

@@ -120,7 +142,10 @@ export class StartedServiceBusContainer extends AbstractStartedContainer {
120142
}
121143

122144
protected override async containerStopped(): Promise<void> {
123-
await this.mssql.stop();
124-
await this.network.stop();
145+
try {
146+
await this.mssql.stop();
147+
} finally {
148+
await this.network.stop();
149+
}
125150
}
126151
}

0 commit comments

Comments
 (0)