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 0071ce7
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 182 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@ import NIOHTTP2


func run(identifier: String) {
testRun(identifier: identifier) { channel in
testRun(identifier: identifier, usePromiseBasedAPI: true) { channel in
let http2Handler = NIOHTTP2Handler(mode: .client)
let multiplexer = HTTP2StreamMultiplexer(mode: .client, channel: channel, inboundStreamInitializer: nil)
try! channel.pipeline.addHandlers([
http2Handler,
multiplexer
]).wait()
return multiplexer
}

testRun(identifier: identifier + "_no_promise_based_API", usePromiseBasedAPI: false) { channel in
let http2Handler = NIOHTTP2Handler(mode: .client)
let multiplexer = HTTP2StreamMultiplexer(mode: .client, channel: channel, inboundStreamInitializer: nil)
try! channel.pipeline.addHandlers([
Expand All @@ -30,9 +40,16 @@ func run(identifier: String) {
return multiplexer
}

//
// MARK: - Inline HTTP2 multiplexer tests
testRun(identifier: identifier + "_inline") { channel in
testRun(identifier: identifier + "_inline", usePromiseBasedAPI: true) { channel in
let http2Handler = NIOHTTP2Handler(mode: .client, eventLoop: channel.eventLoop) { channel in
return channel.eventLoop.makeSucceededVoidFuture()
}
try! channel.pipeline.addHandler(http2Handler).wait()
return try! http2Handler.multiplexer.wait()
}

testRun(identifier: identifier + "_inline_no_promise_based_API", usePromiseBasedAPI: false) { channel in
let http2Handler = NIOHTTP2Handler(mode: .client, eventLoop: channel.eventLoop) { channel in
return channel.eventLoop.makeSucceededVoidFuture()
}
Expand All @@ -41,7 +58,11 @@ func run(identifier: String) {
}
}

private func testRun(identifier: String, pipelineConfigurator: (Channel) throws -> MultiplexerChannelCreator) {
private func testRun(
identifier: String,
usePromiseBasedAPI: Bool,
pipelineConfigurator: (Channel) throws -> MultiplexerChannelCreator
) {
let channel = EmbeddedChannel(handler: nil)
let multiplexer = try! pipelineConfigurator(channel)
try! channel.connect(to: SocketAddress(ipAddress: "1.2.3.4", port: 5678)).wait()
Expand All @@ -50,12 +71,20 @@ private func testRun(identifier: String, pipelineConfigurator: (Channel) throws
var streams = 0

for _ in 0..<1000 {
let promise = channel.eventLoop.makePromise(of: Channel.self)
multiplexer.createStreamChannel(promise: promise) { channel in
return channel.eventLoop.makeSucceededFuture(())
let channelFuture: EventLoopFuture<Channel>
if usePromiseBasedAPI {
let promise = channel.eventLoop.makePromise(of: Channel.self)
multiplexer.createStreamChannel(promise: promise) { channel in
return channel.eventLoop.makeSucceededFuture(())
}
channelFuture = promise.futureResult
} else {
channelFuture = multiplexer.createStreamChannel { channel in
return channel.eventLoop.makeSucceededFuture(())
}
}
channel.embeddedEventLoop.run()
let child = try! promise.futureResult.wait()
let child = try! channelFuture.wait()
streams += 1

let closeFuture = child.close()
Expand Down
6 changes: 2 additions & 4 deletions docker/docker-compose.2204.510.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,10 @@ services:
- MAX_ALLOCS_ALLOWED_client_server_request_response_inline=244050
- 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_create_client_stream_channel=37050
- MAX_ALLOCS_ALLOWED_create_client_stream_channel_inline=37050
- MAX_ALLOCS_ALLOWED_create_client_stream_channel_inline_no_promise_based_API=44050
- MAX_ALLOCS_ALLOWED_create_client_stream_channel_no_promise_based_API=37050
- MAX_ALLOCS_ALLOWED_get_100000_headers_canonical_form=200050
- MAX_ALLOCS_ALLOWED_get_100000_headers_canonical_form_trimming_whitespace=200050
- MAX_ALLOCS_ALLOWED_get_100000_headers_canonical_form_trimming_whitespace_from_long_string=300050
Expand Down
6 changes: 2 additions & 4 deletions docker/docker-compose.2204.58.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,10 @@ services:
- MAX_ALLOCS_ALLOWED_client_server_request_response_inline=244050
- 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_create_client_stream_channel=37050
- MAX_ALLOCS_ALLOWED_create_client_stream_channel_inline=37050
- MAX_ALLOCS_ALLOWED_create_client_stream_channel_inline_no_promise_based_API=44050
- MAX_ALLOCS_ALLOWED_create_client_stream_channel_no_promise_based_API=37050
- MAX_ALLOCS_ALLOWED_get_100000_headers_canonical_form=200050
- MAX_ALLOCS_ALLOWED_get_100000_headers_canonical_form_trimming_whitespace=200050
- MAX_ALLOCS_ALLOWED_get_100000_headers_canonical_form_trimming_whitespace_from_long_string=300050
Expand Down
6 changes: 2 additions & 4 deletions docker/docker-compose.2204.59.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,10 @@ services:
- MAX_ALLOCS_ALLOWED_client_server_request_response_inline=244050
- 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_create_client_stream_channel=37050
- MAX_ALLOCS_ALLOWED_create_client_stream_channel_inline=37050
- MAX_ALLOCS_ALLOWED_create_client_stream_channel_inline_no_promise_based_API=44050
- MAX_ALLOCS_ALLOWED_create_client_stream_channel_no_promise_based_API=37050
- MAX_ALLOCS_ALLOWED_get_100000_headers_canonical_form=200050
- MAX_ALLOCS_ALLOWED_get_100000_headers_canonical_form_trimming_whitespace=200050
- MAX_ALLOCS_ALLOWED_get_100000_headers_canonical_form_trimming_whitespace_from_long_string=300050
Expand Down
6 changes: 2 additions & 4 deletions docker/docker-compose.2204.main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,10 @@ services:
- MAX_ALLOCS_ALLOWED_client_server_request_response_inline=244050
- 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_create_client_stream_channel=37050
- MAX_ALLOCS_ALLOWED_create_client_stream_channel_inline=37050
- MAX_ALLOCS_ALLOWED_create_client_stream_channel_inline_no_promise_based_API=44050
- MAX_ALLOCS_ALLOWED_create_client_stream_channel_no_promise_based_API=37050
- MAX_ALLOCS_ALLOWED_get_100000_headers_canonical_form=200050
- MAX_ALLOCS_ALLOWED_get_100000_headers_canonical_form_trimming_whitespace=200050
- MAX_ALLOCS_ALLOWED_get_100000_headers_canonical_form_trimming_whitespace_from_long_string=300050
Expand Down

0 comments on commit 0071ce7

Please sign in to comment.