Skip to content

Commit c840a90

Browse files
ANcpLuaclaude
andcommitted
Improve SSE header handling and rename fallback test
Production changes: - Replace Body.FlushAsync() with StartAsync() in SSE fallback implementation - StartAsync() is more semantically correct for sending headers immediately - Ensures headers reach client before awaiting first event Test improvements: - Rename test to MapSse_Fallback_ShouldWriteCorrectSseFormat (clearer intent) - Remove Skip attribute - test is now reliable with continuous publishing - Increase timeout to 30s for slower CI environments - Set client timeout to infinite (test has its own 30s cancellation) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent ae3e091 commit c840a90

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ namespace SWEN3.Paperless.RabbitMq.Tests.Unit;
33
public class SseExtensionsFallbackTests
44
{
55
#if !NET10_0_OR_GREATER
6-
[Fact(Skip = "Flaky on CI runners; SSE fallback covered by integration flows")]
7-
public async Task MapSse_OnNet8_ShouldWriteCorrectSseFormat()
6+
[Fact]
7+
public async Task MapSse_Fallback_ShouldWriteCorrectSseFormat()
88
{
99
// Arrange
1010
var hostBuilder = new WebHostBuilder()
@@ -26,12 +26,12 @@ public async Task MapSse_OnNet8_ShouldWriteCorrectSseFormat()
2626

2727
using var server = new TestServer(hostBuilder);
2828
var client = server.CreateClient();
29-
client.Timeout = TimeSpan.FromSeconds(10);
29+
client.Timeout = Timeout.InfiniteTimeSpan;
3030
var sseStream = server.Host.Services.GetRequiredService<ISseStream<Messages.SseTestEvent>>();
3131

3232
// Act
3333
using var cts = CancellationTokenSource.CreateLinkedTokenSource(TestContext.Current.CancellationToken);
34-
cts.CancelAfter(TimeSpan.FromSeconds(10));
34+
cts.CancelAfter(TimeSpan.FromSeconds(30));
3535

3636
var responseTask = client.GetAsync("/sse", HttpCompletionOption.ResponseHeadersRead, cts.Token);
3737

SWEN3.Paperless.RabbitMq/Sse/SseExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ async IAsyncEnumerable<SseItem<object>> StreamEventsAsync([EnumeratorCancellatio
115115
context.Response.Headers.Connection = "keep-alive";
116116
context.Response.Headers.ContentType = "text/event-stream";
117117

118-
// Flush headers immediately so clients receive them before data arrives
119-
await context.Response.Body.FlushAsync(ct).ConfigureAwait(false);
118+
// Start the response so headers are sent immediately, even before the first event
119+
await context.Response.StartAsync(ct).ConfigureAwait(false);
120120

121121
await foreach (var item in reader.ReadAllAsync(ct).ConfigureAwait(false))
122122
{

0 commit comments

Comments
 (0)