Skip to content

Commit e45cd00

Browse files
committed
Skip flaky net8 SSE fallback test in CI
1 parent 236dbe9 commit e45cd00

File tree

1 file changed

+34
-16
lines changed

1 file changed

+34
-16
lines changed

SWEN3.Paperless.RabbitMq.Tests/Unit/SseExtensionsFallbackTests.cs

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,45 @@ public async Task MapSse_OnNet8_ShouldWriteCorrectSseFormat()
3333
using var cts = CancellationTokenSource.CreateLinkedTokenSource(TestContext.Current.CancellationToken);
3434
cts.CancelAfter(TimeSpan.FromSeconds(10));
3535

36-
using var response = await client.GetAsync("/sse", HttpCompletionOption.ResponseHeadersRead, cts.Token);
37-
response.EnsureSuccessStatusCode();
38-
await using var stream = await response.Content.ReadAsStreamAsync(cts.Token);
39-
using var reader = new StreamReader(stream, Encoding.UTF8);
36+
var responseTask = client.GetAsync("/sse", HttpCompletionOption.ResponseHeadersRead, cts.Token);
4037

41-
string? line1 = null;
42-
string? line2 = null;
43-
string? line3 = null;
38+
// Publish repeatedly until the subscriber is definitely connected
39+
var publisherTask = Task.Run(async () =>
40+
{
41+
try
42+
{
43+
while (!cts.Token.IsCancellationRequested)
44+
{
45+
await Task.Delay(50, cts.Token);
46+
sseStream.Publish(new Messages.SseTestEvent { Id = 1, Message = "Hello" });
47+
}
48+
}
49+
catch (OperationCanceledException)
50+
{
51+
// Expected when the test ends
52+
}
53+
}, CancellationToken.None);
4454

45-
for (var i = 0; i < 50 && line1 is null; i++)
55+
try
4656
{
47-
sseStream.Publish(new Messages.SseTestEvent { Id = 1, Message = "Hello" });
48-
line1 = await reader.ReadLineAsync(cts.Token);
49-
}
57+
using var response = await responseTask;
58+
response.EnsureSuccessStatusCode();
59+
await using var stream = await response.Content.ReadAsStreamAsync(cts.Token);
60+
using var reader = new StreamReader(stream, Encoding.UTF8);
5061

51-
line2 = await reader.ReadLineAsync(cts.Token);
52-
line3 = await reader.ReadLineAsync(cts.Token);
62+
var line1 = await reader.ReadLineAsync(cts.Token);
63+
var line2 = await reader.ReadLineAsync(cts.Token);
64+
var line3 = await reader.ReadLineAsync(cts.Token);
5365

54-
line1.Should().Be("event: test-event");
55-
line2.Should().Be("data: {\"id\":1,\"msg\":\"Hello\"}");
56-
line3.Should().BeEmpty(); // The double newline
66+
line1.Should().Be("event: test-event");
67+
line2.Should().Be("data: {\"id\":1,\"msg\":\"Hello\"}");
68+
line3.Should().BeEmpty(); // The double newline
69+
}
70+
finally
71+
{
72+
cts.Cancel();
73+
await publisherTask;
74+
}
5775
}
5876
#endif
5977
}

0 commit comments

Comments
 (0)