Skip to content

Commit a8cec38

Browse files
Implement AsyncDisposable to support TS 5.2's using (#1080)
1 parent 84f83ab commit a8cec38

File tree

76 files changed

+503
-963
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+503
-963
lines changed

eslint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export default [
3232
"error",
3333
{
3434
caughtErrors: "none",
35+
varsIgnorePattern: "^_",
3536
},
3637
],
3738
"no-irregular-whitespace": "off",

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const IMAGE = getImage(__dirname);
77
describe("ArangoDB", { timeout: 180_000 }, () => {
88
// connect {
99
it("should connect and return a query result", async () => {
10-
const container = await new ArangoDBContainer(IMAGE).start();
10+
await using container = await new ArangoDBContainer(IMAGE).start();
1111
const db = new Database({ url: container.getHttpUrl() });
1212

1313
db.database("_system");
@@ -20,8 +20,6 @@ describe("ArangoDB", { timeout: 180_000 }, () => {
2020
});
2121
const returnValue = await result.next();
2222
expect(returnValue).toBe(value);
23-
24-
await container.stop();
2523
});
2624
// }
2725
});

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

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,20 @@ const IMAGE = getImage(__dirname);
77

88
describe("AzureCosmosDbEmulatorContainer", { timeout: 180_000 }, async () => {
99
it("should set https protocol", async () => {
10-
const container = await new AzureCosmosDbEmulatorContainer(IMAGE).withProtocol("https").start();
10+
await using container = await new AzureCosmosDbEmulatorContainer(IMAGE).withProtocol("https").start();
1111
const connectionUri = container.getConnectionUri();
1212
expect(connectionUri).toContain("AccountEndpoint=https://");
13-
await container.stop();
1413
});
14+
1515
it("should set http protocol if no protocol is specified", async () => {
16-
const container = await new AzureCosmosDbEmulatorContainer(IMAGE).start();
16+
await using container = await new AzureCosmosDbEmulatorContainer(IMAGE).start();
1717
const connectionUri = container.getConnectionUri();
1818
expect(connectionUri).toContain("AccountEndpoint=http://");
19-
await container.stop();
2019
});
2120

2221
// httpCreateDB {
2322
it("should be able to create a database using http", async () => {
24-
const container = await new AzureCosmosDbEmulatorContainer(IMAGE).withProtocol("http").start();
23+
await using container = await new AzureCosmosDbEmulatorContainer(IMAGE).withProtocol("http").start();
2524
const cosmosClient = new CosmosClient({
2625
endpoint: container.getEndpoint(),
2726
key: container.getKey(),
@@ -35,14 +34,12 @@ describe("AzureCosmosDbEmulatorContainer", { timeout: 180_000 }, async () => {
3534

3635
const db = await cosmosClient.database(dbName).read();
3736
expect(db.database.id).toBe(dbName);
38-
39-
await container.stop();
4037
});
4138
// }
4239

4340
// httpsCreateDB {
4441
it("should be able to create a database using https", async () => {
45-
const container = await new AzureCosmosDbEmulatorContainer(IMAGE).withProtocol("https").start();
42+
await using container = await new AzureCosmosDbEmulatorContainer(IMAGE).withProtocol("https").start();
4643
const cosmosClient = new CosmosClient({
4744
endpoint: container.getEndpoint(),
4845
key: container.getKey(),
@@ -59,14 +56,12 @@ describe("AzureCosmosDbEmulatorContainer", { timeout: 180_000 }, async () => {
5956

6057
const db = await cosmosClient.database(dbName).read();
6158
expect(db.database.id).toBe(dbName);
62-
63-
await container.stop();
6459
});
6560
// }
6661

6762
// createAndRead {
6863
it("should be able to create a container and store and retrieve items", async () => {
69-
const container = await new AzureCosmosDbEmulatorContainer(IMAGE).withProtocol("http").start();
64+
await using container = await new AzureCosmosDbEmulatorContainer(IMAGE).withProtocol("http").start();
7065
const cosmosClient = new CosmosClient({
7166
endpoint: container.getEndpoint(),
7267
key: container.getKey(),
@@ -94,8 +89,6 @@ describe("AzureCosmosDbEmulatorContainer", { timeout: 180_000 }, async () => {
9489

9590
const readItem = await containerClient.item(createResponse.item.id, "bar").read();
9691
expect(readItem.resource.foo).toEqual("bar");
97-
98-
await container.stop();
9992
});
10093
// }
10194
});

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

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const IMAGE = getImage(__dirname);
99
describe("Azurite", { timeout: 240_000 }, () => {
1010
// uploadAndDownloadBlob {
1111
it("should upload and download blob with default credentials", async () => {
12-
const container = await new AzuriteContainer(IMAGE).start();
12+
await using container = await new AzuriteContainer(IMAGE).start();
1313

1414
const connectionString = container.getConnectionString();
1515
expect(connectionString).toBeTruthy();
@@ -34,14 +34,12 @@ describe("Azurite", { timeout: 240_000 }, () => {
3434
}
3535

3636
expect(data).toBe(content);
37-
38-
await container.stop();
3937
});
4038
// }
4139

4240
// sendAndReceiveQueue {
4341
it("should add to queue with default credentials", async () => {
44-
const container = await new AzuriteContainer(IMAGE).start();
42+
await using container = await new AzuriteContainer(IMAGE).start();
4543

4644
const connectionString = container.getConnectionString();
4745
expect(connectionString).toBeTruthy();
@@ -58,14 +56,12 @@ describe("Azurite", { timeout: 240_000 }, () => {
5856
const messages = await queueClient.receiveMessages();
5957
expect(messages.receivedMessageItems).toHaveLength(1);
6058
expect(messages.receivedMessageItems[0].messageText).toBe(message);
61-
62-
await container.stop();
6359
});
6460
// }
6561

6662
// createAndInsertOnTable {
6763
it("should add to table with default credentials", async () => {
68-
const container = await new AzuriteContainer(IMAGE).start();
64+
await using container = await new AzuriteContainer(IMAGE).start();
6965

7066
const connectionString = container.getConnectionString();
7167
expect(connectionString).toBeTruthy();
@@ -86,8 +82,6 @@ describe("Azurite", { timeout: 240_000 }, () => {
8682
const e1 = await tableClient.listEntities().next();
8783
expect(e1.value).toBeTruthy();
8884
expect(e1.value.name).toBe(entity.name);
89-
90-
await container.stop();
9185
});
9286
// }
9387

@@ -97,7 +91,10 @@ describe("Azurite", { timeout: 240_000 }, () => {
9791
// Account key must be base64 encoded
9892
const accountKey = Buffer.from("test-key").toString("base64");
9993

100-
const container = await new AzuriteContainer(IMAGE).withAccountName(accountName).withAccountKey(accountKey).start();
94+
await using container = await new AzuriteContainer(IMAGE)
95+
.withAccountName(accountName)
96+
.withAccountKey(accountKey)
97+
.start();
10198

10299
const credentials = new StorageSharedKeyCredential(accountName, accountKey);
103100
const serviceClient = new BlobServiceClient(container.getBlobEndpoint(), credentials);
@@ -109,8 +106,6 @@ describe("Azurite", { timeout: 240_000 }, () => {
109106
const blobContainer = await serviceClient.listContainers().next();
110107
expect(blobContainer.value).toBeTruthy();
111108
expect(blobContainer.value.name).toBe(blobContainerName);
112-
113-
await container.stop();
114109
});
115110
// }
116111

@@ -119,7 +114,7 @@ describe("Azurite", { timeout: 240_000 }, () => {
119114
const blobPort = 13000;
120115
const queuePort = 14000;
121116
const tablePort = 15000;
122-
const container = await new AzuriteContainer(IMAGE)
117+
await using container = await new AzuriteContainer(IMAGE)
123118
.withBlobPort({ container: 10001, host: blobPort })
124119
.withQueuePort({ container: 10002, host: queuePort })
125120
.withTablePort({ container: 10003, host: tablePort })
@@ -137,14 +132,12 @@ describe("Azurite", { timeout: 240_000 }, () => {
137132
const serviceClient = BlobServiceClient.fromConnectionString(connectionString);
138133
const containerClient = serviceClient.getContainerClient("test");
139134
await containerClient.createIfNotExists();
140-
141-
await container.stop();
142135
});
143136
// }
144137

145138
// inMemoryPersistence {
146139
it("should be able to use in-memory persistence", async () => {
147-
const container = await new AzuriteContainer(IMAGE).withInMemoryPersistence().start();
140+
await using container = await new AzuriteContainer(IMAGE).withInMemoryPersistence().start();
148141
const blobName = "hello.txt";
149142

150143
{

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const IMAGE = getImage(__dirname);
88
describe.sequential("Cassandra", { timeout: 240_000 }, () => {
99
// connectWithDefaultCredentials {
1010
it("should connect and execute a query with default credentials", async () => {
11-
const container = await new CassandraContainer(IMAGE).start();
11+
await using container = await new CassandraContainer(IMAGE).start();
1212

1313
const client = new Client({
1414
contactPoints: [container.getContactPoint()],
@@ -22,7 +22,6 @@ describe.sequential("Cassandra", { timeout: 240_000 }, () => {
2222
expect(result.rows[0].release_version).toBe(ImageName.fromString(IMAGE).tag);
2323

2424
await client.shutdown();
25-
await container.stop();
2625
});
2726
// }
2827

@@ -31,7 +30,7 @@ describe.sequential("Cassandra", { timeout: 240_000 }, () => {
3130
const username = "testUser";
3231
const password = "testPassword";
3332

34-
const container = await new CassandraContainer(IMAGE).withUsername(username).withPassword(password).start();
33+
await using container = await new CassandraContainer(IMAGE).withUsername(username).withPassword(password).start();
3534

3635
const client = new Client({
3736
contactPoints: [container.getContactPoint()],
@@ -46,15 +45,17 @@ describe.sequential("Cassandra", { timeout: 240_000 }, () => {
4645
expect(result.rows.length).toBeGreaterThan(0);
4746

4847
await client.shutdown();
49-
await container.stop();
5048
});
5149
// }
5250

5351
// customDataCenterAndRack {
5452
it("should set datacenter and rack", async () => {
5553
const customDataCenter = "customDC";
5654
const customRack = "customRack";
57-
const container = await new CassandraContainer(IMAGE).withDatacenter(customDataCenter).withRack(customRack).start();
55+
await using container = await new CassandraContainer(IMAGE)
56+
.withDatacenter(customDataCenter)
57+
.withRack(customRack)
58+
.start();
5859

5960
const client = new Client({
6061
contactPoints: [container.getContactPoint()],
@@ -67,13 +68,12 @@ describe.sequential("Cassandra", { timeout: 240_000 }, () => {
6768
expect(result.rows[0].rack).toBe(customRack);
6869

6970
await client.shutdown();
70-
await container.stop();
7171
});
7272
// }
7373

7474
// createAndFetchData {
7575
it("should create keyspace, a table, insert data, and retrieve it", async () => {
76-
const container = await new CassandraContainer(IMAGE).start();
76+
await using container = await new CassandraContainer(IMAGE).start();
7777

7878
const client = new Client({
7979
contactPoints: [container.getContactPoint()],
@@ -108,12 +108,11 @@ describe.sequential("Cassandra", { timeout: 240_000 }, () => {
108108
expect(result.rows[0].name).toBe(username);
109109

110110
await client.shutdown();
111-
await container.stop();
112111
});
113112
// }
114113

115114
it("should work with restarted container", async () => {
116-
const container = await new CassandraContainer(IMAGE).start();
115+
await using container = await new CassandraContainer(IMAGE).start();
117116
await container.restart();
118117

119118
const client = new Client({
@@ -128,6 +127,5 @@ describe.sequential("Cassandra", { timeout: 240_000 }, () => {
128127
expect(result.rows[0].release_version).toBe(ImageName.fromString(IMAGE).tag);
129128

130129
await client.shutdown();
131-
await container.stop();
132130
});
133131
});

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ const IMAGE = getImage(__dirname);
1111
describe("ChromaDB", { timeout: 360_000 }, () => {
1212
// startContainer {
1313
it("should connect", async () => {
14-
const container = await new ChromaDBContainer(IMAGE).start();
14+
await using container = await new ChromaDBContainer(IMAGE).start();
1515
const client = await connectTo(container);
1616
expect(await client.heartbeat()).toBeDefined();
1717
// Do something with the client
18-
await container.stop();
1918
});
2019
// }
2120

@@ -32,7 +31,7 @@ describe("ChromaDB", { timeout: 360_000 }, () => {
3231

3332
// createCollection {
3433
it("should create collection and get data", async () => {
35-
const container = await new ChromaDBContainer(IMAGE).start();
34+
await using container = await new ChromaDBContainer(IMAGE).start();
3635
const client = await connectTo(container);
3736
const collection = await client.createCollection({ name: "test", metadata: { "hnsw:space": "cosine" } });
3837
expect(collection.name).toBe("test");
@@ -44,13 +43,12 @@ describe("ChromaDB", { timeout: 360_000 }, () => {
4443
expect(getResults.documents[0]).toStrictEqual("my doc");
4544
expect(getResults.metadatas).toBeDefined();
4645
expect(getResults.metadatas?.[0]?.key).toStrictEqual("value");
47-
await container.stop();
4846
});
4947
// }
5048

5149
// queryCollectionWithEmbeddingFunction {
5250
it("should create collection and query", async () => {
53-
const container = await new ChromaDBContainer(IMAGE).start();
51+
await using container = await new ChromaDBContainer(IMAGE).start();
5452
const ollama = await new GenericContainer("ollama/ollama").withExposedPorts(11434).start();
5553
await ollama.exec(["ollama", "pull", "nomic-embed-text"]);
5654
const client = await connectTo(container);
@@ -75,13 +73,12 @@ describe("ChromaDB", { timeout: 360_000 }, () => {
7573
expect(results).toBeDefined();
7674
expect(results.ids[0]).toEqual(["1"]);
7775
expect(results.ids[0][0]).toBe("1");
78-
await container.stop();
7976
});
8077

8178
// persistentData {
8279
it("should reconnect with volume and persistence data", async () => {
8380
const sourcePath = fs.mkdtempSync(path.join(os.tmpdir(), "chroma-temp"));
84-
const container = await new ChromaDBContainer(IMAGE)
81+
await using container = await new ChromaDBContainer(IMAGE)
8582
.withBindMounts([{ source: sourcePath, target: "/data" }])
8683
.start();
8784
const client = await connectTo(container);
@@ -93,7 +90,6 @@ describe("ChromaDB", { timeout: 360_000 }, () => {
9390
const getResults = await collection.get({ ids: ["1"] });
9491
expect(getResults.ids[0]).toBe("1");
9592
expect(getResults.documents[0]).toStrictEqual("my doc");
96-
await container.stop();
9793
expect(fs.existsSync(`${sourcePath}/chroma.sqlite3`)).toBe(true);
9894
try {
9995
fs.rmSync(sourcePath, { force: true, recursive: true });
@@ -109,7 +105,7 @@ describe("ChromaDB", { timeout: 360_000 }, () => {
109105
const tenant = "test-tenant";
110106
const key = "test-key";
111107
const database = "test-db";
112-
const container = await new ChromaDBContainer(IMAGE)
108+
await using container = await new ChromaDBContainer(IMAGE)
113109
.withEnvironment({
114110
CHROMA_SERVER_AUTHN_CREDENTIALS: key,
115111
CHROMA_SERVER_AUTHN_PROVIDER: "chromadb.auth.token_authn.TokenAuthenticationServerProvider",

0 commit comments

Comments
 (0)