@@ -207,7 +207,7 @@ final class LDSwiftEventSourceTests: XCTestCase {
207207 XCTAssertEqual ( handler. request. allHTTPHeaderFields ? [ " X-LD-Header " ] , " def " )
208208 es. stop ( )
209209 }
210-
210+
211211 func testStartRequestIsNotReentrant( ) {
212212 var config = EventSource . Config ( handler: mockHandler, url: URL ( string: " http://example.com " ) !)
213213 config. urlSessionConfiguration = sessionWithMockProtocol ( )
@@ -349,6 +349,47 @@ final class LDSwiftEventSourceTests: XCTestCase {
349349 // Error should not have been given to the handler
350350 mockHandler. events. expectNoEvent ( )
351351 }
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+ }
352393#endif
353394}
354395
0 commit comments