|
6 | 6 |
|
7 | 7 | import java.time.Duration; |
8 | 8 | import java.util.Map; |
| 9 | +import java.util.concurrent.CopyOnWriteArrayList; |
9 | 10 | import java.util.concurrent.atomic.AtomicInteger; |
10 | 11 | import java.util.function.Function; |
11 | 12 |
|
@@ -77,6 +78,11 @@ public int getInboundMessageCount() { |
77 | 78 | return inboundMessageCount.get(); |
78 | 79 | } |
79 | 80 |
|
| 81 | + public void simulateSseComment(String comment) { |
| 82 | + events.tryEmitNext(ServerSentEvent.<String>builder().comment(comment).build()); |
| 83 | + inboundMessageCount.incrementAndGet(); |
| 84 | + } |
| 85 | + |
80 | 86 | public void simulateEndpointEvent(String jsonMessage) { |
81 | 87 | events.tryEmitNext(ServerSentEvent.<String>builder().event("endpoint").data(jsonMessage).build()); |
82 | 88 | inboundMessageCount.incrementAndGet(); |
@@ -158,6 +164,27 @@ void testBuilderPattern() { |
158 | 164 | assertThatCode(() -> transport4.closeGracefully().block()).doesNotThrowAnyException(); |
159 | 165 | } |
160 | 166 |
|
| 167 | + @Test |
| 168 | + void testCommentSseMessage() { |
| 169 | + // If the line starts with a character (:) are comment lins and should be ingored |
| 170 | + // https://html.spec.whatwg.org/multipage/server-sent-events.html#event-stream-interpretation |
| 171 | + |
| 172 | + CopyOnWriteArrayList<Throwable> droppedErrors = new CopyOnWriteArrayList<>(); |
| 173 | + reactor.core.publisher.Hooks.onErrorDropped(droppedErrors::add); |
| 174 | + |
| 175 | + try { |
| 176 | + // Simulate receiving the SSE comment line |
| 177 | + transport.simulateSseComment("sse comment"); |
| 178 | + |
| 179 | + StepVerifier.create(transport.closeGracefully()).verifyComplete(); |
| 180 | + |
| 181 | + assertThat(droppedErrors).hasSize(0); |
| 182 | + } |
| 183 | + finally { |
| 184 | + reactor.core.publisher.Hooks.resetOnErrorDropped(); |
| 185 | + } |
| 186 | + } |
| 187 | + |
161 | 188 | @Test |
162 | 189 | void testMessageProcessing() { |
163 | 190 | // Create a test message |
|
0 commit comments