Skip to content

Commit af78792

Browse files
authored
Fix test_prepost_run_dep after #24890 (#24898)
- Cleanup the test - Add and `id` to the `addRunDependency` call. - Add `.unref` to prevent the dependency watcher from keeping the node process alive. Prior to #24890 the lack of `id` in used in the test caused it to skip the dependency watcher. - Add `--closure=1` to make sure closure doesn't minify the `.unref` call. - Add some RUNTIME_DEBUG logging to add/removeRunDependency.
1 parent a344849 commit af78792

File tree

6 files changed

+39
-28
lines changed

6 files changed

+39
-28
lines changed

src/preamble.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ function addRunDependency(id) {
251251
#endif
252252

253253
#if ASSERTIONS
254+
#if RUNTIME_DEBUG
255+
dbg('addRunDependency', id);
256+
#endif
254257
assert(id, 'addRunDependency requires an ID')
255258
assert(!runDependencyTracking[id]);
256259
runDependencyTracking[id] = 1;
@@ -274,6 +277,11 @@ function addRunDependency(id) {
274277
err('(end of list)');
275278
}
276279
}, 10000);
280+
#if ENVIRONMENT_MAY_BE_NODE
281+
// Prevent this timer from keeping the runtime alive if nothing
282+
// else is.
283+
runDependencyWatcher.unref?.()
284+
#endif
277285
}
278286
#endif
279287
}
@@ -286,6 +294,9 @@ function removeRunDependency(id) {
286294
#endif
287295

288296
#if ASSERTIONS
297+
#if RUNTIME_DEBUG
298+
dbg('removeRunDependency', id);
299+
#endif
289300
assert(id, 'removeRunDependency requires an ID');
290301
assert(runDependencyTracking[id]);
291302
delete runDependencyTracking[id];

test/code_size/test_codesize_hello_O0.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 22449,
3-
"a.out.js.gz": 8326,
2+
"a.out.js": 22462,
3+
"a.out.js.gz": 8336,
44
"a.out.nodebug.wasm": 15143,
55
"a.out.nodebug.wasm.gz": 7452,
6-
"total": 37592,
7-
"total_gz": 15778,
6+
"total": 37605,
7+
"total_gz": 15788,
88
"sent": [
99
"fd_write"
1010
],

test/code_size/test_codesize_minimal_O0.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 17710,
3-
"a.out.js.gz": 6612,
2+
"a.out.js": 17723,
3+
"a.out.js.gz": 6621,
44
"a.out.nodebug.wasm": 1136,
55
"a.out.nodebug.wasm.gz": 659,
6-
"total": 18846,
7-
"total_gz": 7271,
6+
"total": 18859,
7+
"total_gz": 7280,
88
"sent": [],
99
"imports": [],
1010
"exports": [
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
2-
"hello_world.js": 53804,
3-
"hello_world.js.gz": 17065,
2+
"hello_world.js": 53923,
3+
"hello_world.js.gz": 17123,
44
"hello_world.wasm": 15143,
55
"hello_world.wasm.gz": 7452,
66
"no_asserts.js": 26714,
77
"no_asserts.js.gz": 8952,
88
"no_asserts.wasm": 12227,
99
"no_asserts.wasm.gz": 6008,
10-
"strict.js": 51854,
11-
"strict.js.gz": 16403,
10+
"strict.js": 51973,
11+
"strict.js.gz": 16455,
1212
"strict.wasm": 15143,
1313
"strict.wasm.gz": 7438,
14-
"total": 174885,
15-
"total_gz": 63318
14+
"total": 175123,
15+
"total_gz": 63428
1616
}

test/other/codesize/test_codesize_minimal_O0.expected.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,9 @@ function addRunDependency(id) {
531531
err('(end of list)');
532532
}
533533
}, 10000);
534+
// Prevent this timer from keeping the runtime alive if nothing
535+
// else is.
536+
runDependencyWatcher.unref?.()
534537
}
535538
}
536539

test/test_other.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2850,21 +2850,19 @@ def test_get_proc_address_error_message(self):
28502850
})
28512851
def test_prepost(self, no_initial_run, run_dep):
28522852
create_file('pre.js', '''
2853-
var Module = {
2854-
preRun: () => out('pre-run'),
2855-
postRun: () => out('post-run')
2853+
Module = {
2854+
"preRun": () => out('pre-run'),
2855+
"postRun": () => out('post-run')
28562856
};
28572857
''')
28582858

2859-
self.run_process([EMCC, test_file('hello_world.c'), '--pre-js', 'pre.js', '-sWASM_ASYNC_COMPILATION=0'])
2860-
self.assertContained('pre-run\nhello, world!\npost-run\n', self.run_js('a.out.js'))
2859+
self.do_runf('hello_world.c', 'pre-run\nhello, world!\npost-run\n', cflags=['--pre-js', 'pre.js', '-sWASM_ASYNC_COMPILATION=0'])
28612860

28622861
# addRunDependency during preRun should prevent main, and post-run from
28632862
# running.
28642863
with open('pre.js', 'a') as f:
2865-
f.write('Module.preRun = () => { out("add-dep"); addRunDependency(); }\n')
2866-
self.run_process([EMCC, test_file('hello_world.c'), '--pre-js', 'pre.js', '-sWASM_ASYNC_COMPILATION=0'])
2867-
output = self.run_js('a.out.js')
2864+
f.write('Module["preRun"] = () => { out("add-dep"); addRunDependency("dep"); }\n')
2865+
output = self.do_runf('hello_world.c', cflags=['--pre-js', 'pre.js', '-sRUNTIME_DEBUG', '-sWASM_ASYNC_COMPILATION=0', '-O2', '--closure=1'])
28682866
self.assertContained('add-dep\n', output)
28692867
self.assertNotContained('hello, world!\n', output)
28702868
self.assertNotContained('post-run\n', output)
@@ -2874,21 +2872,20 @@ def test_prepost(self, no_initial_run, run_dep):
28742872
if no_initial_run:
28752873
args += ['-sINVOKE_RUN=0']
28762874
if run_dep:
2877-
create_file('pre.js', 'Module.preRun = () => addRunDependency("test");')
2875+
create_file('pre.js', 'Module["preRun"] = () => addRunDependency("test");')
28782876
create_file('post.js', 'removeRunDependency("test");')
28792877
args += ['--pre-js', 'pre.js', '--post-js', 'post.js']
28802878

2881-
self.run_process([EMCC, test_file('hello_world.c')] + args)
2882-
output = self.run_js('a.out.js')
2879+
output = self.do_runf('hello_world.c', cflags=args)
28832880
self.assertContainedIf('hello, world!', output, not no_initial_run)
28842881

28852882
if no_initial_run:
28862883
# Calling main later should still work, filesystem etc. must be set up.
28872884
print('call main later')
2888-
src = read_file('a.out.js')
2885+
src = read_file('hello_world.js')
28892886
src += '\nout("callMain -> " + Module.callMain());\n'
2890-
create_file('a.out.js', src)
2891-
self.assertContained('hello, world!\ncallMain -> 0\n', self.run_js('a.out.js'))
2887+
create_file('hello_world.js', src)
2888+
self.assertContained('hello, world!\ncallMain -> 0\n', self.run_js('hello_world.js'))
28922889

28932890
def test_prepost2(self):
28942891
create_file('pre.js', 'Module.preRun = () => out("pre-run");')

0 commit comments

Comments
 (0)