Skip to content

Commit

Permalink
Add test for singleton EventLoopGroupProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler committed Oct 4, 2023
1 parent 25b365c commit 00be301
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Tests/HummingbirdTests/ApplicationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===//

import Hummingbird
import HummingbirdCoreXCT
import HummingbirdXCT
import NIOHTTP1
import XCTest
Expand Down Expand Up @@ -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<ByteBuffer> 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")
}
}

0 comments on commit 00be301

Please sign in to comment.