Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test failures #3183

Merged
merged 2 commits into from
Apr 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions Tests/VaporTests/PipelineTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import XCTest
import AsyncHTTPClient
import NIOEmbedded
import NIOCore
import NIOConcurrencyHelpers

final class PipelineTests: XCTestCase {
var app: Application!
Expand Down Expand Up @@ -86,7 +87,9 @@ final class PipelineTests: XCTestCase {
}))
}

try app.start()
app.environment.arguments = ["serve"]
gwynne marked this conversation as resolved.
Show resolved Hide resolved
app.http.server.configuration.port = 0
try await app.startup()

guard
let localAddress = app.http.server.shared.localAddress,
Expand All @@ -96,7 +99,7 @@ final class PipelineTests: XCTestCase {
return
}

let client = HTTPClient(eventLoopGroupProvider: .createNew)
let client = HTTPClient()

let chunks = [
"1\r\n",
Expand All @@ -111,14 +114,15 @@ final class PipelineTests: XCTestCase {
]

let response = try await client.post(url: "http://localhost:\(port)/echo", body: .stream { writer in
let box = UnsafeMutableTransferBox(writer)
@Sendable func write(chunks: [String]) -> EventLoopFuture<Void> {
var chunks = chunks
let chunk = chunks.removeFirst()

if chunks.isEmpty {
return writer.write(.byteBuffer(ByteBuffer(string: chunk)))
return box.wrappedValue.write(.byteBuffer(ByteBuffer(string: chunk)))
} else {
return writer.write(.byteBuffer(ByteBuffer(string: chunk))).flatMap { [chunks] in
return box.wrappedValue.write(.byteBuffer(ByteBuffer(string: chunk))).flatMap { [chunks] in
return write(chunks: chunks)
}
}
Expand Down