diff --git a/Jint.Tests.Test262/Test262Test.cs b/Jint.Tests.Test262/Test262Test.cs index ca642a5683..dca9890f76 100644 --- a/Jint.Tests.Test262/Test262Test.cs +++ b/Jint.Tests.Test262/Test262Test.cs @@ -42,10 +42,15 @@ private static Engine BuildTestExecutor(Test262File file, Test262AgentManager? a var delay = (int)TypeConverter.ToNumber(args.At(1)); if (callback is ICallable callable) { - Task.Run(async () => + _ = Task.Run(async () => { await Task.Delay(delay); - callable.Call(JsValue.Undefined, Arguments.Empty); + // Queue callback to event loop instead of calling directly from background thread + // to avoid race conditions with concurrent JavaScript execution + engine.AddToEventLoop(() => + { + callable.Call(JsValue.Undefined, Arguments.Empty); + }); }); } return JsValue.Undefined; diff --git a/Jint.Tests/Runtime/ExecutionConstraintTests.cs b/Jint.Tests/Runtime/ExecutionConstraintTests.cs index fa761644ef..c8dd513c86 100644 --- a/Jint.Tests/Runtime/ExecutionConstraintTests.cs +++ b/Jint.Tests/Runtime/ExecutionConstraintTests.cs @@ -326,7 +326,7 @@ public void ShouldConsiderConstraintsWhenCallingInvoke() { var engine = new Engine(options => { - options.TimeoutInterval(TimeSpan.FromMilliseconds(100)); + options.TimeoutInterval(TimeSpan.FromMilliseconds(1000)); }); var myApi = new MyApi(); @@ -337,7 +337,7 @@ public void ShouldConsiderConstraintsWhenCallingInvoke() foreach (var callback in dataReceivedCallbacks) { engine.Invoke(callback.Value, "Data Received #1"); - Thread.Sleep(101); + Thread.Sleep(200); engine.Invoke(callback.Value, "Data Received #2"); } }