Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ int sync_tunnel_bool(bool);
int main() {
#ifdef BAD
EM_ASM({
globalThis.disableErrorReporting = true;
window.onerror = async (e) => {
var success = e.toString().indexOf("import sync_tunnel was not in ASYNCIFY_IMPORTS, but changed the state") > 0;
if (success) {
console.log("reporting success");
maybeReportResultToServer(0);
}
};
if (globalThis.window) {
globalThis.disableErrorReporting = true;
window.onerror = async (e) => {
var success = e.toString().indexOf("import sync_tunnel was not in ASYNCIFY_IMPORTS, but changed the state") > 0;
if (success) {
console.log("reporting success");
maybeReportResultToServer(0);
}
};
}
});
#endif
int x;
Expand All @@ -63,10 +65,13 @@ int main() {
// We should not get here.
printf("We should not get here\n");
assert(false);
return 1;
#else
// Success!
printf("done\n");
#ifdef REPORT_RESULT
REPORT_RESULT(0);
#endif

return 0;
#endif
}
File renamed without changes.
2 changes: 1 addition & 1 deletion test/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3299,7 +3299,7 @@ def test_async_iostream(self):
def test_async_returnvalue(self, args):
if '@' in str(args):
create_file('filey.txt', 'sync_tunnel\nsync_tunnel_bool\n')
self.btest('test_async_returnvalue.c', '0', cflags=['-sASSERTIONS', '-sASYNCIFY', '-sASYNCIFY_IGNORE_INDIRECT', '--js-library', test_file('browser/test_async_returnvalue.js')] + args)
self.btest('test_async_returnvalue.c', '0', cflags=['-sASSERTIONS', '-sASYNCIFY', '-sASYNCIFY_IGNORE_INDIRECT', '--js-library', test_file('test_async_returnvalue.js')] + args)

@no_safari('TODO: Never reports a result, so times out') # Fails in Safari 17.6 (17618.3.11.11.7, 17618), Safari 26.0.1 (21622.1.22.11.15)
def test_async_bad_list(self):
Expand Down
24 changes: 24 additions & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -10310,6 +10310,30 @@ def test(args, expected):
test(['-sASSERTIONS=1'],
'Aborted(RuntimeError: unreachable). "unreachable" may be due to ASYNCIFY_STACK_SIZE not being large enough (try increasing it)')

# Test an async return value. The value goes through a custom JS library
# method that uses asyncify, and therefore it needs to be declared in
# ASYNCIFY_IMPORTS.
# To make the test more precise we also use ASYNCIFY_IGNORE_INDIRECT here.
@parameterized({
'': (['-sASYNCIFY_IMPORTS=sync_tunnel,sync_tunnel_bool'],), # noqa
'pattern_imports': (['-sASYNCIFY_IMPORTS=[sync_tun*]'],), # noqa
'response': (['-sASYNCIFY_IMPORTS=@filey.txt'],), # noqa
'nothing': (['-DBAD'],), # noqa
'empty_list': (['-DBAD', '-sASYNCIFY_IMPORTS=[]'],), # noqa
'em_js_bad': (['-DBAD', '-DUSE_EM_JS'],), # noqa
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bunch of duplicated code with test_browser. Maybe we can just test this outside of the browser in the other file? That is, right after self.btest there, we can add self.do_runf?

Or, perhaps we can find a nice way to share such logic between browser and non-browser?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Specifically, I worry that we update one test over time, improving it, but forget to update the other version in the other file)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I share this concern, but also this is not a new things. We have many quite a few tests that are run both in browserpy and in other.py or core.py.

I agree it would be nice to have better way to express this duplication.

Also, how do we decide which tests should run in the browser at all? This test, for example, is not testing anything browser specific? Does that mean we should not run it under the browser?

Perhaps we should allow certain tests in test_other.py and test_core.py to be tagged as "@also_run_in_browser" ? Or perhaps we should run all other.py or core.py tests in the browser in certain CI configs.

All of this sounds quick complicated though...

My general feeling is if a test can run outside the browser then there should be a way to run it outside the browser. We have have a way to run browser tests using --browser=node.. maybe we should push more on that option?

I'll leave this PR as a draft for now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea to lean on --browser=node more. maybe a decorator could make a browser test also run in that mode, something like that - hopefully that is simple?

def test_async_returnvalue(self, args):
if '-DBAD' in args:
returncode = NON_ZERO
expected = 'import sync_tunnel was not in ASYNCIFY_IMPORTS, but changed the state'
else:
returncode = 0
expected = 'done\n'
if '@' in str(args):
create_file('filey.txt', 'sync_tunnel\nsync_tunnel_bool\n')
cflags = ['-sASSERTIONS', '-sASYNCIFY', '-sASYNCIFY_IGNORE_INDIRECT', '--js-library', test_file('test_async_returnvalue.js')]
self.do_runf('test_async_returnvalue.c', expected, assert_returncode=returncode, cflags=cflags + args)

# Sockets and networking

def test_inet(self):
Expand Down