mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-17 23:33:12 +09:00
Merge pull request #1010 from bbassie/feature/plugin-browser
Plugin management through web interface
This commit is contained in:
1 parent
e36a76acc5
commit
ffe82f81d8
48 files changed
+4275
-536
No files matched your search
@@ -0,0 +1,48 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { setTimeout as sleep } from "node:timers/promises";
|
||||
|
||||
import { poll } from "../../packages/web_ui/src/util/poll.ts";
|
||||
|
||||
describe("web_ui/util/poll", function() {
|
||||
describe("poll()", function() {
|
||||
it("should keep every result of a task slower than the interval", async function() {
|
||||
let running = 0;
|
||||
let maxRunning = 0;
|
||||
const applied = [];
|
||||
let count = 0;
|
||||
const stop = poll(async () => {
|
||||
count += 1;
|
||||
const run = count;
|
||||
running += 1;
|
||||
maxRunning = Math.max(maxRunning, running);
|
||||
await sleep(20);
|
||||
running -= 1;
|
||||
applied.push(run);
|
||||
}, 1);
|
||||
await sleep(150);
|
||||
stop();
|
||||
await sleep(40);
|
||||
assert.equal(maxRunning, 1);
|
||||
assert.ok(applied.length >= 3, `only ${applied.length} runs finished`);
|
||||
assert.deepEqual(applied, applied.slice().sort((a, b) => a - b));
|
||||
assert.equal(applied.length, count);
|
||||
});
|
||||
|
||||
it("should not run again once stopped", async function() {
|
||||
let count = 0;
|
||||
const stop = poll(async () => { count += 1; }, 1);
|
||||
stop();
|
||||
await sleep(20);
|
||||
assert.equal(count, 1);
|
||||
});
|
||||
|
||||
it("should not run again when stopped while a run is in progress", async function() {
|
||||
let count = 0;
|
||||
const stop = poll(async () => { count += 1; await sleep(10); }, 1);
|
||||
await sleep(2);
|
||||
stop();
|
||||
await sleep(30);
|
||||
assert.equal(count, 1);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user