Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test failure warnings #2142

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions test/Microsoft.Azure.SignalR.Tests/AckHandlerTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft. All rights reserved.
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
Expand All @@ -11,25 +11,25 @@ namespace Microsoft.Azure.SignalR.Tests;
public class AckHandlerTest
{
[Fact]
public void TestOnce()
public async Task TestOnce()
{
var handler = new AckHandler();
var task = handler.CreateSingleAck(out var ackId);
handler.TriggerAck(ackId);
Assert.True(task.IsCompletedSuccessfully);
Assert.Equal(AckStatus.Ok, task.Result);
Assert.Equal(AckStatus.Ok, await task);
}

[Fact]
public async Task TestOnce_Timeout()
{
var handler = new AckHandler(TimeSpan.FromSeconds(1), TimeSpan.FromMilliseconds(20));
var task = handler.CreateSingleAck(out var ackId);
var task = handler.CreateSingleAck(out var _);
Assert.False(task.IsCompleted);
await Task.Delay(TimeSpan.FromSeconds(1.5));
Assert.True(task.IsCompleted);
// This assertion is different from RT for different behaviour when timeout of AckHandler. See annotation in AckHandler.cs method CheckAcs
Assert.Equal(AckStatus.Timeout, task.Result);
Assert.Equal(AckStatus.Timeout, await task);
}

[Fact]
Expand Down Expand Up @@ -68,7 +68,7 @@ public async Task TestTwice_Timeout()
await Task.Delay(TimeSpan.FromSeconds(1.5));
Assert.True(task.IsCompleted);
// This assertion is different from RT for different behaviour when timeout of AckHandler. See annotation in AckHandler.cs method CheckAcs
Assert.Equal(AckStatus.Timeout, task.Result);
Assert.Equal(AckStatus.Timeout, await task);
}

[Fact]
Expand Down
7 changes: 2 additions & 5 deletions test/Microsoft.Azure.SignalR.Tests/AddAzureSignalRFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ public void AddAzureReadsConnectionStringFirst()
}
}


[Theory]
[InlineData(null, ServerStickyMode.Disabled)]
[InlineData("invalid", ServerStickyMode.Disabled)]
Expand Down Expand Up @@ -403,8 +402,7 @@ public void AddAzureSignalRWithOnlySecondaryValueThrows(string customValue, stri
}

// Endpoints from Endpoints and ConnectionString config are merged inside the EndpointManager
Assert.Throws<AzureSignalRNoPrimaryEndpointException>(() =>
serviceProvider.GetRequiredService<IServiceEndpointManager>());
Assert.Throws<AzureSignalRNoPrimaryEndpointException>(serviceProvider.GetRequiredService<IServiceEndpointManager>);
}
}

Expand Down Expand Up @@ -529,7 +527,6 @@ public void AddAzureSignalRWithInValidAppName(string appName)
}
}


[Fact(Skip = "Manual run for CI stable")]
public async Task AddAzureSignalRHotReloadConfigValue()
{
Expand Down Expand Up @@ -633,4 +630,4 @@ private static async Task<IEnumerable<Claim>> GetClaims(Action<ServiceCollection
var t = jwtSecurityTokenHandler.ReadJwtToken(r.AccessToken);
return t.Claims;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public class AddAzureSignalRWithConnectionNameFacts : VerifiableLoggedTest
private const string CustomValue = "Endpoint=https://customconnectionstring;AccessKey=1";
private const string DefaultValue = "Endpoint=https://defaultconnectionstring;AccessKey=1";
private const string SecondaryValue = "Endpoint=https://secondaryconnectionstring;AccessKey=1";
private const string ConfigFile = "testappsettings.json";

public AddAzureSignalRWithConnectionNameFacts(ITestOutputHelper output) : base(output)
{
Expand Down Expand Up @@ -453,8 +452,7 @@ public void AddAzureSignalRWithConnectionNameWithOnlySecondaryValueThrows(string
}

// Endpoints from Endpoints and ConnectionString config are merged inside the EndpointManager
Assert.Throws<AzureSignalRNoPrimaryEndpointException>(() =>
serviceProvider.GetRequiredService<IServiceEndpointManager>());
Assert.Throws<AzureSignalRNoPrimaryEndpointException>(serviceProvider.GetRequiredService<IServiceEndpointManager>);
}
}

Expand Down Expand Up @@ -528,4 +526,4 @@ public void AddAzureSignalRWithConnectionNameCustomizeEndpointsOverridesConfigVa
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft. All rights reserved.
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
Expand Down Expand Up @@ -47,7 +47,7 @@ public void DoNotSetUserIdFeatureWithoutUserIdClaimTest()
}

