Skip to content

Commit

Permalink
Turn tests into variants instead of duplicating them
Browse files Browse the repository at this point in the history
  • Loading branch information
gjcairo committed Jul 16, 2024
1 parent fede418 commit 905dddc
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 180 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ func run(identifier: String) {
}.wait()
}

testRun(identifier: identifier + "_no_promise_based_API", usePromiseBasedAPI: false) { clientChannel in
return try! clientChannel.configureHTTP2Pipeline(mode: .client) { channel in
return channel.eventLoop.makeSucceededVoidFuture()
}.wait()
} serverPipelineConfigurator: { serverChannel in
_ = try! serverChannel.configureHTTP2Pipeline(mode: .server) { channel in
return channel.pipeline.addHandler(ServerHandler())
}.wait()
}

testRun(identifier: identifier + "_many", dataBlockCount: 100, dataBlockLengthBytes: 1000) { clientChannel in
return try! clientChannel.configureHTTP2Pipeline(mode: .client) { channel in
return channel.eventLoop.makeSucceededVoidFuture()
Expand All @@ -99,7 +109,16 @@ func run(identifier: String) {
}.wait()
}

//
testRun(identifier: identifier + "_many_no_promise_based_API", dataBlockCount: 100, dataBlockLengthBytes: 1000, usePromiseBasedAPI: false) { clientChannel in
return try! clientChannel.configureHTTP2Pipeline(mode: .client) { channel in
return channel.eventLoop.makeSucceededVoidFuture()
}.wait()
} serverPipelineConfigurator: { serverChannel in
_ = try! serverChannel.configureHTTP2Pipeline(mode: .server) { channel in
return channel.pipeline.addHandler(ServerHandler())
}.wait()
}

// MARK: - Inline HTTP2 multiplexer tests
testRun(identifier: identifier + "_inline") { clientChannel in
return try! clientChannel.configureHTTP2Pipeline(mode: .client, connectionConfiguration: .init(), streamConfiguration: .init()) { channel in
Expand All @@ -111,6 +130,16 @@ func run(identifier: String) {
}.wait()
}

testRun(identifier: identifier + "_inline_no_promise_based_API", usePromiseBasedAPI: false) { clientChannel in
return try! clientChannel.configureHTTP2Pipeline(mode: .client, connectionConfiguration: .init(), streamConfiguration: .init()) { channel in
return channel.eventLoop.makeSucceededVoidFuture()
}.wait()
} serverPipelineConfigurator: { serverChannel in
_ = try! serverChannel.configureHTTP2Pipeline(mode: .server, connectionConfiguration: .init(), streamConfiguration: .init()) { channel in
return channel.pipeline.addHandler(ServerHandler())
}.wait()
}

testRun(identifier: identifier + "_many_inline", dataBlockCount: 100, dataBlockLengthBytes: 1000) { clientChannel in
return try! clientChannel.configureHTTP2Pipeline(mode: .client, connectionConfiguration: .init(), streamConfiguration: .init()) { channel in
return channel.eventLoop.makeSucceededVoidFuture()
Expand All @@ -120,9 +149,26 @@ func run(identifier: String) {
return channel.pipeline.addHandler(ServerHandler())
}.wait()
}

testRun(identifier: identifier + "_many_inline_no_promise_based_API", dataBlockCount: 100, dataBlockLengthBytes: 1000, usePromiseBasedAPI: false) { clientChannel in
return try! clientChannel.configureHTTP2Pipeline(mode: .client, connectionConfiguration: .init(), streamConfiguration: .init()) { channel in
return channel.eventLoop.makeSucceededVoidFuture()
}.wait()
} serverPipelineConfigurator: { serverChannel in
_ = try! serverChannel.configureHTTP2Pipeline(mode: .server, connectionConfiguration: .init(), streamConfiguration: .init()) { channel in
return channel.pipeline.addHandler(ServerHandler())
}.wait()
}
}

private func testRun(identifier: String, dataBlockCount: Int = 0, dataBlockLengthBytes: Int = 0, clientPipelineConfigurator: (Channel) throws -> MultiplexerChannelCreator, serverPipelineConfigurator: (Channel) throws -> ()) {
private func testRun(
identifier: String,
dataBlockCount: Int = 0,
dataBlockLengthBytes: Int = 0,
usePromiseBasedAPI: Bool = true,
clientPipelineConfigurator: (Channel) throws -> MultiplexerChannelCreator,
serverPipelineConfigurator: (Channel) throws -> ()
) {
let loop = EmbeddedEventLoop()

measure(identifier: identifier) {
Expand All @@ -137,12 +183,21 @@ private func testRun(identifier: String, dataBlockCount: Int = 0, dataBlockLengt
try! clientChannel.connect(to: SocketAddress(ipAddress: "1.2.3.4", port: 5678)).wait()
try! serverChannel.connect(to: SocketAddress(ipAddress: "1.2.3.4", port: 5678)).wait()

let promise = clientChannel.eventLoop.makePromise(of: Channel.self)
clientMultiplexer.createStreamChannel(promise: promise) { channel in
return channel.pipeline.addHandler(ClientHandler(dataBlockCount: dataBlockCount, dataBlockLengthBytes: dataBlockLengthBytes))
let channelFuture: EventLoopFuture<Channel>
if usePromiseBasedAPI {
let promise = clientChannel.eventLoop.makePromise(of: Channel.self)
clientMultiplexer.createStreamChannel(promise: promise) { channel in
return channel.pipeline.addHandler(ClientHandler(dataBlockCount: dataBlockCount, dataBlockLengthBytes: dataBlockLengthBytes))
}
channelFuture = promise.futureResult
} else {
channelFuture = clientMultiplexer.createStreamChannel { channel in
return channel.pipeline.addHandler(ClientHandler(dataBlockCount: dataBlockCount, dataBlockLengthBytes: dataBlockLengthBytes))
}
}

clientChannel.embeddedEventLoop.run()
let child = try! promise.futureResult.wait()
let child = try! channelFuture.wait()
let streamID = try! Int(child.getOption(HTTP2StreamChannelOptions.streamID).wait())

sumOfStreamIDs += streamID
Expand Down

This file was deleted.

8 changes: 4 additions & 4 deletions docker/docker-compose.2204.510.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ services:
- MAX_ALLOCS_ALLOWED_client_server_h1_request_response_inline=269050
- MAX_ALLOCS_ALLOWED_client_server_request_response=253050
- MAX_ALLOCS_ALLOWED_client_server_request_response_inline=244050
- MAX_ALLOCS_ALLOWED_client_server_request_response_inline_no_promise_based_API=251050
- MAX_ALLOCS_ALLOWED_client_server_request_response_many=1198050
- MAX_ALLOCS_ALLOWED_client_server_request_response_many_inline=889050
- MAX_ALLOCS_ALLOWED_client_server_request_response_no_promise_on_channel_creation=253050
- MAX_ALLOCS_ALLOWED_client_server_request_response_no_promise_on_channel_creation_inline=251050
- MAX_ALLOCS_ALLOWED_client_server_request_response_no_promise_on_channel_creation_many=1198050
- MAX_ALLOCS_ALLOWED_client_server_request_response_no_promise_on_channel_creation_many_inline=896050
- MAX_ALLOCS_ALLOWED_client_server_request_response_many_inline_no_promise_based_API=896050
- MAX_ALLOCS_ALLOWED_client_server_request_response_many_no_promise_based_API=1198050
- MAX_ALLOCS_ALLOWED_client_server_request_response_no_promise_based_API=253050
- MAX_ALLOCS_ALLOWED_create_client_stream_channel=37050
- MAX_ALLOCS_ALLOWED_create_client_stream_channel_inline=37050
- MAX_ALLOCS_ALLOWED_get_100000_headers_canonical_form=200050
Expand Down
8 changes: 4 additions & 4 deletions docker/docker-compose.2204.58.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ services:
- MAX_ALLOCS_ALLOWED_client_server_h1_request_response_inline=269050
- MAX_ALLOCS_ALLOWED_client_server_request_response=253050
- MAX_ALLOCS_ALLOWED_client_server_request_response_inline=244050
- MAX_ALLOCS_ALLOWED_client_server_request_response_inline_no_promise_based_API=251050
- MAX_ALLOCS_ALLOWED_client_server_request_response_many=1198050
- MAX_ALLOCS_ALLOWED_client_server_request_response_many_inline=889050
- MAX_ALLOCS_ALLOWED_client_server_request_response_no_promise_on_channel_creation=253050
- MAX_ALLOCS_ALLOWED_client_server_request_response_no_promise_on_channel_creation_inline=251050
- MAX_ALLOCS_ALLOWED_client_server_request_response_no_promise_on_channel_creation_many=1198050
- MAX_ALLOCS_ALLOWED_client_server_request_response_no_promise_on_channel_creation_many_inline=896050
- MAX_ALLOCS_ALLOWED_client_server_request_response_many_inline_no_promise_based_API=896050
- MAX_ALLOCS_ALLOWED_client_server_request_response_many_no_promise_based_API=1198050
- MAX_ALLOCS_ALLOWED_client_server_request_response_no_promise_based_API=253050
- MAX_ALLOCS_ALLOWED_create_client_stream_channel=37050
- MAX_ALLOCS_ALLOWED_create_client_stream_channel_inline=37050
- MAX_ALLOCS_ALLOWED_get_100000_headers_canonical_form=200050
Expand Down
8 changes: 4 additions & 4 deletions docker/docker-compose.2204.59.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ services:
- MAX_ALLOCS_ALLOWED_client_server_h1_request_response_inline=269050
- MAX_ALLOCS_ALLOWED_client_server_request_response=253050
- MAX_ALLOCS_ALLOWED_client_server_request_response_inline=244050
- MAX_ALLOCS_ALLOWED_client_server_request_response_inline_no_promise_based_API=251050
- MAX_ALLOCS_ALLOWED_client_server_request_response_many=1198050
- MAX_ALLOCS_ALLOWED_client_server_request_response_many_inline=889050
- MAX_ALLOCS_ALLOWED_client_server_request_response_no_promise_on_channel_creation=253050
- MAX_ALLOCS_ALLOWED_client_server_request_response_no_promise_on_channel_creation_inline=251050
- MAX_ALLOCS_ALLOWED_client_server_request_response_no_promise_on_channel_creation_many=1198050
- MAX_ALLOCS_ALLOWED_client_server_request_response_no_promise_on_channel_creation_many_inline=896050
- MAX_ALLOCS_ALLOWED_client_server_request_response_many_inline_no_promise_based_API=896050
- MAX_ALLOCS_ALLOWED_client_server_request_response_many_no_promise_based_API=1198050
- MAX_ALLOCS_ALLOWED_client_server_request_response_no_promise_based_API=253050
- MAX_ALLOCS_ALLOWED_create_client_stream_channel=37050
- MAX_ALLOCS_ALLOWED_create_client_stream_channel_inline=37050
- MAX_ALLOCS_ALLOWED_get_100000_headers_canonical_form=200050
Expand Down
8 changes: 4 additions & 4 deletions docker/docker-compose.2204.main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ services:
- MAX_ALLOCS_ALLOWED_client_server_h1_request_response_inline=269050
- MAX_ALLOCS_ALLOWED_client_server_request_response=253050
- MAX_ALLOCS_ALLOWED_client_server_request_response_inline=244050
- MAX_ALLOCS_ALLOWED_client_server_request_response_inline_no_promise_based_API=251050
- MAX_ALLOCS_ALLOWED_client_server_request_response_many=1198050
- MAX_ALLOCS_ALLOWED_client_server_request_response_many_inline=889050
- MAX_ALLOCS_ALLOWED_client_server_request_response_no_promise_on_channel_creation=253050
- MAX_ALLOCS_ALLOWED_client_server_request_response_no_promise_on_channel_creation_inline=251050
- MAX_ALLOCS_ALLOWED_client_server_request_response_no_promise_on_channel_creation_many=1198050
- MAX_ALLOCS_ALLOWED_client_server_request_response_no_promise_on_channel_creation_many_inline=896050
- MAX_ALLOCS_ALLOWED_client_server_request_response_many_inline_no_promise_based_API=896050
- MAX_ALLOCS_ALLOWED_client_server_request_response_many_no_promise_based_API=1198050
- MAX_ALLOCS_ALLOWED_client_server_request_response_no_promise_based_API=253050
- MAX_ALLOCS_ALLOWED_create_client_stream_channel=37050
- MAX_ALLOCS_ALLOWED_create_client_stream_channel_inline=37050
- MAX_ALLOCS_ALLOWED_get_100000_headers_canonical_form=200050
Expand Down

0 comments on commit 905dddc

Please sign in to comment.