Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM denoland/deno:2.8.1
FROM denoland/deno:2.9.4

# Install tools
RUN apt-get update && \
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
with:
fetch-depth: 0

- name: Setup Deno v2.8.1
- name: Setup Deno v2.9.4
uses: denoland/setup-deno@v2
with:
deno-version: v2.8.1
deno-version: v2.9.4

- name: Setup LCOV
run: sudo apt install -y lcov
Expand All @@ -45,7 +45,7 @@ jobs:
strategy:
fail-fast: false
matrix:
deno-version: [v1.46.3, v2.8.1]
deno-version: [v1.46.3, v2.9.4]
os: [ ubuntu-latest, windows-latest ]
runs-on: ${{ matrix.os }}

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/sonar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ jobs:
ref: ${{ steps.pr.outputs.head_sha }}
fetch-depth: 0

- name: Setup Deno v2.8.1
- name: Setup Deno v2.9.4
uses: denoland/setup-deno@v2
with:
deno-version: v2.8.1
deno-version: v2.9.4

- name: Setup LCOV
run: sudo apt install -y lcov
Expand Down
2 changes: 1 addition & 1 deletion tests/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ export {
beforeAll,
afterEach
} from 'jsr:@std/testing@1.0.19/bdd';
export { delay } from 'jsr:@std/async@1.4.0/delay';
export { delay } from 'jsr:@std/async@1.5.0/delay';
export { load } from 'jsr:@std/dotenv@0.225.7';
export * as mf from 'https://deno.land/x/mock_fetch@0.3.0/mod.ts';
37 changes: 33 additions & 4 deletions tests/utils/timed-match.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,36 @@ const okInput = "a";
const nokRE = "^(([a-z])+.)+[A-Z]([a-z])+$";
const nokInput = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";

const COLD_TIME = 500;
const WARM_TIME = 50;
const TIMEOUT = 950; // 50ms margin for worker thread to finish
const COLD_TIME = 900;
const WARM_TIME = 150;
const TIMEOUT = 900; // margin for worker thread to finish

// TimedMatch.setMaxTimeLimit has no getter; track the value tests intend to
// use so warmUpWorker() can restore it after temporarily raising it.
let intendedMaxTimeLimit = 1000;
const setMaxTimeLimit = (value: number) => {
intendedMaxTimeLimit = value;
TimedMatch.setMaxTimeLimit(value);
};

// A freshly (re)created worker pays a one-time JIT/module-instrumentation
// cost on its FIRST real regex dispatch (much larger under `deno test
// --coverage`, which also instruments the worker module). Calls after that
// on the same worker are fast (see the warm loop below). Issue a cheap
// throwaway match right after the worker is (re)created so that cost is
// paid during warm-up instead of during a timing-sensitive assertion.
//
// The warm-up dispatch itself must not be allowed to exceed the *current*
// maxTimeLimit: doing so would make TimedMatch treat the warm-up call as a
// timeout, recreate the worker again, and add an entry to the blacklist -
// potentially evicting the entry a test just set up (maxBlackListed is set
// to 1 in several tests). Temporarily raise the limit for the warm-up call
// only, then restore whatever the test currently expects.
const warmUpWorker = () => {
TimedMatch.setMaxTimeLimit(5000);
TimedMatch.tryMatch([okRE], okInput);
TimedMatch.setMaxTimeLimit(intendedMaxTimeLimit);
};

const getTimer = (timer: number) => (timer - Date.now()) * -1;

Expand All @@ -21,7 +48,8 @@ describe("Timed-Match tests:", function () {
beforeEach(() => {
TimedMatch.clearBlackList();
TimedMatch.setMaxBlackListed(50);
TimedMatch.setMaxTimeLimit(1000);
setMaxTimeLimit(1000);
warmUpWorker();
});

afterAll(() => {
Expand All @@ -48,6 +76,7 @@ describe("Timed-Match tests:", function () {
timer = Date.now();
TimedMatch.tryMatch([nokRE], nokInput);
assertTrue(getTimer(timer) > TIMEOUT);
warmUpWorker();

timer = Date.now();
TimedMatch.tryMatch([okRE], okInput);
Expand Down