[Fact]
public async void TestForwardCloseMessage()
public async Task TestForwardCloseMessage()
{
using var serviceConnection = new TestServiceConnection();

Expand Down Expand Up @@ -88,7 +88,7 @@ public async void TestForwardCloseMessage()
}

[Fact]
public async void TestForwardInvocationMessage()
public async Task TestForwardInvocationMessage()
{
using var serviceConnection = new TestServiceConnection();

Expand Down Expand Up @@ -129,7 +129,7 @@ public async void TestForwardInvocationMessage()
}

[Fact]
public async void TestForwardHandshakeResponse()
public async Task TestForwardHandshakeResponse()
{
using var serviceConnection = new TestServiceConnection();

Expand Down Expand Up @@ -167,7 +167,7 @@ public async void TestForwardHandshakeResponse()
}

[Fact]
public async void TestSkipHandshakeResponse()
public async Task TestSkipHandshakeResponse()
{
using var serviceConnection = new TestServiceConnection();

Expand Down Expand Up @@ -204,7 +204,7 @@ public async void TestSkipHandshakeResponse()
}

[Fact]
public async void TestPauseResume()
public async Task TestPauseResume()
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Information, logChecker: records =>
{
Expand Down Expand Up @@ -262,7 +262,7 @@ public async void TestPauseResume()
}

