test(ext/ffi): Increase timeout value in event loop integration test callback #18394
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The test has flakes for essentially the same reason as what it is trying to test: How asynchronous work started from FFI callbacks gets resolved.
Due to Deno using the
v8::MicrotasksPolicy::kAuto
for handling microtasks, the microtask queue is drained synchronously when the script call depth decrements to zero. FFI callbacks coming from foreign threads get called one at a time from an empty scope created expressly for the purpose of calling that particular callback. As a result, each FFI callback immediately drains the microtask queue upon its completion.The test uses two calls,
queueMicrotask
andsetTimeout
to respectively push one microtask into the queue and push one macrotask into their separate queue. However,setTimeout
isn't exactly guaranteed to create a macrotask. A short enough timeout can cause the task to become a microtask instead. The 10 ms timeout had been chosen as a safe bound but apparently it is not quite safe enough. The flake occurs when thesetTimeout
manages to inch itself into the microtask queue:The test expects that first the "Sync" will be logged from the callback directly, then "Async" from the
queueMicrotask
microtask. Then, the Rust code calling the callback will log its "STORED_FUNCTION called", after which finally thesetTimeout
task logs "Timeout". WhensetTimeout
gets into the microtask queue, it instead logs before the Rust code is returned to.From a JS point of view this would look like this to: