Skip to content

Commit 093ade9

Browse files
committed
Fix SignalR tests
1 parent 3e841cf commit 093ade9

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

src/SignalR/clients/csharp/Client/test/FunctionalTests/HubConnectionTests.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ public async Task CanStreamClientMethodFromServer(string protocolName, HttpTrans
337337
await connection.StartAsync().OrTimeout();
338338

339339
var channel = await connection.StreamAsChannelAsync<int>("Stream", 5).OrTimeout();
340-
var results = await channel.ReadAllAsync().OrTimeout();
340+
var results = await channel.ReadAndCollectAllAsync().OrTimeout();
341341

342342
Assert.Equal(new[] { 0, 1, 2, 3, 4 }, results.ToArray());
343343
}
@@ -375,7 +375,7 @@ public async Task CanStreamToAndFromClientInSameInvocation(string protocolName,
375375
Assert.Equal("2", await channel.ReadAsync().AsTask().OrTimeout());
376376
channelWriter.Writer.Complete();
377377

378-
var results = await channel.ReadAllAsync().OrTimeout();
378+
var results = await channel.ReadAndCollectAllAsync().OrTimeout();
379379
Assert.Empty(results);
380380
}
381381
catch (Exception ex)
@@ -420,7 +420,7 @@ bool ExpectedErrors(WriteContext writeContext)
420420

421421
cts.Cancel();
422422

423-
var results = await channel.ReadAllAsync(suppressExceptions: true).OrTimeout();
423+
var results = await channel.ReadAndCollectAllAsync(suppressExceptions: true).OrTimeout();
424424

425425
Assert.True(results.Count > 0 && results.Count < 1000);
426426

@@ -488,7 +488,7 @@ bool ExpectedErrors(WriteContext writeContext)
488488
await connection.StartAsync().OrTimeout();
489489
var channel = await connection.StreamAsChannelAsync<int>("StreamException").OrTimeout();
490490

491-
var ex = await Assert.ThrowsAsync<HubException>(() => channel.ReadAllAsync().OrTimeout());
491+
var ex = await Assert.ThrowsAsync<HubException>(() => channel.ReadAndCollectAllAsync().OrTimeout());
492492
Assert.Equal("An unexpected error occurred invoking 'StreamException' on the server. InvalidOperationException: Error occurred while streaming.", ex.Message);
493493
}
494494
catch (Exception ex)
@@ -654,7 +654,7 @@ bool ExpectedErrors(WriteContext writeContext)
654654
await connection.StartAsync().OrTimeout();
655655

656656
var channel = await connection.StreamAsChannelAsync<int>("!@#$%");
657-
var ex = await Assert.ThrowsAsync<HubException>(() => channel.ReadAllAsync().OrTimeout());
657+
var ex = await Assert.ThrowsAsync<HubException>(() => channel.ReadAndCollectAllAsync().OrTimeout());
658658
Assert.Equal("Failed to invoke '!@#$%' due to an error on the server. HubException: Method does not exist.", ex.Message);
659659
}
660660
catch (Exception ex)
@@ -688,7 +688,7 @@ bool ExpectedErrors(WriteContext writeContext)
688688
await connection.StartAsync().OrTimeout();
689689

690690
var channel = await connection.StreamAsChannelAsync<int>("Stream", 42, 42);
691-
var ex = await Assert.ThrowsAsync<HubException>(() => channel.ReadAllAsync().OrTimeout());
691+
var ex = await Assert.ThrowsAsync<HubException>(() => channel.ReadAndCollectAllAsync().OrTimeout());
692692
Assert.Equal("Failed to invoke 'Stream' due to an error on the server. InvalidDataException: Invocation provides 2 argument(s) but target expects 1.", ex.Message);
693693
}
694694
catch (Exception ex)
@@ -722,7 +722,7 @@ bool ExpectedErrors(WriteContext writeContext)
722722
await connection.StartAsync().OrTimeout();
723723

