Skip to content

Commit

Permalink
Print checks raw data to get snapshot to write tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kachick committed Apr 14, 2024
1 parent 0882530 commit 3bcf36c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28441,6 +28441,7 @@ async function run() {
}
(0, import_core2.startGroup)(`Polling ${attempts}: ${(/* @__PURE__ */ new Date()).toISOString()}`);
const checks = await fetchChecks(githubToken, trigger);
(0, import_core2.info)(JSON.stringify(checks, null, " "));
const report = generateReport(
checks,
trigger,
Expand Down
54 changes: 54 additions & 0 deletions report.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { performance } from 'node:perf_hooks';
import {
wait,
calcExponentialBackoffAndJitter,
readableDuration,
MIN_JITTER_MILLISECONDS,
MAX_JITTER_MILLISECONDS,
getIdleMilliseconds,
} from './wait.ts';

Check failure on line 9 in report.test.ts

View workflow job for this annotation

GitHub Actions / typecheck

Cannot find module './wait.ts' or its corresponding type declarations.
import test from 'node:test';
import assert from 'node:assert';

test('wait 100 ms', async () => {
performance.mark('start');
await wait(100);
performance.mark('end');
// The void typing looks like a wrong definition of @types/node
const measure: unknown = performance.measure('Wait duration', 'start', 'end');
// Also PerformanceMeasure looks not defined https://github.com/DefinitelyTyped/DefinitelyTyped/blame/be3a5a945efa53010eb2ed7fc35bcd46038909b0/types/node/v16/perf_hooks.d.ts
if (!(measure && typeof measure === 'object' && 'duration' in measure && typeof measure.duration === 'number')) {
throw Error('Performance API does incorrectly work');
}
assert(measure.duration >= 99);
assert(measure.duration < 150);
});

test('interval will be like a cheap exponential backoff', () => {
const minIntervalSeconds = 100;

assert(calcExponentialBackoffAndJitter(minIntervalSeconds, 1) >= (100000 + MIN_JITTER_MILLISECONDS));
assert(calcExponentialBackoffAndJitter(minIntervalSeconds, 1) < (100000 + MAX_JITTER_MILLISECONDS));
assert(calcExponentialBackoffAndJitter(minIntervalSeconds, 2) >= (200000 + MIN_JITTER_MILLISECONDS));
assert(calcExponentialBackoffAndJitter(minIntervalSeconds, 2) < (200000 + MAX_JITTER_MILLISECONDS));
assert(calcExponentialBackoffAndJitter(minIntervalSeconds, 3) >= (400000 + MIN_JITTER_MILLISECONDS));
assert(calcExponentialBackoffAndJitter(minIntervalSeconds, 3) < (400000 + MAX_JITTER_MILLISECONDS));
assert(calcExponentialBackoffAndJitter(minIntervalSeconds, 4) >= (800000 + MIN_JITTER_MILLISECONDS));
assert(calcExponentialBackoffAndJitter(minIntervalSeconds, 4) < (800000 + MAX_JITTER_MILLISECONDS));
assert(calcExponentialBackoffAndJitter(minIntervalSeconds, 5) >= (1600000 + MIN_JITTER_MILLISECONDS));
assert(calcExponentialBackoffAndJitter(minIntervalSeconds, 5) < (1600000 + MAX_JITTER_MILLISECONDS));
});

test('readableDuration', () => {
assert.strictEqual(readableDuration(454356), 'about 7.6 minutes');
assert.strictEqual(readableDuration(32100), 'about 32 seconds');
});

test('getIdleMilliseconds returns different value with the given method', () => {
const minIntervalSeconds = 100;

assert(getIdleMilliseconds('exponential_backoff', minIntervalSeconds, 5) >= (1600000 + MIN_JITTER_MILLISECONDS));
assert(getIdleMilliseconds('exponential_backoff', minIntervalSeconds, 5) < (1600000 + MAX_JITTER_MILLISECONDS));

assert.strictEqual(getIdleMilliseconds('equal_intervals', minIntervalSeconds, 5), minIntervalSeconds * 1000);
});
1 change: 1 addition & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ async function run(): Promise<void> {

startGroup(`Polling ${attempts}: ${(new Date()).toISOString()}`);
const checks = await fetchChecks(githubToken, trigger);
info(JSON.stringify(checks, null, '\t'));
const report = generateReport(
checks,
trigger,
Expand Down

0 comments on commit 3bcf36c

Please sign in to comment.