[Fact]
public async void TestPauseAck()
public async Task TestPauseAck()
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Information, logChecker: records =>
{
Expand Down
30 changes: 17 additions & 13 deletions test/Microsoft.Azure.SignalR.Tests/ClientConnectionManagerTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System;
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Security.Claims;
using System.Threading.Tasks;
using Xunit;
Expand All @@ -7,19 +10,13 @@ namespace Microsoft.Azure.SignalR.Tests;

public class ClientConnectionManagerTests
{
private async Task RemoveConnection(IClientConnectionManager manager, ClientConnectionContext ctx)
{
await Task.Delay(100);
ctx.OnCompleted();
}

[Fact(Skip = "Disable high possibility failed cases until they are fixed")]
public void TestAllClientConnectionsCompleted()
[Fact]
public async Task TestAllClientConnectionsCompleted()
{
var manager = new ClientConnectionManager();

var c1 = new ClientConnectionContext(new Protocol.OpenConnectionMessage("foo", new Claim[0]));
var c2 = new ClientConnectionContext(new Protocol.OpenConnectionMessage("bar", new Claim[0]));
var c1 = new ClientConnectionContext(new Protocol.OpenConnectionMessage("foo", Array.Empty<Claim>()));
var c2 = new ClientConnectionContext(new Protocol.OpenConnectionMessage("bar", Array.Empty<Claim>()));

manager.TryAddClientConnection(c1);
manager.TryAddClientConnection(c2);
Expand All @@ -28,10 +25,17 @@ public void TestAllClientConnectionsCompleted()
_ = RemoveConnection(manager, c2);

var expected = manager.WhenAllCompleted();
var actual = Task.WaitAny(
var actual = await Task.WhenAny(
expected,
Task.Delay(TimeSpan.FromSeconds(1))
);
Assert.Equal(0, actual);
Assert.Equal(expected, actual);
}

private static async Task RemoveConnection(IClientConnectionManager _, ClientConnectionContext ctx)
{
await Task.Delay(100);
ctx.OnCompleted();
}

}
36 changes: 19 additions & 17 deletions test/Microsoft.Azure.SignalR.Tests/ClientInvocationManagerTests.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// Copyright (c) Microsoft. All rights reserved.
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#if NET7_0_OR_GREATER
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

using Microsoft.AspNetCore.SignalR;
using Microsoft.AspNetCore.SignalR.Internal;
using Microsoft.AspNetCore.SignalR.Protocol;
Expand All @@ -30,8 +33,8 @@ public class ClientInvocationManagerTests
private static readonly List<string> TestConnectionIds = new() { "conn0", "conn1" };
private static readonly List<string> TestInstanceIds = new() { "instance0", "instance1" };
private static readonly List<string> TestServerIds = new() { "server1", "server2" };
private static readonly string SuccessCompleteResult = "success-result";
private static readonly string ErrorCompleteResult = "error-result";
private const string SuccessCompleteResult = "success-result";
private const string ErrorCompleteResult = "error-result";

private static ClientInvocationManager GetTestClientInvocationManager(int endpointCount = 1)
{
Expand Down Expand Up @@ -65,7 +68,7 @@ private static ClientInvocationManager GetTestClientInvocationManager(int endpoi
*
* Note: Client 1 and Client 2 are both managed by Server A
*/
public async void TestCompleteWithoutRouterServer(bool isCompletionWithResult)
public async Task TestCompleteWithoutRouterServer(bool isCompletionWithResult)
{
var clientInvocationManager = GetTestClientInvocationManager();
var connectionId = TestConnectionIds[0];
Expand All @@ -89,9 +92,9 @@ public async void TestCompleteWithoutRouterServer(bool isCompletionWithResult)

try
{
await task;
var result = await task;
Assert.True(isCompletionWithResult);
Assert.Equal(SuccessCompleteResult, task.Result);
Assert.Equal(SuccessCompleteResult, result);
}
catch (Exception e)
{
Expand All @@ -111,7 +114,7 @@ public async void TestCompleteWithoutRouterServer(bool isCompletionWithResult)
*
* Note: Server 2 manages Client 2.
*/
public async void TestCompleteWithRouterServer(string protocol, bool isCompletionWithResult)
public async Task TestCompleteWithRouterServer(string protocol, bool isCompletionWithResult)
{
var serverIds = new string[] { TestServerIds[0], TestServerIds[1] };
var ciManagers = new ClientInvocationManager[] {
Expand Down Expand Up @@ -141,9 +144,9 @@ public async void TestCompleteWithRouterServer(string protocol, bool isCompletio

try
{
await task;
var result = await task;
Assert.True(isCompletionWithResult);
Assert.Equal(SuccessCompleteResult, task.Result);
Assert.Equal(SuccessCompleteResult, result);
}
catch (Exception e)
{
Expand Down Expand Up @@ -171,14 +174,13 @@ public void TestCallerManagerCancellation()
Assert.False(clientInvocationManager.Caller.TryGetInvocationReturnType(invocationId, out _));
}


[Theory]
[InlineData(true, 2)]
[InlineData(false, 2)]
[InlineData(true, 3)]
[InlineData(false, 3)]
// isCompletionWithResult: the invocation is completed with result or error
public async void TestCompleteWithMultiEndpointAtLast(bool isCompletionWithResult, int endpointsCount)
public async Task TestCompleteWithMultiEndpointAtLast(bool isCompletionWithResult, int endpointsCount)
{
Assert.True(endpointsCount > 1);
var clientInvocationManager = GetTestClientInvocationManager(endpointsCount);
Expand Down Expand Up @@ -212,9 +214,9 @@ public async void TestCompleteWithMultiEndpointAtLast(bool isCompletionWithResul

try
{
await task;
var result = await task;
Assert.True(isCompletionWithResult);
Assert.Equal(SuccessCompleteResult, task.Result);
Assert.Equal(SuccessCompleteResult, result);
}
catch (Exception e)
{
Expand All @@ -226,7 +228,7 @@ public async void TestCompleteWithMultiEndpointAtLast(bool isCompletionWithResul
[Theory]
[InlineData(2)]
[InlineData(3)]
public async void TestCompleteWithMultiEndpointAtMiddle(int endpointsCount)
public async Task TestCompleteWithMultiEndpointAtMiddle(int endpointsCount)
{
Assert.True(endpointsCount > 1);
var clientInvocationManager = GetTestClientInvocationManager(endpointsCount);
Expand Down Expand Up @@ -262,8 +264,8 @@ public async void TestCompleteWithMultiEndpointAtMiddle(int endpointsCount)

try
{
await task;
Assert.Equal(SuccessCompleteResult, task.Result);
var result = await task;
Assert.Equal(SuccessCompleteResult, result);
}
catch (Exception)
{
Expand All @@ -278,4 +280,4 @@ internal static ReadOnlyMemory<byte> GetBytes(string proto, HubMessage message)
}

}
#endif
#endif
13 changes: 7 additions & 6 deletions test/Microsoft.Azure.SignalR.Tests/EndpointRouterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private static ServiceEndpoint GenerateServiceEndpoint(int capacity, int serverC
EndpointType.Primary, name) { EndpointMetrics = endpointMetrics };
}

private class RandomContext
private sealed class RandomContext
{
private readonly Dictionary<string, int> _counter = new();

Expand All @@ -96,23 +96,24 @@ public void BenchTest(int loops, Func<string> func)
for (var i = 0; i < loops; i++)
{
var name = func();
if (!_counter.ContainsKey(name))
if (!_counter.TryGetValue(name, out var value))
{
_counter.Add(name, 0);
value = 0;
_counter.Add(name, value);
}

_counter[name]++;
_counter[name] = ++value;
}
}

public int GetCount(string name)
{
return _counter.ContainsKey(name) ? _counter[name] : 0;
return _counter.TryGetValue(name, out var value) ? value : 0;
}

public void Reset()
{
_counter.Clear();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft. All rights reserved.
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
Expand Down Expand Up @@ -29,7 +29,7 @@ public void HubMessageSerializerFact()
serializer.SerializeMessage("JsOn", message);
}

private class IgnoreCaseJsonHubProtocol : IHubProtocol
private sealed class IgnoreCaseJsonHubProtocol : IHubProtocol
{
public string Name => "json";

Expand Down
Loading
Loading