-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for SocketException caused by --explore
- Loading branch information
Showing
6 changed files
with
167 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/NUnitEngine/nunit.engine/Internal/CurrentMessageCounter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System.Threading; | ||
|
||
namespace NUnit.Engine.Internal | ||
{ | ||
public sealed class CurrentMessageCounter | ||
{ | ||
private readonly ManualResetEvent _noMessages = new ManualResetEvent(true); | ||
private int _currentMessageCount; | ||
|
||
public void OnMessageStart() | ||
{ | ||
if (Interlocked.Increment(ref _currentMessageCount) == 1) | ||
_noMessages.Reset(); | ||
} | ||
|
||
public void OnMessageEnd() | ||
{ | ||
if (Interlocked.Decrement(ref _currentMessageCount) == 0) | ||
_noMessages.Set(); | ||
} | ||
|
||
public void WaitForAllCurrentMessages() | ||
{ | ||
_noMessages.WaitOne(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
src/NUnitEngine/nunit.engine/Internal/ServerUtilities.ObservableServerChannelSinkProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
using System; | ||
using System.Collections; | ||
using System.IO; | ||
using System.Runtime.Remoting.Channels; | ||
using System.Runtime.Remoting.Messaging; | ||
|
||
namespace NUnit.Engine.Internal | ||
{ | ||
partial class ServerUtilities | ||
{ | ||
private sealed class ObservableServerChannelSinkProvider : IServerChannelSinkProvider | ||
{ | ||
private readonly CurrentMessageCounter _currentMessageCounter; | ||
|
||
public ObservableServerChannelSinkProvider(CurrentMessageCounter currentMessageCounter) | ||
{ | ||
if (currentMessageCounter == null) throw new ArgumentNullException(nameof(currentMessageCounter)); | ||
_currentMessageCounter = currentMessageCounter; | ||
} | ||
|
||
public void GetChannelData(IChannelDataStore channelData) | ||
{ | ||
} | ||
|
||
public IServerChannelSink CreateSink(IChannelReceiver channel) | ||
{ | ||
if (Next == null) | ||
throw new InvalidOperationException("Cannot create a sink without setting the next provider."); | ||
return new ObservableServerChannelSink(_currentMessageCounter, Next.CreateSink(channel)); | ||
} | ||
|
||
public IServerChannelSinkProvider Next { get; set; } | ||
|
||
|
||
private sealed class ObservableServerChannelSink : IServerChannelSink | ||
{ | ||
private readonly IServerChannelSink _next; | ||
private readonly CurrentMessageCounter _currentMessageCounter; | ||
|
||
public ObservableServerChannelSink(CurrentMessageCounter currentMessageCounter, IServerChannelSink next) | ||
{ | ||
if (next == null) throw new ArgumentNullException(nameof(next)); | ||
_currentMessageCounter = currentMessageCounter; | ||
_next = next; | ||
} | ||
|
||
public IDictionary Properties => _next.Properties; | ||
|
||
public ServerProcessing ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, | ||
ITransportHeaders requestHeaders, Stream requestStream, out IMessage responseMsg, | ||
out ITransportHeaders responseHeaders, out Stream responseStream) | ||
{ | ||
_currentMessageCounter.OnMessageStart(); | ||
var isAsync = false; | ||
try | ||
{ | ||
var processing = _next.ProcessMessage(sinkStack, requestMsg, requestHeaders, requestStream, | ||
out responseMsg, out responseHeaders, out responseStream); | ||
isAsync = processing == ServerProcessing.Async; | ||
return processing; | ||
} | ||
finally | ||
{ | ||
if (!isAsync) _currentMessageCounter.OnMessageEnd(); | ||
} | ||
} | ||
|
||
public void AsyncProcessResponse(IServerResponseChannelSinkStack sinkStack, object state, IMessage msg, | ||
ITransportHeaders headers, Stream stream) | ||
{ | ||
try | ||
{ | ||
_next.AsyncProcessResponse(sinkStack, state, msg, headers, stream); | ||
} | ||
finally | ||
{ | ||
_currentMessageCounter.OnMessageEnd(); | ||
} | ||
} | ||
|
||
public Stream GetResponseStream(IServerResponseChannelSinkStack sinkStack, object state, IMessage msg, | ||
ITransportHeaders headers) | ||
{ | ||
return _next.GetResponseStream(sinkStack, state, msg, headers); | ||
} | ||
|
||
public IServerChannelSink NextChannelSink => _next.NextChannelSink; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters