Martin Karkowski
4791914998
- Modified: - cli.runNopeBackend: added the flag "noBaseServices" to prevent providing the base-services - communication.getLayer.nodejs/browser: adding default value for logger - dispatcher.getDispatcher: changed option "constructorClass" to "dispatcherConstructorClass" - helpers.limit.spec: Adapted Timings - loader.getPackageLoader.nodejs/browser: Changed the options.
67 lines
1.8 KiB
TypeScript
67 lines
1.8 KiB
TypeScript
/**
|
|
* @author Martin Karkowski
|
|
* @email m.karkowski@zema.de
|
|
* @desc [description]
|
|
*/
|
|
|
|
import { describe, it } from "mocha";
|
|
import { sleep } from "./async";
|
|
import { limitedCalls } from "./limit";
|
|
|
|
describe("limit", function () {
|
|
// Describe the required Test:
|
|
|
|
describe("limitedCalls", function () {
|
|
it("single-call - sync", async () => {
|
|
const f = limitedCalls(sleep, {
|
|
maxParallel: 0,
|
|
});
|
|
const start = Date.now();
|
|
const promises = [f(100), f(100)];
|
|
await Promise.all(promises);
|
|
const end = Date.now();
|
|
if (end - start < 200) {
|
|
throw Error("Failed to call sync");
|
|
}
|
|
});
|
|
it("single-call - parallel", async () => {
|
|
const f = limitedCalls(sleep, {
|
|
maxParallel: 2,
|
|
});
|
|
const start = Date.now();
|
|
const promises = [f(100), f(100)];
|
|
await Promise.all(promises);
|
|
const end = Date.now();
|
|
if (end - start > 200) {
|
|
throw Error("Failed to call parallel");
|
|
}
|
|
});
|
|
it("single-call - between (sync)", async () => {
|
|
const f = limitedCalls<void>(async (...args) => {}, {
|
|
maxParallel: 0,
|
|
callbackBetween: () => sleep(50),
|
|
});
|
|
const start = Date.now();
|
|
const promises = [f(100), f(100)];
|
|
await Promise.all(promises);
|
|
const end = Date.now();
|
|
if (end - start < 50) {
|
|
throw Error("Failed to call callbackBetween");
|
|
}
|
|
});
|
|
it("single-call - between (parallel)", async () => {
|
|
const f = limitedCalls<void>(async (...args) => {}, {
|
|
maxParallel: 10,
|
|
callbackBetween: () => sleep(50),
|
|
});
|
|
const start = Date.now();
|
|
const promises = [f(100), f(100)];
|
|
await Promise.all(promises);
|
|
const end = Date.now();
|
|
if (end - start > 50) {
|
|
throw Error("Failed to call callbackBetween");
|
|
}
|
|
});
|
|
});
|
|
});
|