Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions __tests__/integration/dynalite.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { createServer } from "node:net";
import type { AddressInfo } from "node:net";
import { DescribeTableCommand } from "@aws-sdk/client-dynamodb";
import type { DynamoDBDocument } from "@aws-sdk/lib-dynamodb";
import dynalite from "dynalite";

export interface DynaliteOptions {
Expand Down Expand Up @@ -57,6 +59,22 @@ export async function startDynalite(options: DynaliteOptions = {}): Promise<Dyna
};
}

export async function waitForTableActive(
doc: DynamoDBDocument,
tableName: string,
timeoutMs = 5000
): Promise<void> {
const deadline = Date.now() + timeoutMs;
while (Date.now() < deadline) {
const result = await doc.send(new DescribeTableCommand({ TableName: tableName }));
if (result.Table?.TableStatus === "ACTIVE") {
return;
}
await new Promise(resolve => setTimeout(resolve, 50));
}
throw new Error(`Table ${tableName} did not become ACTIVE within ${timeoutMs}ms`);
}

async function pickFreePort(): Promise<number> {
return new Promise<number>((resolve, reject) => {
const probe = createServer();
Expand Down
4 changes: 3 additions & 1 deletion __tests__/integration/pipeline.bulkAndRetry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { DdbScanner } from "~/features/DdbScanner/index.js";
import { DdbProcessor } from "~/features/DdbProcessor/index.js";
import { TargetDynamoDbClient } from "~/services/DynamoDbClient/abstractions/DynamoDbClient.js";
import type { BaseRecord } from "~/domain/transform/types/records.js";
import { startDynalite, type DynaliteInstance } from "./dynalite.ts";
import { startDynalite, waitForTableActive, type DynaliteInstance } from "./dynalite.ts";
import { createDdbIntegrationContainer } from "./integrationContainer.ts";

const FAKE_CREDS = { accessKeyId: "test", secretAccessKey: "test" };
Expand Down Expand Up @@ -154,6 +154,8 @@ describe("pipeline — bulk + retry against dynalite", () => {
};
await createDdbTable(doc, pair.source);
await createDdbTable(doc, pair.target);
await waitForTableActive(doc, pair.source);
await waitForTableActive(doc, pair.target);
return pair;
}

Expand Down
Loading