@@ -207,7 +207,7 @@ final class LDSwiftEventSourceTests: XCTestCase {
207
207
XCTAssertEqual ( handler. request. allHTTPHeaderFields ? [ " X-LD-Header " ] , " def " )
208
208
es. stop ( )
209
209
}
210
-
210
+
211
211
func testStartRequestIsNotReentrant( ) {
212
212
var config = EventSource . Config ( handler: mockHandler, url: URL ( string: " http://example.com " ) !)
213
213
config. urlSessionConfiguration = sessionWithMockProtocol ( )
@@ -349,6 +349,47 @@ final class LDSwiftEventSourceTests: XCTestCase {
349
349
// Error should not have been given to the handler
350
350
mockHandler. events. expectNoEvent ( )
351
351
}
352
+
353
+ func testShutdownBy204Response( ) {
354
+ var config = EventSource . Config ( handler: mockHandler, url: URL ( string: " http://example.com " ) !)
355
+ config. urlSessionConfiguration = sessionWithMockProtocol ( )
356
+ config. reconnectTime = 0.1
357
+
358
+ let es = EventSource ( config: config)
359
+ es. start ( )
360
+
361
+ let handler = MockingProtocol . requested. expectEvent ( )
362
+ handler. respond ( statusCode: 204 )
363
+
364
+ MockingProtocol . requested. expectNoEvent ( within: 1.0 )
365
+
366
+ es. stop ( )
367
+ // Error should not have been given to the handler
368
+ mockHandler. events. expectNoEvent ( )
369
+ }
370
+
371
+ func testCanOverride204DefaultBehavior( ) {
372
+ var config = EventSource . Config ( handler: mockHandler, url: URL ( string: " http://example.com " ) !)
373
+ config. urlSessionConfiguration = sessionWithMockProtocol ( )
374
+ config. reconnectTime = 0.1
375
+ config. connectionErrorHandler = { err in
376
+ if let responseErr = err as? UnsuccessfulResponseError {
377
+ XCTAssertEqual ( responseErr. responseCode, 204 )
378
+ } else {
379
+ XCTFail ( " Expected UnsuccessfulResponseError to be given to handler " )
380
+ }
381
+ return . shutdown
382
+ }
383
+ let es = EventSource ( config: config)
384
+ es. start ( )
385
+ let handler = MockingProtocol . requested. expectEvent ( )
386
+ handler. respond ( statusCode: 204 )
387
+ // Expect the client not to reconnect
388
+ MockingProtocol . requested. expectNoEvent ( within: 1.0 )
389
+ es. stop ( )
390
+ // Error should not have been given to the handler
391
+ mockHandler. events. expectNoEvent ( )
392
+ }
352
393
#endif
353
394
}
354
395
0 commit comments