Make the timeout test more resilient

Since we don't keep timers sorted by deadline but by insertion order,
the test is flaky in slow environments (GHA seemingly). Increase the
timeouts to give it a bigger chance of success.

ASan / UBSan builds are notoriously slow, so skip the test in those.
This commit is contained in:
Saúl Ibarra Corretgé 2024-09-09 14:40:23 +02:00
parent 194c45c4b5
commit 54afb19745
3 changed files with 12 additions and 4 deletions

View file

@ -128,6 +128,9 @@ add_link_options(
)
elseif(CONFIG_UBSAN)
message(STATUS "Building with UBSan")
add_compile_definitions(
__UBSAN__=1
)
add_compile_options(
-fsanitize=undefined
-fno-sanitize-recover=all

3
qjs.c
View file

@ -140,6 +140,9 @@ static const JSCFunctionListEntry navigator_obj[] = {
static const JSCFunctionListEntry global_obj[] = {
JS_CFUNC_DEF("gc", 0, js_gc),
JS_OBJECT_DEF("navigator", navigator_obj, countof(navigator_obj), JS_PROP_C_W_E),
#if defined(__ASAN__) || defined(__UBSAN__)
JS_PROP_INT32_DEF("__running_with_sanitizer__", 1, JS_PROP_C_W_E ),
#endif
};
/* also used to initialize the worker context */

View file

@ -277,11 +277,13 @@ function test_timeout()
function test_timeout_order()
{
if (globalThis.__running_with_sanitizer__) return;
var s = "";
os.setTimeout(a, 1);
os.setTimeout(b, 2);
os.setTimeout(d, 5);
function a() { s += "a"; os.setTimeout(c, 0); }
os.setTimeout(a, 100);
os.setTimeout(b, 200);
os.setTimeout(d, 500);
function a() { s += "a"; os.setTimeout(c, 200); }
function b() { s += "b"; }
function c() { s += "c"; }
function d() { assert(s === "abc"); } // not "acb"