Skip to content

Commit b0946b9

Browse files
authored
chore: smaller improvements and cleanup (#808)
1 parent 0a4e008 commit b0946b9

File tree

4 files changed

+49
-6
lines changed

4 files changed

+49
-6
lines changed

.github/workflows/nodejs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
fail-fast: false
3939
matrix:
4040
os: [ubuntu-latest, macos-latest, windows-latest]
41-
node-version: [20.x, 22.x, 23.x]
41+
node-version: [20.x, 22.x, 24.x]
4242
runs-on: ${{matrix.os}}
4343
steps:
4444
- uses: actions/checkout@v4

src/histogram.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ export class PiscinaHistogramHandler {
5151
return this.#runTime.count;
5252
}
5353

54-
get waitTimeCount(): number {
55-
return this.#waitTime.count;
56-
}
57-
5854
recordRunTime(value: number) {
5955
this.#runTime.record(PiscinaHistogramHandler.toHistogramIntegerNano(value));
6056
}

src/worker.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
commonState.isWorkerThread = true;
2424
commonState.workerData = workerData;
2525

26+
/* c8 ignore next*/
2627
function noop (): void {}
2728

2829
const handlerCache : Map<string, Function> = new Map();
@@ -70,6 +71,7 @@ async function getHandler (filename : string, name : string) : Promise<Function
7071

7172
// Limit the handler cache size. This should not usually be an issue and is
7273
// only provided for pathological cases.
74+
/* c8 ignore next */
7375
if (handlerCache.size > 1000) {
7476
const [[key]] = handlerCache;
7577
handlerCache.delete(key);
@@ -132,6 +134,7 @@ function atomicsWaitLoop (port : MessagePort, sharedBuffer : Int32Array) {
132134
const { async, value } = Atomics.waitAsync(sharedBuffer, kRequestCountField, lastSeenRequestCount);
133135

134136
// We do not check for result
137+
/* c8 ignore start */
135138
return async === true && value.then(() => {
136139
lastSeenRequestCount = Atomics.load(sharedBuffer, kRequestCountField);
137140

@@ -142,6 +145,7 @@ function atomicsWaitLoop (port : MessagePort, sharedBuffer : Int32Array) {
142145
onMessage(port, sharedBuffer, entry.message);
143146
}
144147
});
148+
/* c8 ignore stop */
145149
}
146150

147151
while (currentTasks === 0) {
@@ -231,5 +235,5 @@ async function onMessage (
231235
}
232236

233237
function throwInNextTick (error : Error) {
234-
process.nextTick((e: Error) => { throw e; }, error);
238+
queueMicrotask(() => { throw error; });
235239
}

test/histogram.test.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,49 @@ test('pool will maintain run and wait time histograms by default', async (t: Tes
3535
t.assert.strictEqual(typeof histogram.resetWaitTime, 'function');
3636
});
3737

38+
test('pool will maintain reset histograms upon call', async (t: TestContext) => {
39+
const pool = new Piscina({
40+
filename: resolve(__dirname, 'fixtures/eval.js')
41+
});
42+
43+
const tasks = [];
44+
for (let n = 0; n < 10; n++) {
45+
tasks.push(pool.run('42'));
46+
}
47+
await Promise.all(tasks);
48+
49+
const histogram = pool.histogram;
50+
let waitTime = histogram.waitTime;
51+
t.assert.ok(waitTime);
52+
t.assert.strictEqual(typeof waitTime.average, 'number');
53+
t.assert.strictEqual(typeof waitTime.mean, 'number');
54+
t.assert.strictEqual(typeof waitTime.stddev, 'number');
55+
t.assert.ok(waitTime.min > 0);
56+
t.assert.ok(waitTime.max > 0);
57+
58+
let runTime = histogram.runTime;
59+
t.assert.ok(runTime);
60+
t.assert.strictEqual(typeof runTime.average, 'number');
61+
t.assert.strictEqual(typeof runTime.mean, 'number');
62+
t.assert.strictEqual(typeof runTime.stddev, 'number');
63+
t.assert.ok(runTime.min > 0);
64+
t.assert.ok(runTime.max > 0);
65+
66+
histogram.resetRunTime();
67+
runTime = histogram.runTime;
68+
t.assert.ok(Number.isNaN(runTime.average));
69+
t.assert.ok(Number.isNaN(runTime.mean));
70+
t.assert.ok(Number.isNaN(runTime.stddev));
71+
t.assert.strictEqual(runTime.max, 0);
72+
73+
histogram.resetWaitTime();
74+
waitTime = histogram.waitTime;
75+
t.assert.ok(Number.isNaN(waitTime.average));
76+
t.assert.ok(Number.isNaN(waitTime.mean));
77+
t.assert.ok(Number.isNaN(waitTime.stddev));
78+
t.assert.strictEqual(waitTime.max, 0);
79+
});
80+
3881
test('pool will maintain run and wait time histograms when recordTiming is true', async (t: TestContext) => {
3982
const pool = new Piscina({
4083
filename: resolve(__dirname, 'fixtures/eval.js'),

0 commit comments

Comments
 (0)