From 00be3015faeda1583b65809b887bc7a3d501f61d Mon Sep 17 00:00:00 2001 From: Adam Fowler Date: Wed, 4 Oct 2023 14:38:00 +0100 Subject: [PATCH] Add test for singleton EventLoopGroupProvider --- Tests/HummingbirdTests/ApplicationTests.swift | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Tests/HummingbirdTests/ApplicationTests.swift b/Tests/HummingbirdTests/ApplicationTests.swift index 839fdd3fd..a8a315439 100644 --- a/Tests/HummingbirdTests/ApplicationTests.swift +++ b/Tests/HummingbirdTests/ApplicationTests.swift @@ -13,6 +13,7 @@ //===----------------------------------------------------------------------===// import Hummingbird +import HummingbirdCoreXCT import HummingbirdXCT import NIOHTTP1 import XCTest @@ -473,4 +474,28 @@ final class ApplicationTests: XCTestCase { XCTAssert(address == "127.0.0.1" || address == "::1") } } + + func testSingleEventLoopGroup() throws { + let app = HBApplication(eventLoopGroupProvider: .singleton) + app.router.get("/hello") { request -> EventLoopFuture in + let buffer = request.allocator.buffer(string: "GET: Hello") + return request.eventLoop.makeSucceededFuture(buffer) + } + try app.start() + defer { app.stop() } + + let client = HBXCTClient( + host: "localhost", + port: app.server.port!, + configuration: .init(timeout: .seconds(15)), + eventLoopGroupProvider: .createNew + ) + defer { try? client.syncShutdown() } + client.connect() + let response = try client.get("/hello").wait() + var body = try XCTUnwrap(response.body) + let string = body.readString(length: body.readableBytes) + XCTAssertEqual(response.status, .ok) + XCTAssertEqual(string, "GET: Hello") + } }