Skip to content

Commit 2f2a558

Browse files
hardfistCPunisher
andauthored
fix: fix flaky wasm tests (#13655)
* chore: add debugger * chore: parallel run wasm ci * chore: remove debugger * Revert "chore: remove debugger" This reverts commit 9cf41c2. * chore: max workers * Reapply "chore: remove debugger" This reverts commit 4b2b18a. * chore: wasi sdk * chore: remote custom wasi * chore: try increase increase memory * chore: try decrease memory * chore: limit memory to 2G * chore: adjust 2gb * chore: udpate comment * chore: update --------- Co-authored-by: CPunisher <1343316114@qq.com>
1 parent 0d4e1e9 commit 2f2a558

File tree

10 files changed

+39
-25
lines changed

10 files changed

+39
-25
lines changed

.cargo/config.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ rustflags = [
5555
[target.wasm32-wasip1-threads]
5656
rustflags = [
5757
"-C",
58-
"target-feature=+simd128",
58+
"target-feature=+simd128",
59+
"-C",
60+
# Set initial and max memory to 2GB to disable memory.grow at runtime.
61+
# The allocator uses this link-time value to decide whether to call memory.grow,
62+
# so it must match the runtime initial pages to ensure memory.grow is never called.
63+
"link-args=--initial-memory=2147483648 --max-memory=2147483648",
5964
"--cfg", "tokio_unstable"
6065
]
6166

.github/workflows/reusable-build-build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ jobs:
156156
- name: Build wasm32-wasip1-threads with linux
157157
if: ${{ inputs.target == 'wasm32-wasip1-threads' && inputs.profile != 'release' }}
158158
run: |
159+
159160
DISABLE_PLUGIN=1 RUST_TARGET=wasm32-wasip1-threads RSPACK_TARGET_BROWSER=1 pnpm build:binding:${{ inputs.profile }}
160161
DISABLE_PLUGIN=1 RUST_TARGET=wasm32-wasip1-threads pnpm build:binding:${{ inputs.profile }}
161162

.github/workflows/reusable-build-test.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,7 @@ jobs:
172172
NODE_NO_WARNINGS: 1
173173
WASM: 1
174174
RSPACK_LOADER_WORKER_THREADS: 1
175-
NODE_OPTIONS: '--max_old_space_size=8192 --stack-trace-limit=100'
176-
run: pnpm run build:js && pnpm --filter "@rspack/cli" test && pnpm --filter "@rspack/tests" test
175+
run: pnpm run test:ci
177176

178177
- name: Upload Test Reporter
179178
if: always()

crates/node_binding/rspack.wasi-browser.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ const __wasmUrl = new URL('./rspack.wasm32-wasi.wasm', import.meta.url).href
2121
const __emnapiContext = __emnapiGetDefaultContext()
2222
__emnapiContext.feature.Buffer = Buffer
2323

24+
// Allocate 2GB fixed shared memory (initial == maximum to disable memory.grow).
2425
const __sharedMemory = new WebAssembly.Memory({
25-
initial: 16384,
26-
maximum: 65536,
26+
initial: 32768,
27+
maximum: 32768,
2728
shared: true,
2829
})
2930

@@ -57,6 +58,10 @@ const {
5758
...importObject.napi,
5859
...importObject.emnapi,
5960
memory: __sharedMemory,
61+
// Override emnapi's napi_adjust_external_memory to a no-op.
62+
// emnapi implements this by calling memory.grow, but we've disabled memory.grow
63+
// (initial == maximum).
64+
napi_adjust_external_memory() { return 0 },
6065
}
6166
return importObject
6267
},

crates/node_binding/rspack.wasi.cjs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ const __wasi = new __nodeWASI({
2626

2727
const __emnapiContext = __emnapiGetDefaultContext()
2828

29+
// Allocate 2GB fixed shared memory (initial == maximum to disable memory.grow).
2930
const __sharedMemory = new WebAssembly.Memory({
30-
initial: 16384,
31-
maximum: 65536,
31+
initial: 32768,
32+
maximum: 32768,
3233
shared: true,
3334
})
3435

@@ -97,6 +98,10 @@ const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule
9798
...importObject.napi,
9899
...importObject.emnapi,
99100
memory: __sharedMemory,
101+
// Override emnapi's napi_adjust_external_memory to a no-op.
102+
// emnapi implements this by calling memory.grow, but we've disabled memory.grow
103+
// (initial == maximum).
104+
napi_adjust_external_memory() { return 0 },
100105
}
101106
return importObject
102107
},

crates/node_binding/wasi-worker-browser.mjs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ const handler = new MessageHandler({
1616
// eslint-disable-next-line no-console
1717
console.log.apply(console, arguments)
1818
},
19-
printErr: function() {
19+
printErr: function () {
2020
// eslint-disable-next-line no-console
2121
console.error.apply(console, arguments)
22-
22+
2323
errorOutputs.push([...arguments])
2424
},
2525
})
@@ -32,6 +32,10 @@ const handler = new MessageHandler({
3232
...importObject.napi,
3333
...importObject.emnapi,
3434
memory: wasmMemory,
35+
// Override emnapi's napi_adjust_external_memory to a no-op.
36+
// emnapi implements this by calling memory.grow, but we've disabled memory.grow
37+
// (initial == maximum).
38+
napi_adjust_external_memory() { return 0 },
3539
}
3640
},
3741
})

