Skip to content

Commit

Permalink
Replaced RunIsolatesTest with IsolatesRunSimultaneously, which won't …
Browse files Browse the repository at this point in the history
…fail when the test machine is slow.
  • Loading branch information
oliverbock committed Nov 8, 2018
1 parent 75af582 commit 5bc4e57
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions Tests/Noesis.Javascript.Tests/IsolationTests.cs
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using FluentAssertions;
using System;

namespace Noesis.Javascript.Tests
{
Expand All @@ -14,29 +15,29 @@ namespace Noesis.Javascript.Tests
public class IsolationTests
{
[TestMethod]
public void RunIsolatesTest()
public void IsolatesRunSimultaneously()
{

Stopwatch timer = new Stopwatch();
timer.Start();

Thread thread = new Thread(RunInstance);
thread.Start(); // First instance
RunInstance(); // Second instance
thread.Join();

timer.ElapsedMilliseconds.Should().BeLessThan(1999, "It took too long, they must not be running in parallel.");
var thread1_started = new EventWaitHandle(false, EventResetMode.ManualReset);
var thread2_started = new EventWaitHandle(false, EventResetMode.ManualReset);
Thread thread1 = new Thread(() => RunAndCallbackIntoCsharp(() => {
thread1_started.Set();
thread2_started.WaitOne();
}));
Thread thread2 = new Thread(() => RunAndCallbackIntoCsharp(() => {
thread2_started.Set();
thread1_started.WaitOne();
}));
thread1.Start();
thread2.Start();
thread1.Join();
thread2.Join();
}

static void RunInstance()
static void RunAndCallbackIntoCsharp(Action run_in_javascript_thread)
{
using (JavascriptContext context = new JavascriptContext()) {
int i = (int)context.Run(@"
var started = new Date();
var i = 0;
while (new Date().getTime() - started.getTime() < 1000)
i ++;
i;");
context.SetParameter("csharp_code", run_in_javascript_thread);
context.Run("csharp_code();");
}
}

Expand Down

0 comments on commit 5bc4e57

Please sign in to comment.