Skip to content

Commit 563b9c0

Browse files
authored
Fix test failure warnings (#2142)
* Fix test failure warnings * Fix build failure
1 parent ad95e32 commit 563b9c0

36 files changed

+204
-193
lines changed

AzureSignalR.sln

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
2020
build\dependencies.private.props = build\dependencies.private.props
2121
build\dependencies.props = build\dependencies.props
2222
Directory.Build.props = Directory.Build.props
23-
Directory.Build.targets = Directory.Build.targets
2423
NuGet.config = NuGet.config
2524
build\sources.props = build\sources.props
2625
version.props = version.props

test/Microsoft.Azure.SignalR.Tests/AckHandlerTest.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft. All rights reserved.
1+
// Copyright (c) Microsoft. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
using System;
@@ -11,25 +11,25 @@ namespace Microsoft.Azure.SignalR.Tests;
1111
public class AckHandlerTest
1212
{
1313
[Fact]
14-
public void TestOnce()
14+
public async Task TestOnce()
1515
{
1616
var handler = new AckHandler();
1717
var task = handler.CreateSingleAck(out var ackId);
1818
handler.TriggerAck(ackId);
1919
Assert.True(task.IsCompletedSuccessfully);
20-
Assert.Equal(AckStatus.Ok, task.Result);
20+
Assert.Equal(AckStatus.Ok, await task);
2121
}
2222

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

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

7474
[Fact]

test/Microsoft.Azure.SignalR.Tests/AddAzureSignalRFacts.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ public void AddAzureReadsConnectionStringFirst()
224224
}
225225
}
226226

227-
228227
[Theory]
229228
[InlineData(null, ServerStickyMode.Disabled)]
230229
[InlineData("invalid", ServerStickyMode.Disabled)]
@@ -403,8 +402,7 @@ public void AddAzureSignalRWithOnlySecondaryValueThrows(string customValue, stri
403402
}
404403

405404
// Endpoints from Endpoints and ConnectionString config are merged inside the EndpointManager
406-
Assert.Throws<AzureSignalRNoPrimaryEndpointException>(() =>
407-
serviceProvider.GetRequiredService<IServiceEndpointManager>());
405+
Assert.Throws<AzureSignalRNoPrimaryEndpointException>(serviceProvider.GetRequiredService<IServiceEndpointManager>);
408406
}
409407
}
410408

@@ -529,7 +527,6 @@ public void AddAzureSignalRWithInValidAppName(string appName)
529527
}
530528
}
531529

532-
533530
[Fact(Skip = "Manual run for CI stable")]
534531
public async Task AddAzureSignalRHotReloadConfigValue()
535532
{
@@ -633,4 +630,4 @@ private static async Task<IEnumerable<Claim>> GetClaims(Action<ServiceCollection
633630
var t = jwtSecurityTokenHandler.ReadJwtToken(r.AccessToken);
634631
return t.Claims;
635632
}
636-
}
633+
}

test/Microsoft.Azure.SignalR.Tests/AddAzureSignalRWithConnectionNameFacts.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public class AddAzureSignalRWithConnectionNameFacts : VerifiableLoggedTest
2020
private const string CustomValue = "Endpoint=https://customconnectionstring;AccessKey=1";
2121
private const string DefaultValue = "Endpoint=https://defaultconnectionstring;AccessKey=1";
2222
private const string SecondaryValue = "Endpoint=https://secondaryconnectionstring;AccessKey=1";
23-
private const string ConfigFile = "testappsettings.json";
2423

2524
public AddAzureSignalRWithConnectionNameFacts(ITestOutputHelper output) : base(output)
2625
{
@@ -453,8 +452,7 @@ public void AddAzureSignalRWithConnectionNameWithOnlySecondaryValueThrows(string
453452
}
454453

455454
// Endpoints from Endpoints and ConnectionString config are merged inside the EndpointManager
456-
Assert.Throws<AzureSignalRNoPrimaryEndpointException>(() =>
457-
serviceProvider.GetRequiredService<IServiceEndpointManager>());
455+
Assert.Throws<AzureSignalRNoPrimaryEndpointException>(serviceProvider.GetRequiredService<IServiceEndpointManager>);
458456
}
459457
}
460458