crates/node_binding/wasi-worker.mjs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Object.assign(globalThis, {
1919
require,
2020
Worker,
2121
importScripts: function (f) {
22-
;(0, eval)(fs.readFileSync(f, "utf8") + "//# sourceURL=" + f);
22+
; (0, eval)(fs.readFileSync(f, "utf8") + "//# sourceURL=" + f);
2323
},
2424
postMessage: function (msg) {
2525
if (parentPort) {
@@ -51,7 +51,11 @@ const handler = new MessageHandler({
5151
...importObject.env,
5252
...importObject.napi,
5353
...importObject.emnapi,
54-
memory: wasmMemory
54+
memory: wasmMemory,
55+
// Override emnapi's napi_adjust_external_memory to a no-op.
56+
// emnapi implements this by calling memory.grow, but we've disabled memory.grow
57+
// (initial == maximum).
58+
napi_adjust_external_memory() { return 0 },
5559
};
5660
},
5761
});

packages/rspack-cli/rstest.config.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ const wasmConfig: RstestConfig | undefined = process.env.WASM
55
exclude: [
66
'**/*/profile.test.ts', // Skip due to lack of system api support
77
],
8-
pool: {
9-
maxWorkers: 1,
10-
},
11-
maxConcurrency: 1,
128
}
139
: undefined;
1410

packages/rspack-test-tools/src/test/creator.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ export interface IBasicCaseCreatorOptions {
4444
[key: string]: unknown;
4545
}
4646

47-
const DEFAULT_MAX_CONCURRENT = process.env.WASM
48-
? 1
49-
: Number(process.env.DEFAULT_MAX_CONCURRENT) || 5;
47+
const DEFAULT_MAX_CONCURRENT = Number(process.env.DEFAULT_MAX_CONCURRENT) || 5;
5048

5149
export class BasicCaseCreator {
5250
protected currentConcurrent = 0;
@@ -89,9 +87,7 @@ export class BasicCaseCreator {
8987
testConfig,
9088
options,
9189
);
92-
const concurrent = process.env.WASM
93-
? 1
94-
: testConfig.concurrent || options.concurrent;
90+
const concurrent = testConfig.concurrent || options.concurrent;
9591
if (options.describe) {
9692
if (run) {
9793
if (concurrent) {

tests/rspack-test/rstest.config.mts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ const wasmConfig = process.env.WASM && defineProject({
3333
"Incremental-*.test.js",
3434
"NativeWatcher*.test.js",
3535
],
36-
maxConcurrency: 1,
3736
});
3837

3938
const testFilter = process.argv.includes("--test") || process.argv.includes("-t")
@@ -44,9 +43,9 @@ const testFilter = process.argv.includes("--test") || process.argv.includes("-t"
4443
]
4544
: undefined;
4645

47-
const reporters: RstestConfig['reporters'] = testFilter ? ['verbose' as const] : ['default' as const];
46+
const reporters: RstestConfig['reporters'] = testFilter ? ['verbose' as const] : ['default' as const];
4847
if (process.env.CI) {
49-
reporters.push(new StreamedEventReporter( path.join(__dirname, '../../', 'rspack-test-event-report.txt')));
48+
reporters.push(new StreamedEventReporter(path.join(__dirname, '../../', 'rspack-test-event-report.txt')));
5049
}
5150

5251
const sharedConfig = defineProject({
@@ -139,7 +138,7 @@ export default defineConfig({
139138
}],
140139
reporters,
141140
pool: {
142-
maxWorkers: process.env.WASM ? 1 : "80%",
141+
maxWorkers: "80%",
143142
execArgv: ['--no-warnings', '--expose-gc', '--max-old-space-size=8192', '--experimental-vm-modules'],
144143
},
145144
});

0 commit comments

Comments
 (0)