724724
var channel = await connection.StreamAsChannelAsync<int>("Stream", "xyz");
725-
var ex = await Assert.ThrowsAsync<HubException>(() => channel.ReadAllAsync().OrTimeout());
725+
var ex = await Assert.ThrowsAsync<HubException>(() => channel.ReadAndCollectAllAsync().OrTimeout());
726726
Assert.Equal("Failed to invoke 'Stream' due to an error on the server. InvalidDataException: Error binding arguments. Make sure that the types of the provided values match the types of the hub method being invoked.", ex.Message);
727727
}
728728
catch (Exception ex)
@@ -755,7 +755,7 @@ bool ExpectedErrors(WriteContext writeContext)
755755
{
756756
await connection.StartAsync().OrTimeout();
757757
var channel = await connection.StreamAsChannelAsync<int>("HelloWorld").OrTimeout();
758-
var ex = await Assert.ThrowsAsync<HubException>(() => channel.ReadAllAsync()).OrTimeout();
758+
var ex = await Assert.ThrowsAsync<HubException>(() => channel.ReadAndCollectAllAsync()).OrTimeout();
759759
Assert.Equal("The client attempted to invoke the non-streaming 'HelloWorld' method with a streaming invocation.", ex.Message);
760760
}
761761
catch (Exception ex)
@@ -821,7 +821,7 @@ bool ExpectedErrors(WriteContext writeContext)
821821
{
822822
await connection.StartAsync().OrTimeout();
823823
var channel = await connection.StreamAsChannelAsync<int>("StreamBroken").OrTimeout();
824-
var ex = await Assert.ThrowsAsync<HubException>(() => channel.ReadAllAsync()).OrTimeout();
824+
var ex = await Assert.ThrowsAsync<HubException>(() => channel.ReadAndCollectAllAsync()).OrTimeout();
825825
Assert.Equal("The value returned by the streaming method 'StreamBroken' is not a ChannelReader<>.", ex.Message);
826826
}
827827
catch (Exception ex)

src/SignalR/clients/csharp/Client/test/UnitTests/HubConnectionTests.Protocol.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public async Task ClientSendsHandshakeMessageWhenStartingConnection()
6666
[Fact]
6767
public async Task ClientIsOkayReceivingMinorVersionInHandshake()
6868
{
69-
// We're just testing that the client doesn't fail when a minor version is added to the handshake
69+
// We're just testing that the client doesn't fail when a minor version is added to the handshake
7070
// The client doesn't actually use that version anywhere yet so there's nothing else to test at this time
7171

7272
var connection = new TestConnection(autoHandshake: false);
@@ -228,7 +228,7 @@ public async Task StreamCompletesWhenCompletionMessageIsReceived()
228228

229229
await connection.ReceiveJsonMessage(new { invocationId = "1", type = 3 }).OrTimeout();
230230

231-
Assert.Empty(await channel.ReadAllAsync());
231+
Assert.Empty(await channel.ReadAndCollectAllAsync().OrTimeout());
232232
}
233233
finally
234234
{
@@ -295,7 +295,7 @@ public async Task StreamFailsIfCompletionMessageHasPayload()
295295

296296
await connection.ReceiveJsonMessage(new { invocationId = "1", type = 3, result = "Oops" }).OrTimeout();
297297

298-
var ex = await Assert.ThrowsAsync<InvalidOperationException>(async () => await channel.ReadAllAsync().OrTimeout());
298+
var ex = await Assert.ThrowsAsync<InvalidOperationException>(async () => await channel.ReadAndCollectAllAsync().OrTimeout());
299299
Assert.Equal("Server provided a result in a completion response to a streamed invocation.", ex.Message);
300300
}
301301
finally
@@ -318,7 +318,7 @@ public async Task StreamFailsWithExceptionWhenCompletionWithErrorReceived()
318318

319319
await connection.ReceiveJsonMessage(new { invocationId = "1", type = 3, error = "An error occurred" }).OrTimeout();
320320

321-
var ex = await Assert.ThrowsAsync<HubException>(async () => await channel.ReadAllAsync().OrTimeout());
321+
var ex = await Assert.ThrowsAsync<HubException>(async () => await channel.ReadAndCollectAllAsync().OrTimeout());
322322
Assert.Equal("An error occurred", ex.Message);
323323
}
324324
finally
@@ -367,7 +367,7 @@ public async Task StreamYieldsItemsAsTheyArrive()
367367
await connection.ReceiveJsonMessage(new { invocationId = "1", type = 2, item = "3" }).OrTimeout();
368368
await connection.ReceiveJsonMessage(new { invocationId = "1", type = 3 }).OrTimeout();
369369

370-
var notifications = await channel.ReadAllAsync().OrTimeout();
370+
var notifications = await channel.ReadAndCollectAllAsync().OrTimeout();
371371

372372
Assert.Equal(new[] { "1", "2", "3", }, notifications.ToArray());
373373
}

src/SignalR/common/testassets/Tests.Utils/ChannelExtensions.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33

44
using System.Collections.Generic;
55
using System.Threading.Tasks;
6-
using Xunit;
76

87
namespace System.Threading.Channels
98
{
109
public static class ChannelExtensions
1110
{
12-
public static async Task<List<T>> ReadAllAsync<T>(this ChannelReader<T> channel, bool suppressExceptions = false)
11+
public static async Task<List<T>> ReadAndCollectAllAsync<T>(this ChannelReader<T> channel, bool suppressExceptions = false)
1312
{
1413
var list = new List<T>();
1514
try

0 commit comments

Comments
 (0)