Skip to content

Commit eb5e876

Browse files
committed
get available port using portGenerator
1 parent 1569f3d commit eb5e876

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

packages/modules/azurecosmosdb/src/azure-cosmosdb-emulator-container.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import * as net from "node:net";
2-
import { AbstractStartedContainer, GenericContainer, StartedTestContainer, Wait } from "testcontainers";
2+
import {
3+
AbstractStartedContainer,
4+
GenericContainer,
5+
PortGenerator,
6+
RandomUniquePortGenerator,
7+
StartedTestContainer,
8+
Wait,
9+
} from "testcontainers";
310

411
type Protocol = "http" | "https";
512
const DEFAULT_KEY = "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=="; // default key for Cosmos DB Emulator
@@ -14,9 +21,11 @@ export class AzureCosmosDbEmulatorContainer extends GenericContainer {
1421
private protocol: Protocol = DEFAULT_PROTOCOL;
1522
private telemetryEnabled = DEFAULT_TELEMETRY_ENABLED;
1623
private explorerEnabled = DEFAULT_EXPLORER_ENABLED;
24+
private portGenerator: PortGenerator;
1725

1826
constructor(image = "mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:vnext-preview") {
1927
super(image);
28+
this.portGenerator = new RandomUniquePortGenerator();
2029
this.withWaitStrategy(Wait.forLogMessage(COSMOS_READY_LOG_MESSAGE));
2130
}
2231

@@ -31,7 +40,7 @@ export class AzureCosmosDbEmulatorContainer extends GenericContainer {
3140
}
3241

3342
public override async start(): Promise<StartedAzureCosmosDbEmulatorContainer> {
34-
const port = await this.getFreePort();
43+
const port = await this.portGenerator.generatePort();
3544
this.withExposedPorts({
3645
host: port,
3746
container: port,

0 commit comments

Comments
 (0)