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