Remove @testable use of NIO. (#11)

Motivation:

When this was in-tree with NIO we could safely use @testable imports to
get at the project internals, because we couldn't possibly regress against
them. This is no longer true, so we should avoid @testable imports.

Modifications:

Removed all @testable imports.

Changed NIO.Posix.open to Darwin/Glibc.open.

Replaced uses of fulfilled with either wait() or callbacks.

Result:

Less chance of randomly breaking due to NIO changes.
This commit is contained in:
Cory Benfield authored and GitHub committed 2018-03-26 15:33:38 +01:00
1 parent 85a55f91bf
commit ea006b6368
4 files changed
+24 -11

No files matched your search

@@ -14,7 +14,7 @@
import XCTest
import CNIOOpenSSL
@testable import NIO
import NIO
@testable import NIOOpenSSL
import NIOTLS
import class Foundation.Process
@@ -298,8 +298,8 @@ class OpenSSLIntegrationTest: XCTestCase {
guard let fileName = fileName else {
fatalError("couldn't make temp file")
}
let tempFile = try fileName.withCString { ptr in
return try Posix.open(file: ptr, oFlag: O_RDWR | O_CREAT | O_TRUNC | O_CLOEXEC, mode: 0o644)
let tempFile = fileName.withCString { ptr in
return open(ptr, O_RDWR | O_CREAT | O_TRUNC | O_CLOEXEC, 0o644)
}
precondition(tempFile > 1, String(cString: strerror(errno)))
let fileBio = BIO_new_fp(fdopen(tempFile, "w+"), BIO_CLOSE)
@@ -487,7 +487,12 @@ class OpenSSLIntegrationTest: XCTestCase {
serverClosed = true
for promise in promises {
XCTAssert(promise.futureResult.fulfilled)
// This should never block, but it may throw because the I/O is complete.
do {
_ = try promise.futureResult.wait()
} catch {
// Suppress all errors, they're fine.
}
}
}
@@ -600,7 +605,7 @@ class OpenSSLIntegrationTest: XCTestCase {
let closePromise: EventLoopPromise<Void> = channel.eventLoop.newPromise()
channel.close(promise: closePromise)
XCTAssertTrue(closePromise.futureResult.fulfilled)
XCTAssertNoThrow(try closePromise.futureResult.wait())
}
func testAddingTlsToActiveChannelStillHandshakes() throws {
@@ -729,6 +734,7 @@ class OpenSSLIntegrationTest: XCTestCase {
func testDontLoseClosePromises() throws {
let serverChannel = EmbeddedChannel()
let clientChannel = EmbeddedChannel()
var channelClosed = false
defer {
// We know this will throw.
_ = try? serverChannel.finish()
@@ -754,10 +760,15 @@ class OpenSSLIntegrationTest: XCTestCase {
// synchronization: all of this should succeed synchronously. If it doesn't, that's
// a bug too!
let closePromise = serverChannel.close()
XCTAssertFalse(closePromise.fulfilled)
closePromise.whenComplete {
// This looks like unsynchronized access to channelClosed, but it isn't: as we're
// using EmbeddedChannel here there is no cross-thread hopping.
channelClosed = true
}
XCTAssertFalse(channelClosed)
serverChannel.pipeline.fireChannelInactive()
XCTAssertTrue(closePromise.fulfilled)
XCTAssertTrue(channelClosed)
closePromise.map {
XCTFail("Unexpected success")
@@ -940,7 +951,9 @@ class OpenSSLIntegrationTest: XCTestCase {
_ = try clientChannel.writeAndFlush(originalBuffer).wait()
// At this time all the writes should have succeeded.
XCTAssertTrue(promises.map { $0.fulfilled }.reduce(true, { $0 && $1 }))
for promise in promises {
XCTAssertNoThrow(try promise.wait())
}
let newBuffer = try completionPromise.futureResult.wait()
XCTAssertEqual(newBuffer, originalBuffer)
@@ -14,7 +14,7 @@
import Foundation
import XCTest
@testable import NIO
import NIO
@testable import NIOOpenSSL
let multiSanCert = """
@@ -14,7 +14,7 @@
import Foundation
import XCTest
@testable import NIO
import NIO
@testable import NIOOpenSSL
class SSLPrivateKeyTest: XCTestCase {
@@ -14,7 +14,7 @@
import XCTest
import CNIOOpenSSL
@testable import NIO
import NIO
@testable import NIOOpenSSL
import NIOTLS