Skip to content

Commit

Permalink
test: simple wait queue
Browse files Browse the repository at this point in the history
  • Loading branch information
Natoandro committed Jan 16, 2025
1 parent ad8e667 commit 7838471
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/patterns/worker_manager/pooling_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright Metatype OÜ, licensed under the Mozilla Public License Version 2.0.
// SPDX-License-Identifier: MPL-2.0

import { createSimpleWaitQueue } from "@metatype/typegate/runtimes/patterns/worker_manager/pooling.ts";
import { assert, assertEquals, assertFalse } from "@std/assert";

Deno.test("simple wait queue", (t) => {
const queue = createSimpleWaitQueue<number>();

const history: number[] = [];

assertFalse(queue.shift(() => 1));
queue.push((v) => history.push(v), () => {});
assertEquals(history.length, 0);
queue.shift(() => 2);
assertEquals(history.length, 1);
assertEquals(history[0], 2);
assertFalse(queue.shift(() => 1));
queue.push((v) => history.push(v), () => {});
assertEquals(history.length, 1);
queue.shift(() => 3);
assertEquals(history.length, 2);
assertEquals(history[1], 3);
});

0 comments on commit 7838471

Please sign in to comment.