Skip to content

Commit

Permalink
test: wait for trigger to fire
Browse files Browse the repository at this point in the history
  • Loading branch information
allanhvam committed Dec 6, 2024
1 parent 2c7889d commit 96268b3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/tests/triggers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import assert from "node:assert";
import { Worker } from "../worker/Worker.js";
import { DurableFunctionsWorkflowHistoryStore } from "../stores/index.js";
import { startup } from "./workflows/startup.js";
import { sleep } from "../sleep.js";

test.before(async () => {
const worker = Worker.getInstance();
Expand Down Expand Up @@ -36,6 +37,7 @@ void test("startup trigger args", async (t) => {

// Act
await workflow.start();
await sleep("1s"); // Wait for trigger to fire

// Assert
const result = await store.getInstances();
Expand Down
4 changes: 2 additions & 2 deletions src/tests/workflows.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ void test("Workflow", async (t) => {

// Assert
assert.equal(result, 3);
assert.ok(workflows.has("math"));
assert.ok(workflows.has(workflow.name));

const now = new Date();
const from = new Date(now.getTime() - ms("2m"));
const instances = await store.getInstances({ filter: { from, to: now } });
const mathInstances = instances.instances.filter(i => i.instanceId.indexOf("math ") === 0);
const mathInstances = instances.instances.filter(i => i.instanceId.indexOf(`${workflow.name} `) === 0);

assert.ok(mathInstances.length >= 1);
});

0 comments on commit 96268b3

Please sign in to comment.