Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Speed up slow unit tests.
Motivation:

One single test, testWeDealWithFlowControlProperly, was taking up to 16s
to run when the rest of the test suite would run in less than 1s. We
need to speed that test up.

Modifications:

Speedily initialize the bytes of the buffer.

Result:

Test now runs in 8ms.
  • Loading branch information
Lukasa committed Apr 29, 2020
commit cd692f72f0f8e58da2a2a5733132ae56031932da
6 changes: 5 additions & 1 deletion Tests/NIOSSHTests/ChildChannelMultiplexerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1169,8 +1169,12 @@ final class ChildChannelMultiplexerTests: XCTestCase {
XCTAssertNoThrow(try harness.multiplexer.receiveMessage(self.openConfirmation(originalChannelID: channelID!, peerChannelID: 1)))

// The default window size is 1<<24 bytes. Sadly, we need a buffer that size.
// Sorry for the unsafe code, but otherwise this test takes _ages_.
var buffer = channel.allocator.buffer(capacity: (1 << 24) + 1)
buffer.writeBytes(repeatElement(0, count: (1 << 24) + 1))
buffer.writeWithUnsafeMutableBytes(minimumWritableBytes: (1 << 24) + 1) { ptr in
memset(ptr.baseAddress!, 0, (1 << 24) + 1)
return (1 << 24) + 1
}

// We're going to write one byte short.
XCTAssertEqual(harness.flushedMessages.count, 1)
Expand Down