@@ -528,4 +526,4 @@ public void AddAzureSignalRWithConnectionNameCustomizeEndpointsOverridesConfigVa
528526
}
529527
}
530528
}
531-
}
529+
}

test/Microsoft.Azure.SignalR.Tests/ClientConnectionContextFacts.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft. All rights reserved.
1+
// Copyright (c) Microsoft. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
using System;
@@ -47,7 +47,7 @@ public void DoNotSetUserIdFeatureWithoutUserIdClaimTest()
4747
}
4848

4949
[Fact]
50-
public async void TestForwardCloseMessage()
50+
public async Task TestForwardCloseMessage()
5151
{
5252
using var serviceConnection = new TestServiceConnection();
5353

@@ -88,7 +88,7 @@ public async void TestForwardCloseMessage()
8888
}
8989

9090
[Fact]
91-
public async void TestForwardInvocationMessage()
91+
public async Task TestForwardInvocationMessage()
9292
{
9393
using var serviceConnection = new TestServiceConnection();
9494

@@ -129,7 +129,7 @@ public async void TestForwardInvocationMessage()
129129
}
130130

131131
[Fact]
132-
public async void TestForwardHandshakeResponse()
132+
public async Task TestForwardHandshakeResponse()
133133
{
134134
using var serviceConnection = new TestServiceConnection();
135135

@@ -167,7 +167,7 @@ public async void TestForwardHandshakeResponse()
167167
}
168168

169169
[Fact]
170-
public async void TestSkipHandshakeResponse()
170+
public async Task TestSkipHandshakeResponse()
171171
{
172172
using var serviceConnection = new TestServiceConnection();
173173

@@ -204,7 +204,7 @@ public async void TestSkipHandshakeResponse()
204204
}
205205

