summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2008-09-24 22:24:10 -0700
committerAndrew <andrewarnott@gmail.com>2008-09-24 22:24:10 -0700
commit48409e1795dbdf3330dae3174bd0c14bb97341c7 (patch)
tree1aab93aa0cac347b3457ed68592678ed1e436788
parente7bdc2a55c64b19b143769ea322a88d8f461c58b (diff)
downloadDotNetOpenAuth-48409e1795dbdf3330dae3174bd0c14bb97341c7.zip
DotNetOpenAuth-48409e1795dbdf3330dae3174bd0c14bb97341c7.tar.gz
DotNetOpenAuth-48409e1795dbdf3330dae3174bd0c14bb97341c7.tar.bz2
Fixed Coordinator to better handle its helper threads throwing exceptions.
-rw-r--r--src/DotNetOAuth.Test/Scenarios/Coordinator.cs28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/DotNetOAuth.Test/Scenarios/Coordinator.cs b/src/DotNetOAuth.Test/Scenarios/Coordinator.cs
index 42cda0b..45518a2 100644
--- a/src/DotNetOAuth.Test/Scenarios/Coordinator.cs
+++ b/src/DotNetOAuth.Test/Scenarios/Coordinator.cs
@@ -12,6 +12,7 @@ namespace DotNetOAuth.Test.Scenarios {
using System.Threading;
using DotNetOAuth.Messaging;
using DotNetOAuth.ChannelElements;
+ using Microsoft.VisualStudio.TestTools.UnitTesting;
/// <summary>
/// Runs a Consumer and Service Provider simultaneously so they can interact in a full simulation.
@@ -59,12 +60,35 @@ namespace DotNetOAuth.Test.Scenarios {
consumerChannel.RemoteChannel = serviceProviderChannel;
serviceProviderChannel.RemoteChannel = consumerChannel;
- Thread consumerThread = new Thread(() => { consumerAction(consumerChannel); });
- Thread serviceProviderThread = new Thread(() => { serviceProviderAction(serviceProviderChannel); });
+ Thread consumerThread = null, serviceProviderThread = null;
+ Exception failingException = null;
+
+ Action<Actor, OAuthChannel> safeWrapper = (actor, channel) => {
+ try {
+ actor(channel);
+ } catch (Exception ex) {
+ // We may be the second thread in an ThreadAbortException, so check the "flag"
+ if (failingException == null) {
+ failingException = ex;
+ if (Thread.CurrentThread == consumerThread) {
+ serviceProviderThread.Abort();
+ } else {
+ consumerThread.Abort();
+ }
+ }
+ }
+ };
+
+ consumerThread = new Thread(() => { safeWrapper(consumerAction, consumerChannel); });
+ serviceProviderThread = new Thread(() => { safeWrapper(serviceProviderAction, serviceProviderChannel); });
consumerThread.Start();
serviceProviderThread.Start();
consumerThread.Join();
serviceProviderThread.Join();
+
+ if (failingException != null) {
+ throw new AssertFailedException("Coordinator thread threw unhandled exception: " + failingException, failingException);
+ }
}
}
}