Commit 136279bb authored by Jeremy Meng's avatar Jeremy Meng

Disable Thread.Abort() usage for dnxcore.

Use Volatile wrapper.
parent 1a8a43e5
......@@ -38,17 +38,17 @@ public void ExplicitPublishMode()
Thread.Sleep(1000);
pub.Publish("abcd", "efg");
Thread.Sleep(500);
Assert.AreEqual(0, Thread.VolatileRead(ref a), "a1");
Assert.AreEqual(1, Thread.VolatileRead(ref b), "b1");
Assert.AreEqual(1, Thread.VolatileRead(ref c), "c1");
Assert.AreEqual(1, Thread.VolatileRead(ref d), "d1");
Assert.AreEqual(0, VolatileWrapper.Read(ref a), "a1");
Assert.AreEqual(1, VolatileWrapper.Read(ref b), "b1");
Assert.AreEqual(1, VolatileWrapper.Read(ref c), "c1");
Assert.AreEqual(1, VolatileWrapper.Read(ref d), "d1");
pub.Publish("*bcd", "efg");
Thread.Sleep(500);
Assert.AreEqual(1, Thread.VolatileRead(ref a), "a2");
//Assert.AreEqual(1, Thread.VolatileRead(ref b), "b2");
//Assert.AreEqual(1, Thread.VolatileRead(ref c), "c2");
//Assert.AreEqual(1, Thread.VolatileRead(ref d), "d2");
Assert.AreEqual(1, VolatileWrapper.Read(ref a), "a2");
//Assert.AreEqual(1, VolatileWrapper.Read(ref b), "b2");
//Assert.AreEqual(1, VolatileWrapper.Read(ref c), "c2");
//Assert.AreEqual(1, VolatileWrapper.Read(ref d), "d2");
}
}
......@@ -101,7 +101,7 @@ public void TestBasicPubSub(bool preserveOrder, string channelPrefix, bool wildC
{
Assert.AreEqual(0, received.Count);
}
Assert.AreEqual(0, Thread.VolatileRead(ref secondHandler));
Assert.AreEqual(0, VolatileWrapper.Read(ref secondHandler));
var count = sub.Publish(pubChannel, "def");
Ping(muxer, pub, sub, 3);
......@@ -110,7 +110,7 @@ public void TestBasicPubSub(bool preserveOrder, string channelPrefix, bool wildC
{
Assert.AreEqual(1, received.Count);
}
Assert.AreEqual(1, Thread.VolatileRead(ref secondHandler));
Assert.AreEqual(1, VolatileWrapper.Read(ref secondHandler));
// unsubscribe from first; should still see second
sub.Unsubscribe(subChannel, handler1);
......@@ -120,7 +120,7 @@ public void TestBasicPubSub(bool preserveOrder, string channelPrefix, bool wildC
{
Assert.AreEqual(1, received.Count);
}
Assert.AreEqual(2, Thread.VolatileRead(ref secondHandler));
Assert.AreEqual(2, VolatileWrapper.Read(ref secondHandler));
Assert.AreEqual(1, count);
// unsubscribe from second; should see nothing this time
......@@ -131,7 +131,7 @@ public void TestBasicPubSub(bool preserveOrder, string channelPrefix, bool wildC
{
Assert.AreEqual(1, received.Count);
}
Assert.AreEqual(2, Thread.VolatileRead(ref secondHandler));
Assert.AreEqual(2, VolatileWrapper.Read(ref secondHandler));
Assert.AreEqual(0, count);
}
}
......@@ -172,7 +172,7 @@ public void TestBasicPubSubFireAndForget(bool preserveOrder)
{
Assert.AreEqual(0, received.Count);
}
Assert.AreEqual(0, Thread.VolatileRead(ref secondHandler));
Assert.AreEqual(0, VolatileWrapper.Read(ref secondHandler));
Ping(muxer, pub, sub);
var count = sub.Publish(key, "def", CommandFlags.FireAndForget);
Ping(muxer, pub, sub);
......@@ -181,7 +181,7 @@ public void TestBasicPubSubFireAndForget(bool preserveOrder)
{
Assert.AreEqual(1, received.Count);
}
Assert.AreEqual(1, Thread.VolatileRead(ref secondHandler));
Assert.AreEqual(1, VolatileWrapper.Read(ref secondHandler));
sub.Unsubscribe(key);
count = sub.Publish(key, "ghi", CommandFlags.FireAndForget);
......@@ -247,7 +247,7 @@ public void TestPatternPubSub(bool preserveOrder)
{
Assert.AreEqual(0, received.Count);
}
Assert.AreEqual(0, Thread.VolatileRead(ref secondHandler));
Assert.AreEqual(0, VolatileWrapper.Read(ref secondHandler));
var count = sub.Publish("abc", "def");
Ping(muxer, pub, sub);
......@@ -256,7 +256,7 @@ public void TestPatternPubSub(bool preserveOrder)
{
Assert.AreEqual(1, received.Count);
}
Assert.AreEqual(1, Thread.VolatileRead(ref secondHandler));
Assert.AreEqual(1, VolatileWrapper.Read(ref secondHandler));
sub.Unsubscribe("a*c");
count = sub.Publish("abc", "ghi");
......@@ -392,7 +392,7 @@ public void SubscriptionsSurviveConnectionFailure()
});
sub.Publish(channel, "abc");
sub.Ping();
Assert.AreEqual(1, Thread.VolatileRead(ref counter), "counter");
Assert.AreEqual(1, VolatileWrapper.Read(ref counter), "counter");
var server = GetServer(muxer);
Assert.AreEqual(1, server.GetCounters().Subscription.SocketCount, "sockets");
......@@ -408,8 +408,20 @@ public void SubscriptionsSurviveConnectionFailure()
#endif
sub.Publish(channel, "abc");
sub.Ping();
Assert.AreEqual(2, Thread.VolatileRead(ref counter), "counter");
Assert.AreEqual(2, VolatileWrapper.Read(ref counter), "counter");
}
}
}
internal static class VolatileWrapper
{
public static int Read(ref int location)
{
#if !NETCORE
return Thread.VolatileRead(ref location);
#else
return Volatile.Read(ref location);
#endif
}
}
}
......@@ -285,11 +285,13 @@ protected static TimeSpan RunConcurrent(Action work, int threads, int timeout =
}
if (!allDone.WaitOne(timeout))
{
for(int i = 0; i < threads; i++)
#if !NETCORE
for (int i = 0; i < threads; i++)
{
var thd = threadArr[i];
if (thd.IsAlive) thd.Abort();
}
#endif
throw new TimeoutException();
}
......
......@@ -24,6 +24,7 @@
"dependencies": {
"System.Console": "4.0.0-beta-*",
"System.Linq.Expressions": "4.0.11-beta-*",
"System.Threading.Tasks.Parallel": "4.0.1-beta-*",
"moq": "4.3.0.0",
"nunit": "3.0.0-beta-5"
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment