Skip to content

Commit

Permalink
add AsyncManualResetEvent to Functional Tests
Browse files Browse the repository at this point in the history
Conflicts:
	tests/Microsoft.AspNet.SignalR.FunctionalTests/Client/KeepAliveFacts.cs
	tests/Microsoft.AspNet.SignalR.FunctionalTests/Server/Connections/ConnectionFacts.cs
	tests/Microsoft.AspNet.SignalR.Tests.Common/Microsoft.AspNet.SignalR.Tests.Common.csproj
  • Loading branch information
Gustavo Armenta authored and gustavo-armenta committed Oct 11, 2013
1 parent 27b43ee commit 2cad84a
Show file tree
Hide file tree
Showing 11 changed files with 237 additions and 184 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public async Task RequestHeadersCanBeSetOnceConnected(HostType hostType, Transpo
// Arrange
host.Initialize();
var connection = CreateConnection(host, "/examine-request");
var mre = new ManualResetEventSlim();
var mre = new AsyncManualResetEvent();

using (connection)
{
Expand All @@ -303,7 +303,7 @@ public async Task RequestHeadersCanBeSetOnceConnected(HostType hostType, Transpo
var ignore = connection.Send("message");

// Assert
Assert.True(mre.Wait(TimeSpan.FromSeconds(10)));
Assert.True(await mre.WaitAsync(TimeSpan.FromSeconds(10)));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class HubProxyFacts : HostedTest
[InlineData(HostType.HttpListener, TransportType.LongPolling, MessageBusType.Default)]
public async Task TransportTimesOutIfNoInitMessage(HostType hostType, TransportType transportType, MessageBusType messageBusType)
{
var mre = new ManualResetEventSlim();
var mre = new AsyncManualResetEvent();

using (var host = CreateHost(hostType, transportType))
{
Expand All @@ -46,7 +46,7 @@ public async Task TransportTimesOutIfNoInitMessage(HostType hostType, TransportT
mre.Set();
}

Assert.True(mre.Wait(TimeSpan.FromSeconds(10)));
Assert.True(await mre.WaitAsync(TimeSpan.FromSeconds(10)));
}
}
}
Expand Down Expand Up @@ -366,7 +366,7 @@ public async Task ConnectionErrorCapturesExceptionsThrownInClientHubMethod(HostT
{
using (var host = CreateHost(hostType, transportType))
{
var wh = new ManualResetEventSlim();
var wh = new AsyncManualResetEvent();
Exception thrown = new Exception(),
caught = null;

Expand All @@ -392,7 +392,7 @@ public async Task ConnectionErrorCapturesExceptionsThrownInClientHubMethod(HostT
await connection.Start(host.Transport);
var ignore = proxy.Invoke("Send", "").Catch();

Assert.True(wh.Wait(TimeSpan.FromSeconds(5)));
Assert.True(await wh.WaitAsync(TimeSpan.FromSeconds(5)));
Assert.Equal(thrown, caught);
}
}
Expand Down Expand Up @@ -468,7 +468,7 @@ public async Task RequestHeadersCanBeSetOnceConnected(HostType hostType, Transpo
// Arrange
host.Initialize(messageBusType: messageBusType);
HubConnection hubConnection = CreateHubConnection(host);
var mre = new ManualResetEventSlim();
var mre = new AsyncManualResetEvent();

using (hubConnection)
{
Expand All @@ -484,7 +484,7 @@ public async Task RequestHeadersCanBeSetOnceConnected(HostType hostType, Transpo

hubConnection.Headers.Add("test-header", "test-header");
var ignore = proxy.Invoke("Send").Catch();
Assert.True(mre.Wait(TimeSpan.FromSeconds(5)));
Assert.True(await mre.WaitAsync(TimeSpan.FromSeconds(5)));
}
}
}
Expand Down Expand Up @@ -542,8 +542,8 @@ public async Task ClientCallbackWithFewerArgumentsDoesNotThrow(HostType hostType
{
host.Initialize();
HubConnection hubConnection = CreateHubConnection(host);
var mre = new ManualResetEventSlim();
var wh = new ManualResetEventSlim();
var mre = new AsyncManualResetEvent();
var wh = new AsyncManualResetEvent();

hubConnection.Error += (ex) =>
{
Expand All @@ -559,8 +559,8 @@ public async Task ClientCallbackWithFewerArgumentsDoesNotThrow(HostType hostType
await hubConnection.Start(host.Transport);
await proxy.Invoke("SendOneArgument");

Assert.True(mre.Wait(TimeSpan.FromSeconds(5)));
Assert.False(wh.Wait(TimeSpan.FromSeconds(5)));
Assert.True(await mre.WaitAsync(TimeSpan.FromSeconds(5)));
Assert.False(await wh.WaitAsync(TimeSpan.FromSeconds(5)));
}
}
}
Expand All @@ -581,10 +581,12 @@ public async Task ClientCallbackArgumentTypeMismatchExceptionThrown(HostType hos
host.Initialize();
HubConnection hubConnection = CreateHubConnection(host);
var tcs = new TaskCompletionSource<Exception>();
var mre = new AsyncManualResetEvent();

hubConnection.Error += (ex) =>
{
tcs.TrySetResult(ex);
mre.Set();
};

using (hubConnection)
Expand All @@ -596,7 +598,7 @@ public async Task ClientCallbackArgumentTypeMismatchExceptionThrown(HostType hos
await hubConnection.Start(host.Transport);
await proxy.Invoke("SendArgumentsTypeMismatch");

Assert.True(tcs.Task.Wait(TimeSpan.FromSeconds(5)));
Assert.True(await mre.WaitAsync(TimeSpan.FromSeconds(5)));
Assert.IsType(typeof(InvalidOperationException), tcs.Task.Result);
Assert.Equal(((InvalidOperationException)tcs.Task.Result).Message, "A client callback for event foo with 1 argument(s) was found, however an error occurred because Could not convert string to integer: arg1. Path ''.");
}
Expand All @@ -616,7 +618,7 @@ public async Task WaitingOnHubInvocationDoesNotDeadlock(HostType hostType, Trans
{
host.Initialize();
HubConnection hubConnection = CreateHubConnection(host);
var mre = new ManualResetEventSlim();
var mre = new AsyncManualResetEvent();

using (hubConnection)
{
Expand All @@ -638,7 +640,7 @@ public async Task WaitingOnHubInvocationDoesNotDeadlock(HostType hostType, Trans

await hubConnection.Start(host.Transport);
var ignore = proxy.Invoke("EchoCallback", "message").Catch();
Assert.True(mre.Wait(TimeSpan.FromSeconds(10)));
Assert.True(await mre.WaitAsync(TimeSpan.FromSeconds(10)));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public async Task ReconnectionSuccesfulTest(HostType hostType, TransportType tra
using (var host = CreateHost(hostType, transportType))
{
// Arrange
var mre = new ManualResetEventSlim(false);
var mre = new AsyncManualResetEvent(false);
host.Initialize(keepAlive: null, messageBusType: messageBusType);
var connection = CreateConnection(host, "/my-reconnect");

Expand All @@ -38,8 +38,7 @@ public async Task ReconnectionSuccesfulTest(HostType hostType, TransportType tra

await connection.Start(host.Transport);

// Assert
Assert.True(mre.Wait(TimeSpan.FromSeconds(10)));
Assert.True(await mre.WaitAsync(TimeSpan.FromSeconds(10)));

// Clean-up
mre.Dispose();
Expand All @@ -61,7 +60,7 @@ public async Task SuccessiveTimeoutTest(HostType hostType, TransportType transpo
using (var host = CreateHost(hostType, transportType))
{
// Arrange
var mre = new ManualResetEventSlim(false);
var mre = new AsyncManualResetEvent(false);
host.Initialize(keepAlive: 5, messageBusType: messageBusType);
var connection = CreateConnection(host, "/my-reconnect");

Expand All @@ -77,11 +76,11 @@ public async Task SuccessiveTimeoutTest(HostType hostType, TransportType transpo
((Client.IConnection)connection).KeepAliveData = new KeepAliveData(TimeSpan.FromMilliseconds(500));

// Assert that Reconnected is called
Assert.True(mre.Wait(TimeSpan.FromSeconds(15)));
Assert.True(await mre.WaitAsync(TimeSpan.FromSeconds(15)));

// Assert that Reconnected is called again
mre.Reset();
Assert.True(mre.Wait(TimeSpan.FromSeconds(15)));
Assert.True(await mre.WaitAsync(TimeSpan.FromSeconds(15)));

// Clean-up
mre.Dispose();
Expand All @@ -102,7 +101,7 @@ public async Task OnConnectionSlowTest(HostType hostType, TransportType transpor
using (var host = CreateHost(hostType, transportType))
{
// Arrange
var mre = new ManualResetEventSlim(false);
var mre = new AsyncManualResetEvent(false);
host.Initialize(keepAlive: null, messageBusType: messageBusType);
var connection = CreateConnection(host, "/my-reconnect");

Expand All @@ -118,7 +117,7 @@ public async Task OnConnectionSlowTest(HostType hostType, TransportType transpor
await connection.Start(host.Transport);

// Assert
Assert.True(mre.Wait(TimeSpan.FromSeconds(15)));
Assert.True(await mre.WaitAsync(TimeSpan.FromSeconds(15)));

// Clean-up
mre.Dispose();
Expand All @@ -135,7 +134,7 @@ public async Task OnConnectionSlowDoesntFireForLongPolling(HostType hostType, Tr
using (var host = CreateHost(hostType, transportType))
{
// Arrange
var mre = new ManualResetEventSlim();
var mre = new AsyncManualResetEvent();
host.Initialize(keepAlive: 2);
var connection = CreateConnection(host, "/my-reconnect");

Expand All @@ -151,7 +150,7 @@ public async Task OnConnectionSlowDoesntFireForLongPolling(HostType hostType, Tr
await connection.Start(host.Transport);

// Assert
Assert.False(mre.Wait(TimeSpan.FromSeconds(10)));
Assert.False(await mre.WaitAsync(TimeSpan.FromSeconds(10)));

// Clean-up
mre.Dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,8 @@ public async Task ClientStopsReconnectingAfterDisconnectTimeout(HostType hostTyp

using (connection)
{
var reconnectWh = new ManualResetEventSlim();
var disconnectWh = new ManualResetEventSlim();
var reconnectWh = new AsyncManualResetEvent();
var disconnectWh = new AsyncManualResetEvent();

connection.Reconnecting += () =>
{
Expand All @@ -509,8 +509,8 @@ public async Task ClientStopsReconnectingAfterDisconnectTimeout(HostType hostTyp
await connection.Start(host.Transport);
host.Shutdown();

Assert.True(reconnectWh.Wait(TimeSpan.FromSeconds(15)), "Reconnect never fired");
Assert.True(disconnectWh.Wait(TimeSpan.FromSeconds(15)), "Closed never fired");
Assert.True(await reconnectWh.WaitAsync(TimeSpan.FromSeconds(25)), "Reconnect never fired");
Assert.True(await disconnectWh.WaitAsync(TimeSpan.FromSeconds(25)), "Closed never fired");
}
}
}
Expand Down Expand Up @@ -541,8 +541,8 @@ public async Task ClientStaysReconnectedAfterDisconnectTimeout(HostType hostType

using (connection)
{
var reconnectingWh = new ManualResetEventSlim();
var reconnectedWh = new ManualResetEventSlim();
var reconnectingWh = new AsyncManualResetEvent();
var reconnectedWh = new AsyncManualResetEvent();

connection.Reconnecting += () =>
{
Expand All @@ -558,8 +558,12 @@ public async Task ClientStaysReconnectedAfterDisconnectTimeout(HostType hostType

await connection.Start(host.Transport);

Assert.True(reconnectingWh.Wait(TimeSpan.FromSeconds(30)));
Assert.True(reconnectedWh.Wait(TimeSpan.FromSeconds(30)));
// Force reconnect
Thread.Sleep(TimeSpan.FromSeconds(5));

Assert.True(await reconnectingWh.WaitAsync(TimeSpan.FromSeconds(30)));
Assert.True(await reconnectedWh.WaitAsync(TimeSpan.FromSeconds(30)));

Thread.Sleep(TimeSpan.FromSeconds(15));
Assert.NotEqual(ConnectionState.Disconnected, connection.State);
}
Expand All @@ -580,7 +584,7 @@ public async Task ConnectionErrorCapturesExceptionsThrownInReceived(HostType hos
using (var host = CreateHost(hostType, transportType))
{
var errorsCaught = 0;
var wh = new ManualResetEventSlim();
var wh = new AsyncManualResetEvent();
Exception thrown = new Exception(),
caught = null;

Expand All @@ -606,7 +610,7 @@ public async Task ConnectionErrorCapturesExceptionsThrownInReceived(HostType hos

await connection.Start(host.Transport);

Assert.True(wh.Wait(TimeSpan.FromSeconds(5)));
Assert.True(await wh.WaitAsync(TimeSpan.FromSeconds(5)));
Assert.Equal(thrown, caught);
}
}
Expand Down Expand Up @@ -637,7 +641,7 @@ public async Task ConnectionErrorCapturesExceptionsThrownWhenReceivingResponseFr
{
Debug.WriteLine("Transport: {0}", (object)transport.Name);

var wh = new ManualResetEventSlim();
var wh = new AsyncManualResetEvent();
Exception thrown = new InvalidOperationException(),
caught = null;

Expand All @@ -659,7 +663,7 @@ public async Task ConnectionErrorCapturesExceptionsThrownWhenReceivingResponseFr
await connection.Start(transport);
var ignore = connection.Send("");

Assert.True(wh.Wait(TimeSpan.FromSeconds(5)));
Assert.True(await wh.WaitAsync(TimeSpan.FromSeconds(5)));
Assert.Equal(thrown, caught);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public async Task DisconnectFiresForPersistentConnectionWhenClientGoesAway()
{
using (var host = new MemoryHost())
{
var connectWh = new ManualResetEventSlim();
var disconnectWh = new ManualResetEventSlim();
var connectWh = new AsyncManualResetEvent();
var disconnectWh = new AsyncManualResetEvent();
var dr = new DefaultDependencyResolver();
var configuration = dr.Resolve<IConfigurationManager>();

Expand All @@ -101,11 +101,11 @@ public async Task DisconnectFiresForPersistentConnectionWhenClientGoesAway()

await connection.Start(host);

Assert.True(connectWh.Wait(TimeSpan.FromSeconds(10)), "Connect never fired");
Assert.True(await connectWh.WaitAsync(TimeSpan.FromSeconds(10)), "Connect never fired");

connection.Stop();

Assert.True(disconnectWh.Wait(disconnectWait), "Disconnect never fired");
Assert.True(await disconnectWh.WaitAsync(disconnectWait), "Disconnect never fired");
}
}

Expand All @@ -117,8 +117,8 @@ public async Task DisconnectFiresForHubsWhenConnectionGoesAway()
var dr = new DefaultDependencyResolver();
var configuration = dr.Resolve<IConfigurationManager>();

var connectWh = new ManualResetEventSlim();
var disconnectWh = new ManualResetEventSlim();
var connectWh = new AsyncManualResetEvent();
var disconnectWh = new AsyncManualResetEvent();
host.Configure(app =>
{
var config = new HubConfiguration
Expand All @@ -141,11 +141,11 @@ public async Task DisconnectFiresForHubsWhenConnectionGoesAway()

await connection.Start(host);

Assert.True(connectWh.Wait(TimeSpan.FromSeconds(10)), "Connect never fired");
Assert.True(await connectWh.WaitAsync(TimeSpan.FromSeconds(10)), "Connect never fired");

connection.Stop();

Assert.True(disconnectWh.Wait(disconnectWait), "Disconnect never fired");
Assert.True(await disconnectWh.WaitAsync(disconnectWait), "Disconnect never fired");
}
}

Expand Down Expand Up @@ -287,10 +287,10 @@ protected override Task OnReceived(IRequest request, string connectionId, string

public class MyHub : Hub
{
private ManualResetEventSlim _connectWh;
private ManualResetEventSlim _disconnectWh;
private AsyncManualResetEvent _connectWh;
private AsyncManualResetEvent _disconnectWh;

public MyHub(ManualResetEventSlim connectWh, ManualResetEventSlim disconnectWh)
public MyHub(AsyncManualResetEvent connectWh, AsyncManualResetEvent disconnectWh)
{
_connectWh = connectWh;
_disconnectWh = disconnectWh;
Expand Down Expand Up @@ -318,10 +318,10 @@ public override Task OnReconnected()

private class MyConnection : PersistentConnection
{
private ManualResetEventSlim _connectWh;
private ManualResetEventSlim _disconnectWh;
private AsyncManualResetEvent _connectWh;
private AsyncManualResetEvent _disconnectWh;

public MyConnection(ManualResetEventSlim connectWh, ManualResetEventSlim disconnectWh)
public MyConnection(AsyncManualResetEvent connectWh, AsyncManualResetEvent disconnectWh)
{
_connectWh = connectWh;
_disconnectWh = disconnectWh;
Expand Down
Loading

0 comments on commit 2cad84a

Please sign in to comment.