Skip to content

Commit

Permalink
Add test verifying connection is closed if error thrown in response b…
Browse files Browse the repository at this point in the history
…ody writer
  • Loading branch information
adam-fowler committed Jan 14, 2025
1 parent 480f29f commit f377115
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Tests/HummingbirdTests/ApplicationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,27 @@ final class ApplicationTests: XCTestCase {
}
}
#endif

func testErrorInResponseWriterClosesConnection() async throws {
let router = Router()
router.post("error") { request, context -> Response in
Response(
status: .ok,
body: .init { writer in
throw HTTPError(.badRequest)
}
)
}
let app = Application(router: router)
try await app.test(.live) { client in
do {
_ = try await client.execute(uri: "/error", method: .post)
XCTFail("Should not receive a response as the response writer failed before finishing")
} catch TestClient.Error.connectionClosing {
// verify connection was closed before reading full response
}
}
}
}

/// HTTPField used during tests
Expand Down

0 comments on commit f377115

Please sign in to comment.