Skip to content

Commit

Permalink
🛣️ Parallize units tests (crypto, did, others)
Browse files Browse the repository at this point in the history
  • Loading branch information
KimlikDAO-bot committed Sep 14, 2024
1 parent 5f92f48 commit d796183
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ jobs:
- name: Run crypto benchmarks
run: |
bun i
bun run.js bench
bun test.js bench
47 changes: 27 additions & 20 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,52 @@ on:
branches: ["ana", "prod"]

jobs:
check_bun_tests:
name: Unit tests with bun
strategy:
fail-fast: true

bun_unit_tests:
name: bun unit tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: oven-sh/setup-bun@v2
- name: Run bun tests
run: |
- run: |
bun i
bun test --timeout 15000
id: test
check_compiled_bun:
name: Compiled tests with bun
strategy:
fail-fast: true
kdjs_unit_tests_crypto:
name: kdjs unit tests, crypto
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: oven-sh/setup-bun@v2
- run: |
bun i
bun test.js crypto
kdjs_unit_tests_did:
name: kdjs unit tests, did
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: oven-sh/setup-bun@v2
- name: "`kdjs` compiled tests with bun"
run: |
- run: |
bun i
bun run.js test
bun test.js did
kdjs_unit_tests_others:
name: kdjs unit tests, others
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: oven-sh/setup-bun@v2
- run: |
bun i
bun test.js test --filter did crypto
compile_kdjs_with_kdjs:
name: Compile `kdjs` with `kdjs`
strategy:
fail-fast: true

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: oven-sh/setup-bun@v2
- name: "Compile `kdjs` with `kdjs`"
run: |
- run: |
bun i
bun kdjs/kdjs.js kdjs/kdjs.js
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ The tests can be run in two different modes:
the packages are correctly typed and allows us to make measurements on the
compiled versions of the code.
```shell
bun run.js test
bun test.js test
```

To run tests in a certain directory, say `crypto`, you can also do
```shell
bun test crypto # uncompiled
bun run.js crypto # compiled
bun test.js crypto # compiled
```

When run, output will look like this:
Expand Down
13 changes: 12 additions & 1 deletion run.js → test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ const args = parseArgs(process.argv.slice(2), "target", {
args["buildConcurrency"] ||= 4;
args["runConcurrency"] ||= 4;

/**
* @param {!Array<string>} patterns
* @return {!RegExp}
*/
const createMatcher = (patterns) => {
const regexPattern = patterns.map((p) => p.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('|');
return new RegExp(regexPattern);
};

/**
* @param {string} pattern
* @param {string} command
Expand All @@ -25,9 +34,11 @@ const compileAndRunMatching = async (pattern, command, args) => {
const compileTasks = [];
const compileBN = bottleneck(args["buildConcurrency"] || args["concurrency"]);
const runBN = bottleneck(args["runConcurrency"] || args["concurrency"]);
/** @const {!Array<string>} */
const filter = createMatcher(["build/", "kastro/", "node_modules/"].concat(args["filter"] || []));

for await (const f of glob.scan(".")) {
if (f.startsWith("build") || f.includes("kastro") || f.includes("node_modules")) continue;
if (filter.test(f)) continue;
const output = `build/${f}`;
compileTasks.push(compileBN(() => compile({
...args,
Expand Down

0 comments on commit d796183

Please sign in to comment.