206206
[Fact]
207-
public async void TestPauseResume()
207+
public async Task TestPauseResume()
208208
{
209209
using (StartVerifiableLog(out var loggerFactory, LogLevel.Information, logChecker: records =>
210210
{
@@ -262,7 +262,7 @@ public async void TestPauseResume()
262262
}
263263

264264
[Fact]
265-
public async void TestPauseAck()
265+
public async Task TestPauseAck()
266266
{
267267
using (StartVerifiableLog(out var loggerFactory, LogLevel.Information, logChecker: records =>
268268
{
Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using System;
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
25
using System.Security.Claims;
36
using System.Threading.Tasks;
47
using Xunit;
@@ -7,19 +10,13 @@ namespace Microsoft.Azure.SignalR.Tests;
710

811
public class ClientConnectionManagerTests
912
{
10-
private async Task RemoveConnection(IClientConnectionManager manager, ClientConnectionContext ctx)
11-
{
12-
await Task.Delay(100);
13-
ctx.OnCompleted();
14-
}
15-
16-
[Fact(Skip = "Disable high possibility failed cases until they are fixed")]
17-
public void TestAllClientConnectionsCompleted()
13+
[Fact]
14+
public async Task TestAllClientConnectionsCompleted()
1815
{
1916
var manager = new ClientConnectionManager();
2017

21-
var c1 = new ClientConnectionContext(new Protocol.OpenConnectionMessage("foo", new Claim[0]));
22-
var c2 = new ClientConnectionContext(new Protocol.OpenConnectionMessage("bar", new Claim[0]));
18+
var c1 = new ClientConnectionContext(new Protocol.OpenConnectionMessage("foo", Array.Empty<Claim>()));
19+
var c2 = new ClientConnectionContext(new Protocol.OpenConnectionMessage("bar", Array.Empty<Claim>()));
2320

2421
manager.TryAddClientConnection(c1);
2522
manager.TryAddClientConnection(c2);
@@ -28,10 +25,17 @@ public void TestAllClientConnectionsCompleted()
2825
_ = RemoveConnection(manager, c2);
2926

3027
var expected = manager.WhenAllCompleted();
31-
var actual = Task.WaitAny(
28+
var actual = await Task.WhenAny(
3229
expected,
3330
Task.Delay(TimeSpan.FromSeconds(1))
3431
);
35-
Assert.Equal(0, actual);
32+
Assert.Equal(expected, actual);
3633
}
34+
35+
private static async Task RemoveConnection(IClientConnectionManager _, ClientConnectionContext ctx)
36+
{
37+
await Task.Delay(100);
38+
ctx.OnCompleted();
39+
}
40+
3741
}

test/Microsoft.Azure.SignalR.Tests/ClientInvocationManagerTests.cs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
// Copyright (c) Microsoft. All rights reserved.
1+
// Copyright (c) Microsoft. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
34
#if NET7_0_OR_GREATER
45
using System;
56
using System.Collections.Generic;
67
using System.Linq;
78
using System.Threading;
9+
using System.Threading.Tasks;
10+
811
using Microsoft.AspNetCore.SignalR;
912
using Microsoft.AspNetCore.SignalR.Internal;
1013
using Microsoft.AspNetCore.SignalR.Protocol;
@@ -30,8 +33,8 @@ public class ClientInvocationManagerTests
3033
private static readonly List<string> TestConnectionIds = new() { "conn0", "conn1" };
3134
private static readonly List<string> TestInstanceIds = new() { "instance0", "instance1" };
3235
private static readonly List<string> TestServerIds = new() { "server1", "server2" };
33-
private static readonly string SuccessCompleteResult = "success-result";
34-
private static readonly string ErrorCompleteResult = "error-result";
36+
private const string SuccessCompleteResult = "success-result";
37+
private const string ErrorCompleteResult = "error-result";
3538

3639
private static ClientInvocationManager GetTestClientInvocationManager(int endpointCount = 1)
3740
{
@@ -65,7 +68,7 @@ private static ClientInvocationManager GetTestClientInvocationManager(int endpoi
6568
*
6669
* Note: Client 1 and Client 2 are both managed by Server A
6770
*/
68-
public async void TestCompleteWithoutRouterServer(bool isCompletionWithResult)
71+
public async Task TestCompleteWithoutRouterServer(bool isCompletionWithResult)
6972
{
7073
var clientInvocationManager = GetTestClientInvocationManager();
7174
var connectionId = TestConnectionIds[0];
@@ -89,9 +92,9 @@ public async void TestCompleteWithoutRouterServer(bool isCompletionWithResult)
8992

9093
try
9194
{
92-
await task;
95+
var result = await task;
9396
Assert.True(isCompletionWithResult);
94-
Assert.Equal(SuccessCompleteResult, task.Result);
97+
Assert.Equal(SuccessCompleteResult, result);
9598
}
9699
catch (Exception e)
97100
{
@@ -111,7 +114,7 @@ public async void TestCompleteWithoutRouterServer(bool isCompletionWithResult)
111114
*
112115
* Note: Server 2 manages Client 2.
113116
*/
114-
public async void TestCompleteWithRouterServer(string protocol, bool isCompletionWithResult)
117+
public async Task TestCompleteWithRouterServer(string protocol, bool isCompletionWithResult)
115118
{
116119
var serverIds = new string[] { TestServerIds[0], TestServerIds[1] };
117120
var ciManagers = new ClientInvocationManager[] {
@@ -141,9 +144,9 @@ public async void TestCompleteWithRouterServer(string protocol, bool isCompletio
141144

142145
try
143146
{
144-
await task;
147+
var result = await task;
145148
Assert.True(isCompletionWithResult);
146-
Assert.Equal(SuccessCompleteResult, task.Result);
149+
Assert.Equal(SuccessCompleteResult, result);
147150
}
148151
catch (Exception e)
149152
{
@@ -171,14 +174,13 @@ public void TestCallerManagerCancellation()
171174
Assert.False(clientInvocationManager.Caller.TryGetInvocationReturnType(invocationId, out _));
172175
}
173176

174-
175177
[Theory]
176178
[InlineData(true, 2)]
177179
[InlineData(false, 2)]
178180
[InlineData(true, 3)]
179181
[InlineData(false, 3)]
180182
// isCompletionWithResult: the invocation is completed with result or error
181-
public async void TestCompleteWithMultiEndpointAtLast(bool isCompletionWithResult, int endpointsCount)
183+
public async Task TestCompleteWithMultiEndpointAtLast(bool isCompletionWithResult, int endpointsCount)
182184
{
183185
Assert.True(endpointsCount > 1);
184186
var clientInvocationManager = GetTestClientInvocationManager(endpointsCount);
@@ -212,9 +214,9 @@ public async void TestCompleteWithMultiEndpointAtLast(bool isCompletionWithResul
212214

213215
try
214216
{
215-
await task;
217+
var result = await task;
216218
Assert.True(isCompletionWithResult);
217-
Assert.Equal(SuccessCompleteResult, task.Result);
219+
Assert.Equal(SuccessCompleteResult, result);
218220
}
219221
catch (Exception e)
220222
{
@@ -226,7 +228,7 @@ public async void TestCompleteWithMultiEndpointAtLast(bool isCompletionWithResul
226228
[Theory]
227229
[InlineData(2)]
228230
[InlineData(3)]
229-
public async void TestCompleteWithMultiEndpointAtMiddle(int endpointsCount)
231+
public async Task TestCompleteWithMultiEndpointAtMiddle(int endpointsCount)
230232
{
231233
Assert.True(endpointsCount > 1);
232234
var clientInvocationManager = GetTestClientInvocationManager(endpointsCount);
@@ -262,8 +264,8 @@ public async void TestCompleteWithMultiEndpointAtMiddle(int endpointsCount)
262264

263265
try
264266
{
265-
await task;
266-
Assert.Equal(SuccessCompleteResult, task.Result);
267+
var result = await task;
268+
Assert.Equal(SuccessCompleteResult, result);
267269
}
268270
catch (Exception)
269271
{
@@ -278,4 +280,4 @@ internal static ReadOnlyMemory<byte> GetBytes(string proto, HubMessage message)
278280
}
279281

280282
}
281-
#endif
283+
#endif

test/Microsoft.Azure.SignalR.Tests/EndpointRouterTests.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ private static ServiceEndpoint GenerateServiceEndpoint(int capacity, int serverC
8787
EndpointType.Primary, name) { EndpointMetrics = endpointMetrics };
8888
}
8989

90-
private class RandomContext
90+
private sealed class RandomContext
9191
{
9292
private readonly Dictionary<string, int> _counter = new();
9393

@@ -96,23 +96,24 @@ public void BenchTest(int loops, Func<string> func)
9696
for (var i = 0; i < loops; i++)
9797
{
9898
var name = func();
99-
if (!_counter.ContainsKey(name))
99+
if (!_counter.TryGetValue(name, out var value))
100100
{
101-
_counter.Add(name, 0);
101+
value = 0;
102+
_counter.Add(name, value);
102103
}
103104

104-
_counter[name]++;
105+
_counter[name] = ++value;
105106
}
106107
}
107108

108109
public int GetCount(string name)
109110
{
110-
return _counter.ContainsKey(name) ? _counter[name] : 0;
111+
return _counter.TryGetValue(name, out var value) ? value : 0;
111112
}
112113

113114
public void Reset()
114115
{
115116
_counter.Clear();
116117
}
117118
}
118-
}
119+
}

0 commit comments

Comments
 (0)