Skip to content

Commit

Permalink
api: Fix tests (they were broken before!)
Browse files Browse the repository at this point in the history
  • Loading branch information
victorges committed Apr 24, 2024
1 parent aff5120 commit 22e0160
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 4 additions & 0 deletions packages/api/src/util.ts
Expand Up @@ -62,6 +62,10 @@ export class Semaphore {
}

release() {
if (this.current <= 0) {
throw new Error("releasing semaphore that is not acquired");
}

if (this.waitQueue.length === 0) {
this.current--;
} else {
Expand Down
7 changes: 4 additions & 3 deletions packages/api/src/webhooks/cannon.test.ts
Expand Up @@ -286,7 +286,8 @@ describe("webhook cannon", () => {
expect(callCount).toBe(1);
expect(receivedEvent).toBe("stream.started");

sem = semaphore();
// at this point the semaphore is re-acquired cause we just waited (acquired) above

await server.queue.publishWebhook("events.stream.idle", {
type: "webhook_event",
id: "webhook_test_42",
Expand All @@ -301,7 +302,6 @@ describe("webhook cannon", () => {
expect(receivedEvent).toBe("stream.idle");

// does not receive some random event
sem = semaphore();
await server.queue.publishWebhook("events.stream.unknown" as any, {
type: "webhook_event",
id: "webhook_test_93",
Expand All @@ -311,7 +311,8 @@ describe("webhook cannon", () => {
userId: nonAdminUser.id,
});

await sem.wait(1000);
const err = await sem.wait(1000).catch((err) => err);
expect(err?.message).toBe("timeout");
expect(callCount).toBe(2);
});

Expand Down

0 comments on commit 22e0160

Please sign in to comment.