make more tests faster (#1367)

Motivation:

Some tests are slow (#1358), they should be faster.

Modifications:

Make more tests faster.

Result:

Faster test suite
This commit is contained in:
Johannes Weiss 2020-01-29 17:00:13 +00:00 committed by GitHub
parent 9f9976adae
commit d220737da7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 18 additions and 27 deletions

View File

@ -920,7 +920,7 @@ class NIOConcurrencyHelpersTests: XCTestCase {
@available(*, deprecated, message: "AtomicBox is deprecated, this is a test for the deprecated functionality")
func testLoadAndCASHammering() {
let allDeallocations = NIOAtomic<Int>.makeAtomic(value: 0)
let iterations = 100_000
let iterations = 1_000
@inline(never)
func doIt() {

View File

@ -62,14 +62,9 @@ internal class ArrayAccumulationHandler<T>: ChannelInboundHandler {
class HTTPServerClientTest : XCTestCase {
/* needs to be something reasonably large and odd so it has good odds producing incomplete writes even on the loopback interface */
private static let massiveResponseLength = 5 * 1024 * 1024 + 7
private static let massiveResponseLength = 1 * 1024 * 1024 + 7
private static let massiveResponseBytes: [UInt8] = {
var bytes: [UInt8] = []
bytes.reserveCapacity(HTTPServerClientTest.massiveResponseLength)
for f in 0..<HTTPServerClientTest.massiveResponseLength {
bytes.append(UInt8(f % 255))
}
return bytes
return Array(repeating: 0xff, count: HTTPServerClientTest.massiveResponseLength)
}()
enum SendMode {
@ -191,13 +186,7 @@ class HTTPServerClientTest : XCTestCase {
case "/massive-response":
var buf = context.channel.allocator.buffer(capacity: HTTPServerClientTest.massiveResponseLength)
buf.writeWithUnsafeMutableBytes(minimumWritableBytes: HTTPServerClientTest.massiveResponseLength) { targetPtr in
return HTTPServerClientTest.massiveResponseBytes.withUnsafeBytes { srcPtr in
precondition(targetPtr.count >= srcPtr.count)
targetPtr.copyMemory(from: srcPtr)
return srcPtr.count
}
}
buf.reserveCapacity(HTTPServerClientTest.massiveResponseLength)
buf.writeBytes(HTTPServerClientTest.massiveResponseBytes)
var head = HTTPResponseHead(version: req.version, status: .ok)
head.headers.add(name: "Connection", value: "close")

View File

@ -182,7 +182,7 @@ class HTTPTest: XCTestCase {
req2.headers.add(name: "C", value: "D")
try checkHTTPRequests([req1, req2])
try checkHTTPRequests(Array(repeating: req1, count: 1000))
try checkHTTPRequests(Array(repeating: req1, count: 10))
}
func testHTTPBody() throws {
@ -196,7 +196,9 @@ class HTTPTest: XCTestCase {
}
func testHTTPPipeliningWithBody() throws {
try checkHTTPRequests(Array(repeating: HTTPRequestHead(version: HTTPVersion(major: 1, minor: 1), method: .GET, uri: "/"), count: 1000),
try checkHTTPRequests(Array(repeating: HTTPRequestHead(version: HTTPVersion(major: 1, minor: 1),
method: .GET, uri: "/"),
count: 20),
body: "1")
}

View File

@ -1637,7 +1637,7 @@ class ByteBufferTest: XCTestCase {
func testLargeSliceBegin16MBIsOkayAndDoesNotCopy() throws {
var fourMBBuf = self.allocator.buffer(capacity: 4 * 1024 * 1024)
fourMBBuf.writeBytes(repeatElement(0xff, count: fourMBBuf.capacity))
fourMBBuf.writeBytes(Array<UInt8>(repeating: 0xff, count: fourMBBuf.capacity))
let totalBufferSize = 5 * fourMBBuf.readableBytes
XCTAssertEqual(4 * 1024 * 1024, fourMBBuf.readableBytes)
var buf = self.allocator.buffer(capacity: totalBufferSize)
@ -1674,7 +1674,7 @@ class ByteBufferTest: XCTestCase {
func testLargeSliceBeginMoreThan16MBIsOkay() throws {
var fourMBBuf = self.allocator.buffer(capacity: 4 * 1024 * 1024)
fourMBBuf.writeBytes(repeatElement(0xff, count: fourMBBuf.capacity))
fourMBBuf.writeBytes(Array<UInt8>(repeating: 0xff, count: fourMBBuf.capacity))
let totalBufferSize = 5 * fourMBBuf.readableBytes + 1
XCTAssertEqual(4 * 1024 * 1024, fourMBBuf.readableBytes)
var buf = self.allocator.buffer(capacity: totalBufferSize)

View File

@ -1851,7 +1851,7 @@ public final class ChannelTests: XCTestCase {
}
}
for _ in 0..<1000 {
for _ in 0..<20 {
XCTAssertNoThrow(try runTest())
}
}

View File

@ -83,7 +83,7 @@ class HeapTests: XCTestCase {
var maxHeapLast = UInt8.max
var minHeapLast = UInt8.min
let N = 100
let N = 10
for n in getRandomNumbers(count: N) {
maxHeap.append(n)

View File

@ -227,19 +227,19 @@ class NonBlockingFileIOTest: XCTestCase {
}
func testChunkReadingWorksForIncrediblyLongChain() throws {
let content = String(repeatElement("X", count: 20*1024))
let content = String(repeating: "X", count: 20*1024)
var numCalls = 0
let expectedByte = content.utf8.first!
try withTemporaryFile(content: content) { (fileHandle, path) -> Void in
let fr = FileRegion(fileHandle: fileHandle, readerIndex: 0, endIndex: content.utf8.count)
try self.fileIO.readChunked(fileRegion: fr,
try self.fileIO.readChunked(fileHandle: fileHandle,
fromOffset: 0,
byteCount: content.utf8.count,
chunkSize: 1,
allocator: self.allocator,
eventLoop: self.eventLoop) { buf in
var buf = buf
XCTAssertTrue(self.eventLoop.inEventLoop)
XCTAssertEqual(1, buf.readableBytes)
XCTAssertEqual(expectedByte, buf.readBytes(length: 1)!.first!)
XCTAssertEqual(expectedByte, buf.readableBytesView.first)
numCalls += 1
return self.eventLoop.makeSucceededFuture(())
}.wait()

View File

@ -624,7 +624,7 @@ class StreamChannelTest: XCTestCase {
case .waitingForWritableAgain:
XCTAssert(context.channel.isWritable)
self.state = .done
var buffer = context.channel.allocator.buffer(capacity: 100 * 1024 * 1024)
var buffer = context.channel.allocator.buffer(capacity: 10 * 1024 * 1024)
buffer.writeBytes(Array(repeating: UInt8(ascii: "X"), count: buffer.capacity - 1))
context.writeAndFlush(self.wrapOutboundOut(buffer), promise: self.finishedBigWritePromise)
self.beganBigWritePromise.succeed(())