diff --git a/Tests/NIOHTTP1Tests/HTTPRequestEncoderTest.swift b/Tests/NIOHTTP1Tests/HTTPRequestEncoderTest.swift index f455e1946..2be7cdb0a 100644 --- a/Tests/NIOHTTP1Tests/HTTPRequestEncoderTest.swift +++ b/Tests/NIOHTTP1Tests/HTTPRequestEncoderTest.swift @@ -26,10 +26,10 @@ class HTTPRequestEncoderTests: XCTestCase { private func sendRequest(withMethod method: HTTPMethod, andHeaders headers: HTTPHeaders) throws -> ByteBuffer { let channel = EmbeddedChannel() defer { - XCTAssertFalse(try! channel.finish()) + XCTAssertEqual(.some(false), try? channel.finish()) } - try! channel.pipeline.add(handler: HTTPRequestEncoder()).wait() + try channel.pipeline.add(handler: HTTPRequestEncoder()).wait() var request = HTTPRequestHead(version: HTTPVersion(major: 1, minor:1), method: method, uri: "/uri") request.headers = headers try channel.writeOutbound(data: HTTPClientRequestPart.head(request)) @@ -60,14 +60,14 @@ class HTTPRequestEncoderTests: XCTestCase { func testNoChunkedEncodingForHTTP10() throws { let channel = EmbeddedChannel() defer { - XCTAssertFalse(try! channel.finish()) + XCTAssertEqual(.some(false), try? channel.finish()) } - try! channel.pipeline.add(handler: HTTPRequestEncoder()).wait() + XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPRequestEncoder()).wait()) // This request contains neither Transfer-Encoding: chunked or Content-Length. let request = HTTPRequestHead(version: HTTPVersion(major: 1, minor:0), method: .GET, uri: "/uri") - try! channel.writeOutbound(data: HTTPClientRequestPart.head(request)) + XCTAssertNoThrow(try channel.writeOutbound(data: HTTPClientRequestPart.head(request))) let writtenData: IOData = channel.readOutbound()! switch writtenData { @@ -82,19 +82,19 @@ class HTTPRequestEncoderTests: XCTestCase { func testBody() throws { let channel = EmbeddedChannel() defer { - XCTAssertFalse(try! channel.finish()) + XCTAssertEqual(.some(false), try? channel.finish()) } - try! channel.pipeline.add(handler: HTTPRequestEncoder()).wait() + try channel.pipeline.add(handler: HTTPRequestEncoder()).wait() var request = HTTPRequestHead(version: HTTPVersion(major: 1, minor:1), method: .POST, uri: "/uri") request.headers.add(name: "content-length", value: "4") var buf = channel.allocator.buffer(capacity: 4) buf.write(staticString: "test") - try! channel.writeOutbound(data: HTTPClientRequestPart.head(request)) - try! channel.writeOutbound(data: HTTPClientRequestPart.body(.byteBuffer(buf))) - try! channel.writeOutbound(data: HTTPClientRequestPart.end(nil)) + XCTAssertNoThrow(try channel.writeOutbound(data: HTTPClientRequestPart.head(request))) + XCTAssertNoThrow(try channel.writeOutbound(data: HTTPClientRequestPart.body(.byteBuffer(buf)))) + XCTAssertNoThrow(try channel.writeOutbound(data: HTTPClientRequestPart.end(nil))) assertOutboundContainsOnly(channel, "POST /uri HTTP/1.1\r\ncontent-length: 4\r\n\r\n") assertOutboundContainsOnly(channel, "test") diff --git a/Tests/NIOHTTP1Tests/HTTPResponseCompressorTest.swift b/Tests/NIOHTTP1Tests/HTTPResponseCompressorTest.swift index 20810c384..5dd9fc347 100644 --- a/Tests/NIOHTTP1Tests/HTTPResponseCompressorTest.swift +++ b/Tests/NIOHTTP1Tests/HTTPResponseCompressorTest.swift @@ -134,7 +134,7 @@ class HTTPResponseCompressorTest: XCTestCase { private func clientParsingChannel() -> EmbeddedChannel { let channel = EmbeddedChannel() - try! channel.pipeline.addHTTPClientHandlers().wait() + XCTAssertNoThrow(try channel.pipeline.addHTTPClientHandlers().wait()) return channel } @@ -332,17 +332,17 @@ class HTTPResponseCompressorTest: XCTestCase { XCTAssertEqual(uncompressedBody, bodyBuffer) } - private func compressionChannel() -> EmbeddedChannel { + private func compressionChannel() throws -> EmbeddedChannel { let channel = EmbeddedChannel() - try! channel.pipeline.add(handler: HTTPResponseEncoder()).wait() - try! channel.pipeline.add(handler: HTTPResponseCompressor()).wait() + XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPResponseEncoder()).wait()) + XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPResponseCompressor()).wait()) return channel } func testCanCompressSimpleBodies() throws { - let channel = compressionChannel() + let channel = try compressionChannel() defer { - try! channel.close().wait() + XCTAssertNoThrow(try channel.close().wait()) } try sendRequest(acceptEncoding: "deflate", channel: channel) @@ -350,9 +350,9 @@ class HTTPResponseCompressorTest: XCTestCase { } func testCanCompressSimpleBodiesGzip() throws { - let channel = compressionChannel() + let channel = try compressionChannel() defer { - try! channel.close().wait() + XCTAssertNoThrow(try channel.close().wait()) } try sendRequest(acceptEncoding: "gzip", channel: channel) @@ -360,9 +360,9 @@ class HTTPResponseCompressorTest: XCTestCase { } func testCanCompressDeflateWithAwkwardFlushes() throws { - let channel = compressionChannel() + let channel = try compressionChannel() defer { - try! channel.close().wait() + XCTAssertNoThrow(try channel.close().wait()) } try sendRequest(acceptEncoding: "deflate", channel: channel) @@ -370,9 +370,9 @@ class HTTPResponseCompressorTest: XCTestCase { } func testCanCompressGzipWithAwkwardFlushes() throws { - let channel = compressionChannel() + let channel = try compressionChannel() defer { - try! channel.close().wait() + XCTAssertNoThrow(try channel.close().wait()) } try sendRequest(acceptEncoding: "gzip", channel: channel) @@ -380,9 +380,9 @@ class HTTPResponseCompressorTest: XCTestCase { } func testDoesNotCompressWithoutAcceptEncodingHeader() throws { - let channel = compressionChannel() + let channel = try compressionChannel() defer { - try! channel.close().wait() + XCTAssertNoThrow(try channel.close().wait()) } try sendRequest(acceptEncoding: nil, channel: channel) @@ -390,9 +390,9 @@ class HTTPResponseCompressorTest: XCTestCase { } func testHandlesPipelinedRequestsProperly() throws { - let channel = compressionChannel() + let channel = try compressionChannel() defer { - try! channel.close().wait() + XCTAssertNoThrow(try channel.close().wait()) } // Three requests: one for deflate, one for gzip, one for nothing. @@ -406,9 +406,9 @@ class HTTPResponseCompressorTest: XCTestCase { } func testHandlesBasicQValues() throws { - let channel = compressionChannel() + let channel = try compressionChannel() defer { - try! channel.close().wait() + XCTAssertNoThrow(try channel.close().wait()) } try sendRequest(acceptEncoding: "gzip, deflate;q=0.5", channel: channel) @@ -416,9 +416,9 @@ class HTTPResponseCompressorTest: XCTestCase { } func testAlwaysPrefersHighestQValue() throws { - let channel = compressionChannel() + let channel = try compressionChannel() defer { - try! channel.close().wait() + XCTAssertNoThrow(try channel.close().wait()) } try sendRequest(acceptEncoding: "deflate;q=0.5, gzip;q=0.8, *;q=0.3", channel: channel) @@ -426,9 +426,9 @@ class HTTPResponseCompressorTest: XCTestCase { } func testAsteriskMeansGzip() throws { - let channel = compressionChannel() + let channel = try compressionChannel() defer { - try! channel.close().wait() + XCTAssertNoThrow(try channel.close().wait()) } try sendRequest(acceptEncoding: "*", channel: channel) @@ -436,9 +436,9 @@ class HTTPResponseCompressorTest: XCTestCase { } func testIgnoresUnknownAlgorithms() throws { - let channel = compressionChannel() + let channel = try compressionChannel() defer { - try! channel.close().wait() + XCTAssertNoThrow(try channel.close().wait()) } try sendRequest(acceptEncoding: "br", channel: channel) @@ -446,9 +446,9 @@ class HTTPResponseCompressorTest: XCTestCase { } func testNonNumericQValuePreventsChoice() throws { - let channel = compressionChannel() + let channel = try compressionChannel() defer { - try! channel.close().wait() + XCTAssertNoThrow(try channel.close().wait()) } try sendRequest(acceptEncoding: "deflate;q=fish=fish, gzip;q=0.3", channel: channel) @@ -456,9 +456,9 @@ class HTTPResponseCompressorTest: XCTestCase { } func testNaNQValuePreventsChoice() throws { - let channel = compressionChannel() + let channel = try compressionChannel() defer { - try! channel.close().wait() + XCTAssertNoThrow(try channel.close().wait()) } try sendRequest(acceptEncoding: "deflate;q=NaN, gzip;q=0.3", channel: channel) @@ -466,9 +466,9 @@ class HTTPResponseCompressorTest: XCTestCase { } func testInfinityQValuePreventsChoice() throws { - let channel = compressionChannel() + let channel = try compressionChannel() defer { - try! channel.close().wait() + XCTAssertNoThrow(try channel.close().wait()) } try sendRequest(acceptEncoding: "deflate;q=Inf, gzip;q=0.3", channel: channel) @@ -476,9 +476,9 @@ class HTTPResponseCompressorTest: XCTestCase { } func testNegativeInfinityQValuePreventsChoice() throws { - let channel = compressionChannel() + let channel = try compressionChannel() defer { - try! channel.close().wait() + XCTAssertNoThrow(try channel.close().wait()) } try sendRequest(acceptEncoding: "deflate;q=-Inf, gzip;q=0.3", channel: channel) @@ -486,9 +486,9 @@ class HTTPResponseCompressorTest: XCTestCase { } func testOutOfRangeQValuePreventsChoice() throws { - let channel = compressionChannel() + let channel = try compressionChannel() defer { - try! channel.close().wait() + XCTAssertNoThrow(try channel.close().wait()) } try sendRequest(acceptEncoding: "deflate;q=2.2, gzip;q=0.3", channel: channel) @@ -496,7 +496,7 @@ class HTTPResponseCompressorTest: XCTestCase { } func testRemovingHandlerFailsPendingWrites() throws { - let channel = compressionChannel() + let channel = try compressionChannel() try sendRequest(acceptEncoding: "gzip", channel: channel) let head = HTTPResponseHead(version: HTTPVersion(major: 1, minor: 1), status: .ok) let writePromise: EventLoopPromise = channel.eventLoop.newPromise() @@ -522,7 +522,7 @@ class HTTPResponseCompressorTest: XCTestCase { } func testDoesNotBufferWritesNoAlgorithm() throws { - let channel = compressionChannel() + let channel = try compressionChannel() try sendRequest(acceptEncoding: nil, channel: channel) let head = HTTPResponseHead(version: HTTPVersion(major: 1, minor: 1), status: .ok) let writePromise: EventLoopPromise = channel.eventLoop.newPromise() diff --git a/Tests/NIOHTTP1Tests/HTTPResponseEncoderTest.swift b/Tests/NIOHTTP1Tests/HTTPResponseEncoderTest.swift index a79dd447e..e68771f9b 100644 --- a/Tests/NIOHTTP1Tests/HTTPResponseEncoderTest.swift +++ b/Tests/NIOHTTP1Tests/HTTPResponseEncoderTest.swift @@ -26,13 +26,13 @@ class HTTPResponseEncoderTests: XCTestCase { private func sendResponse(withStatus status: HTTPResponseStatus, andHeaders headers: HTTPHeaders) -> ByteBuffer { let channel = EmbeddedChannel() defer { - XCTAssertFalse(try! channel.finish()) + XCTAssertEqual(.some(false), try? channel.finish()) } - try! channel.pipeline.add(handler: HTTPResponseEncoder()).wait() + XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPResponseEncoder()).wait()) var switchingResponse = HTTPResponseHead(version: HTTPVersion(major: 1, minor:1), status: status) switchingResponse.headers = headers - try! channel.writeOutbound(data: HTTPServerResponsePart.head(switchingResponse)) + XCTAssertNoThrow(try channel.writeOutbound(data: HTTPServerResponsePart.head(switchingResponse))) if case .some(.byteBuffer(let buffer)) = channel.readOutbound() { return buffer } else { @@ -95,14 +95,14 @@ class HTTPResponseEncoderTests: XCTestCase { func testNoChunkedEncodingForHTTP10() throws { let channel = EmbeddedChannel() defer { - XCTAssertFalse(try! channel.finish()) + XCTAssertEqual(.some(false), try? channel.finish()) } - try! channel.pipeline.add(handler: HTTPResponseEncoder()).wait() + XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPResponseEncoder()).wait()) // This response contains neither Transfer-Encoding: chunked or Content-Length. let response = HTTPResponseHead(version: HTTPVersion(major: 1, minor:0), status: .ok) - try! channel.writeOutbound(data: HTTPServerResponsePart.head(response)) + XCTAssertNoThrow(try channel.writeOutbound(data: HTTPServerResponsePart.head(response))) let writtenData: IOData = channel.readOutbound()! switch writtenData{ diff --git a/Tests/NIOHTTP1Tests/HTTPUpgradeTests.swift b/Tests/NIOHTTP1Tests/HTTPUpgradeTests.swift index ae8061b50..24c512ddf 100644 --- a/Tests/NIOHTTP1Tests/HTTPUpgradeTests.swift +++ b/Tests/NIOHTTP1Tests/HTTPUpgradeTests.swift @@ -27,8 +27,8 @@ private extension ChannelPipeline { } } -private func serverHTTPChannel(group: EventLoopGroup, handlers: [ChannelHandler]) -> Channel { - return try! ServerBootstrap(group: group) +private func serverHTTPChannel(group: EventLoopGroup, handlers: [ChannelHandler]) throws -> Channel { + return try ServerBootstrap(group: group) .serverChannelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1) .childChannelInitializer { channel in channel.pipeline.addHTTPServerHandlers().then { @@ -38,16 +38,16 @@ private func serverHTTPChannel(group: EventLoopGroup, handlers: [ChannelHandler] }.bind(to: "127.0.0.1", on: 0).wait() } -private func connectedClientChannel(group: EventLoopGroup, serverAddress: SocketAddress) -> Channel { - return try! ClientBootstrap(group: group) +private func connectedClientChannel(group: EventLoopGroup, serverAddress: SocketAddress) throws -> Channel { + return try ClientBootstrap(group: group) .connect(to: serverAddress) .wait() } -private func setUpTest(withHandlers handlers: [ChannelHandler]) -> (EventLoopGroup, Channel, Channel) { +private func setUpTest(withHandlers handlers: [ChannelHandler]) throws -> (EventLoopGroup, Channel, Channel) { let group = MultiThreadedEventLoopGroup(numThreads: 1) - let serverChannel = serverHTTPChannel(group: group, handlers: handlers) - let clientChannel = connectedClientChannel(group: group, serverAddress: serverChannel.localAddress!) + let serverChannel = try serverHTTPChannel(group: group, handlers: handlers) + let clientChannel = try connectedClientChannel(group: group, serverAddress: serverChannel.localAddress!) return (group, serverChannel, clientChannel) } @@ -176,15 +176,15 @@ class HTTPUpgradeTestCase: XCTestCase { let handler = HTTPServerUpgradeHandler(upgraders: [ExplodingUpgrader(forProtocol: "myproto")]) { _ in XCTFail("upgrade completed") } - let (group, server, client) = setUpTest(withHandlers: [handler]) + let (group, server, client) = try setUpTest(withHandlers: [handler]) defer { - try! client.close().wait() - try! server.close().wait() - try! group.syncShutdownGracefully() + XCTAssertNoThrow(try client.close().wait()) + XCTAssertNoThrow(try server.close().wait()) + XCTAssertNoThrow(try group.syncShutdownGracefully()) } let request = "OPTIONS * HTTP/1.1\r\nHost: localhost\r\n\r\n" - try! client.writeAndFlush(data: NIOAny(ByteBuffer.forString(request))).wait() + XCTAssertNoThrow(try client.writeAndFlush(data: NIOAny(ByteBuffer.forString(request))).wait()) // At this time the channel pipeline should not contain our handler: it should have removed itself. try client.pipeline.assertDoesNotContain(handler: handler) @@ -194,16 +194,16 @@ class HTTPUpgradeTestCase: XCTestCase { let handler = HTTPServerUpgradeHandler(upgraders: [ExplodingUpgrader(forProtocol: "myproto")]) { _ in XCTFail("upgrade completed") } - let (group, server, client) = setUpTest(withHandlers: [handler]) + let (group, server, client) = try setUpTest(withHandlers: [handler]) defer { - try! client.close().wait() - try! server.close().wait() - try! group.syncShutdownGracefully() + XCTAssertNoThrow(try client.close().wait()) + XCTAssertNoThrow(try server.close().wait()) + XCTAssertNoThrow(try group.syncShutdownGracefully()) } // This request fires a subsequent upgrade in immediately. It should also be ignored. let request = "OPTIONS * HTTP/1.1\r\nHost: localhost\r\n\r\nOPTIONS * HTTP/1.1\r\nHost: localhost\r\nUpgrade: myproto\r\nConnection: upgrade\r\n\r\n" - try! client.writeAndFlush(data: NIOAny(ByteBuffer.forString(request))).wait() + XCTAssertNoThrow(try client.writeAndFlush(data: NIOAny(ByteBuffer.forString(request))).wait()) // At this time the channel pipeline should not contain our handler: it should have removed itself. try client.pipeline.assertDoesNotContain(handler: handler) @@ -212,7 +212,7 @@ class HTTPUpgradeTestCase: XCTestCase { func testUpgradeHandlerBarfsOnUnexpectedOrdering() throws { let channel = EmbeddedChannel() defer { - XCTAssertFalse(try! channel.finish()) + XCTAssertEqual(.some(false), try? channel.finish()) } let handler = HTTPServerUpgradeHandler(upgraders: [ExplodingUpgrader(forProtocol: "myproto")]) { _ in @@ -220,7 +220,7 @@ class HTTPUpgradeTestCase: XCTestCase { } let data = HTTPServerRequestPart.body(ByteBuffer.forString("hello")) - try! channel.pipeline.add(handler: handler).wait() + XCTAssertNoThrow(try channel.pipeline.add(handler: handler).wait()) do { try channel.writeInbound(data: data) @@ -255,9 +255,9 @@ class HTTPUpgradeTestCase: XCTestCase { ctx.close(promise: nil) } - let (group, server, client) = setUpTest(withHandlers: [handler]) + let (group, server, client) = try setUpTest(withHandlers: [handler]) defer { - try! group.syncShutdownGracefully() + XCTAssertNoThrow(try group.syncShutdownGracefully()) } let completePromise: EventLoopPromise = group.next().newPromise() @@ -268,14 +268,14 @@ class HTTPUpgradeTestCase: XCTestCase { expectedResponseHeaders: ["x-upgrade-complete: true", "upgrade: myproto", "connection: upgrade"]) completePromise.succeed(result: ()) } - try! client.pipeline.add(handler: clientHandler).wait() + XCTAssertNoThrow(try client.pipeline.add(handler: clientHandler).wait()) // This request is safe to upgrade. let request = "OPTIONS * HTTP/1.1\r\nHost: localhost\r\nUpgrade: myproto\r\nKafkaesque: yup\r\nConnection: upgrade\r\nConnection: kafkaesque\r\n\r\n" - try! client.writeAndFlush(data: NIOAny(ByteBuffer.forString(request))).wait() + XCTAssertNoThrow(try client.writeAndFlush(data: NIOAny(ByteBuffer.forString(request))).wait()) // Let the machinery do its thing. - try! completePromise.futureResult.wait() + XCTAssertNoThrow(try completePromise.futureResult.wait()) // At this time we want to assert that everything got called. Their own callbacks assert // that the ordering was correct. @@ -290,15 +290,15 @@ class HTTPUpgradeTestCase: XCTestCase { let handler = HTTPServerUpgradeHandler(upgraders: [ExplodingUpgrader(forProtocol: "myproto", requiringHeaders: ["kafkaesque"])]) { _ in XCTFail("upgrade completed") } - let (group, server, client) = setUpTest(withHandlers: [handler]) + let (group, server, client) = try setUpTest(withHandlers: [handler]) defer { - try! client.close().wait() - try! server.close().wait() - try! group.syncShutdownGracefully() + XCTAssertNoThrow(try client.close().wait()) + XCTAssertNoThrow(try server.close().wait()) + XCTAssertNoThrow(try group.syncShutdownGracefully()) } let request = "OPTIONS * HTTP/1.1\r\nHost: localhost\r\nConnection: upgrade\r\nUpgrade: myproto\r\n\r\n" - try! client.writeAndFlush(data: NIOAny(ByteBuffer.forString(request))).wait() + XCTAssertNoThrow(try client.writeAndFlush(data: NIOAny(ByteBuffer.forString(request))).wait()) // At this time the channel pipeline should not contain our handler: it should have removed itself. try client.pipeline.assertDoesNotContain(handler: handler) @@ -308,15 +308,15 @@ class HTTPUpgradeTestCase: XCTestCase { let handler = HTTPServerUpgradeHandler(upgraders: [ExplodingUpgrader(forProtocol: "myproto", requiringHeaders: ["kafkaesque"])]) { _ in XCTFail("upgrade completed") } - let (group, server, client) = setUpTest(withHandlers: [handler]) + let (group, server, client) = try setUpTest(withHandlers: [handler]) defer { - try! client.close().wait() - try! server.close().wait() - try! group.syncShutdownGracefully() + XCTAssertNoThrow(try client.close().wait()) + XCTAssertNoThrow(try server.close().wait()) + XCTAssertNoThrow(try group.syncShutdownGracefully()) } let request = "OPTIONS * HTTP/1.1\r\nHost: localhost\r\nConnection: upgrade\r\nUpgrade: myproto\r\nKafkaesque: true\r\n\r\n" - try! client.writeAndFlush(data: NIOAny(ByteBuffer.forString(request))).wait() + XCTAssertNoThrow(try client.writeAndFlush(data: NIOAny(ByteBuffer.forString(request))).wait()) // At this time the channel pipeline should not contain our handler: it should have removed itself. try client.pipeline.assertDoesNotContain(handler: handler) @@ -326,15 +326,15 @@ class HTTPUpgradeTestCase: XCTestCase { let handler = HTTPServerUpgradeHandler(upgraders: [ExplodingUpgrader(forProtocol: "myproto")]) { _ in XCTFail("upgrade completed") } - let (group, server, client) = setUpTest(withHandlers: [handler]) + let (group, server, client) = try setUpTest(withHandlers: [handler]) defer { - try! client.close().wait() - try! server.close().wait() - try! group.syncShutdownGracefully() + XCTAssertNoThrow(try client.close().wait()) + XCTAssertNoThrow(try server.close().wait()) + XCTAssertNoThrow(try group.syncShutdownGracefully()) } let request = "OPTIONS * HTTP/1.1\r\nHost: localhost\r\nConnection: upgrade\r\nUpgrade: something-else\r\n\r\n" - try! client.writeAndFlush(data: NIOAny(ByteBuffer.forString(request))).wait() + XCTAssertNoThrow(try client.writeAndFlush(data: NIOAny(ByteBuffer.forString(request))).wait()) // At this time the channel pipeline should not contain our handler: it should have removed itself. try client.pipeline.assertDoesNotContain(handler: handler) @@ -360,9 +360,9 @@ class HTTPUpgradeTestCase: XCTestCase { ctx.close(promise: nil) } - let (group, server, client) = setUpTest(withHandlers: [handler]) + let (group, server, client) = try setUpTest(withHandlers: [handler]) defer { - try! group.syncShutdownGracefully() + XCTAssertNoThrow(try group.syncShutdownGracefully()) } let completePromise: EventLoopPromise = group.next().newPromise() @@ -373,14 +373,14 @@ class HTTPUpgradeTestCase: XCTestCase { expectedResponseHeaders: ["x-upgrade-complete: true", "upgrade: myproto", "connection: upgrade"]) completePromise.succeed(result: ()) } - try! client.pipeline.add(handler: clientHandler).wait() + XCTAssertNoThrow(try client.pipeline.add(handler: clientHandler).wait()) // This request is safe to upgrade. let request = "OPTIONS * HTTP/1.1\r\nHost: localhost\r\nUpgrade: myproto, exploder\r\nKafkaesque: yup\r\nConnection: upgrade, kafkaesque\r\n\r\n" - try! client.writeAndFlush(data: NIOAny(ByteBuffer.forString(request))).wait() + XCTAssertNoThrow(try client.writeAndFlush(data: NIOAny(ByteBuffer.forString(request))).wait()) // Let the machinery do its thing. - try! completePromise.futureResult.wait() + XCTAssertNoThrow(try completePromise.futureResult.wait()) // At this time we want to assert that everything got called. Their own callbacks assert // that the ordering was correct. @@ -404,9 +404,9 @@ class HTTPUpgradeTestCase: XCTestCase { ctx.close(promise: nil) } - let (group, server, client) = setUpTest(withHandlers: [handler, eventSaver]) + let (group, server, client) = try setUpTest(withHandlers: [handler, eventSaver]) defer { - try! group.syncShutdownGracefully() + XCTAssertNoThrow(try group.syncShutdownGracefully()) } let completePromise: EventLoopPromise = group.next().newPromise() @@ -417,18 +417,18 @@ class HTTPUpgradeTestCase: XCTestCase { expectedResponseHeaders: ["x-upgrade-complete: true", "upgrade: myproto", "connection: upgrade"]) completePromise.succeed(result: ()) } - try! client.pipeline.add(handler: clientHandler).wait() + XCTAssertNoThrow(try client.pipeline.add(handler: clientHandler).wait()) // This request is safe to upgrade. let request = "OPTIONS * HTTP/1.1\r\nHost: localhost\r\nUpgrade: myproto\r\nKafkaesque: yup\r\nConnection: upgrade,kafkaesque\r\n\r\n" - try! client.writeAndFlush(data: NIOAny(ByteBuffer.forString(request))).wait() + XCTAssertNoThrow(try client.writeAndFlush(data: NIOAny(ByteBuffer.forString(request))).wait()) // Let the machinery do its thing. - try! completePromise.futureResult.wait() + XCTAssertNoThrow(try completePromise.futureResult.wait()) // At this time we should have received one user event. We schedule this onto the // event loop to guarantee thread safety. - try! group.next().scheduleTask(in: .nanoseconds(0)) { + XCTAssertNoThrow(try group.next().scheduleTask(in: .nanoseconds(0)) { XCTAssertEqual(eventSaver.events.count, 1) if case .upgradeComplete(let proto, let req) = eventSaver.events[0] { XCTAssertEqual(proto, "myproto") @@ -438,7 +438,7 @@ class HTTPUpgradeTestCase: XCTestCase { } else { XCTFail("Unexpected event: \(eventSaver.events[0])") } - }.futureResult.wait() + }.futureResult.wait()) // We also want to confirm that the upgrade handler is no longer in the pipeline. try client.pipeline.assertDoesNotContain(handler: handler) @@ -465,9 +465,9 @@ class HTTPUpgradeTestCase: XCTestCase { } let errorCatcher = ErrorSaver() - let (group, server, client) = setUpTest(withHandlers: [handler, errorCatcher]) + let (group, server, client) = try setUpTest(withHandlers: [handler, errorCatcher]) defer { - try! group.syncShutdownGracefully() + XCTAssertNoThrow(try group.syncShutdownGracefully()) } let completePromise: EventLoopPromise = group.next().newPromise() @@ -478,14 +478,14 @@ class HTTPUpgradeTestCase: XCTestCase { expectedResponseHeaders: ["x-upgrade-complete: true", "upgrade: myproto", "connection: upgrade"]) completePromise.succeed(result: ()) } - try! client.pipeline.add(handler: clientHandler).wait() + XCTAssertNoThrow(try client.pipeline.add(handler: clientHandler).wait()) // This request is safe to upgrade. let request = "OPTIONS * HTTP/1.1\r\nHost: localhost\r\nUpgrade: noproto,myproto\r\nKafkaesque: yup\r\nConnection: upgrade, kafkaesque\r\n\r\n" - try! client.writeAndFlush(data: NIOAny(ByteBuffer.forString(request))).wait() + XCTAssertNoThrow(try client.writeAndFlush(data: NIOAny(ByteBuffer.forString(request))).wait()) // Let the machinery do its thing. - try! completePromise.futureResult.wait() + XCTAssertNoThrow(try completePromise.futureResult.wait()) // At this time we want to assert that everything got called. Their own callbacks assert // that the ordering was correct. diff --git a/Tests/NIOOpenSSLTests/OpenSSLALPNTest.swift b/Tests/NIOOpenSSLTests/OpenSSLALPNTest.swift index 359080ea1..5b684ed4a 100644 --- a/Tests/NIOOpenSSLTests/OpenSSLALPNTest.swift +++ b/Tests/NIOOpenSSLTests/OpenSSLALPNTest.swift @@ -42,7 +42,7 @@ class OpenSSLALPNTest: XCTestCase { clientContext: NIOOpenSSL.SSLContext) throws { let group = MultiThreadedEventLoopGroup(numThreads: 1) defer { - try! group.syncShutdownGracefully() + XCTAssertNoThrow(try group.syncShutdownGracefully()) } let completionPromise: EventLoopPromise = group.next().newPromise() @@ -52,7 +52,7 @@ class OpenSSLALPNTest: XCTestCase { andHandlers: [serverHandler, PromiseOnReadHandler(promise: completionPromise)], onGroup: group) defer { - _ = try! serverChannel.close().wait() + XCTAssertNoThrow(try serverChannel.close().wait()) } let clientChannel = try clientTLSChannel(withContext: clientContext, @@ -61,7 +61,7 @@ class OpenSSLALPNTest: XCTestCase { onGroup: group, connectingTo: serverChannel.localAddress!) defer { - _ = try! clientChannel.close().wait() + XCTAssertNoThrow(try clientChannel.close().wait()) } var originalBuffer = clientChannel.allocator.buffer(capacity: 5) diff --git a/Tests/NIOOpenSSLTests/OpenSSLIntegrationTest.swift b/Tests/NIOOpenSSLTests/OpenSSLIntegrationTest.swift index 68fce353c..32e2182e3 100644 --- a/Tests/NIOOpenSSLTests/OpenSSLIntegrationTest.swift +++ b/Tests/NIOOpenSSLTests/OpenSSLIntegrationTest.swift @@ -219,7 +219,7 @@ internal func serverTLSChannel(withContext: NIOOpenSSL.SSLContext, preHandlers: .childChannelInitializer { channel in let results = preHandlers.map { channel.pipeline.add(handler: $0) } return EventLoopFuture.andAll(results, eventLoop: results.first?.eventLoop ?? onGroup.next()).then { - return channel.pipeline.add(handler: try! OpenSSLServerHandler(context: withContext)).then(callback: { v2 in + return channel.pipeline.add(handler: try OpenSSLServerHandler(context: withContext)).then(callback: { v2 in let results = postHandlers.map { channel.pipeline.add(handler: $0) } return EventLoopFuture.andAll(results, eventLoop: results.first?.eventLoop ?? onGroup.next()) }) @@ -237,7 +237,7 @@ internal func clientTLSChannel(withContext: NIOOpenSSL.SSLContext, .channelInitializer { channel in let results = preHandlers.map { channel.pipeline.add(handler: $0) } return EventLoopFuture.andAll(results, eventLoop: results.first?.eventLoop ?? onGroup.next()).then(callback: { v2 in - return channel.pipeline.add(handler: try! OpenSSLClientHandler(context: withContext, serverHostname: serverHostname)).then(callback: { v2 in + return channel.pipeline.add(handler: try OpenSSLClientHandler(context: withContext, serverHostname: serverHostname)).then(callback: { v2 in let results = postHandlers.map { channel.pipeline.add(handler: $0) } return EventLoopFuture.andAll(results, eventLoop: results.first?.eventLoop ?? onGroup.next()) }) @@ -289,14 +289,14 @@ class OpenSSLIntegrationTest: XCTestCase { let group = MultiThreadedEventLoopGroup(numThreads: 1) defer { - try! group.syncShutdownGracefully() + XCTAssertNoThrow(try group.syncShutdownGracefully()) } let completionPromise: EventLoopPromise = group.next().newPromise() let serverChannel = try serverTLSChannel(withContext: ctx, andHandlers: [SimpleEchoServer()], onGroup: group) defer { - _ = try! serverChannel.close().wait() + XCTAssertNoThrow(try serverChannel.close().wait()) } let clientChannel = try clientTLSChannel(withContext: ctx, @@ -305,7 +305,7 @@ class OpenSSLIntegrationTest: XCTestCase { onGroup: group, connectingTo: serverChannel.localAddress!) defer { - _ = try! clientChannel.close().wait() + XCTAssertNoThrow(try clientChannel.close().wait()) } var originalBuffer = clientChannel.allocator.buffer(capacity: 5) @@ -321,7 +321,7 @@ class OpenSSLIntegrationTest: XCTestCase { let group = MultiThreadedEventLoopGroup(numThreads: 1) defer { - try! group.syncShutdownGracefully() + XCTAssertNoThrow(try group.syncShutdownGracefully()) } let readComplete: EventLoopPromise = group.next().newPromise() @@ -330,7 +330,7 @@ class OpenSSLIntegrationTest: XCTestCase { andHandlers: [serverHandler, PromiseOnReadHandler(promise: readComplete)], onGroup: group) defer { - _ = try! serverChannel.close().wait() + XCTAssertNoThrow(try serverChannel.close().wait()) } let clientChannel = try clientTLSChannel(withContext: ctx, @@ -339,7 +339,7 @@ class OpenSSLIntegrationTest: XCTestCase { onGroup: group, connectingTo: serverChannel.localAddress!) defer { - _ = try! clientChannel.close().wait() + XCTAssertNoThrow(try clientChannel.close().wait()) } var originalBuffer = clientChannel.allocator.buffer(capacity: 5) @@ -368,7 +368,7 @@ class OpenSSLIntegrationTest: XCTestCase { let group = MultiThreadedEventLoopGroup(numThreads: 1) defer { - try! group.syncShutdownGracefully() + XCTAssertNoThrow(try group.syncShutdownGracefully()) } let readComplete: EventLoopPromise = group.next().newPromise() @@ -414,7 +414,7 @@ class OpenSSLIntegrationTest: XCTestCase { let group = MultiThreadedEventLoopGroup(numThreads: 1) defer { - try! group.syncShutdownGracefully() + XCTAssertNoThrow(try group.syncShutdownGracefully()) } let completionPromise: EventLoopPromise = group.next().newPromise() @@ -422,7 +422,7 @@ class OpenSSLIntegrationTest: XCTestCase { let serverChannel = try serverTLSChannel(withContext: ctx, andHandlers: [SimpleEchoServer()], onGroup: group) defer { if !serverClosed { - _ = try! serverChannel.close().wait() + XCTAssertNoThrow(try serverChannel.close().wait()) } } @@ -432,7 +432,7 @@ class OpenSSLIntegrationTest: XCTestCase { onGroup: group, connectingTo: serverChannel.localAddress!) defer { - _ = try! clientChannel.close().wait() + XCTAssertNoThrow(try clientChannel.close().wait()) } var originalBuffer = clientChannel.allocator.buffer(capacity: 5) @@ -456,7 +456,7 @@ class OpenSSLIntegrationTest: XCTestCase { } } - _ = try! promises.first!.futureResult.wait() + XCTAssertNoThrow(try promises.first!.futureResult.wait()) serverClosed = true for promise in promises { @@ -469,13 +469,13 @@ class OpenSSLIntegrationTest: XCTestCase { let group = MultiThreadedEventLoopGroup(numThreads: 1) defer { - try! group.syncShutdownGracefully() + XCTAssertNoThrow(try group.syncShutdownGracefully()) } let recorderHandler = EventRecorderHandler() let serverChannel = try serverTLSChannel(withContext: ctx, andHandlers: [SimpleEchoServer()], onGroup: group) defer { - _ = try! serverChannel.close().wait() + XCTAssertNoThrow(try serverChannel.close().wait()) } let writeCounter = WriteCountingHandler() @@ -486,7 +486,7 @@ class OpenSSLIntegrationTest: XCTestCase { onGroup: group, connectingTo: serverChannel.localAddress!) defer { - _ = try! clientChannel.close().wait() + XCTAssertNoThrow(try clientChannel.close().wait()) } // We're going to issue a number of small writes. Each of these should be coalesced together @@ -514,13 +514,13 @@ class OpenSSLIntegrationTest: XCTestCase { let group = MultiThreadedEventLoopGroup(numThreads: 1) defer { - try! group.syncShutdownGracefully() + XCTAssertNoThrow(try group.syncShutdownGracefully()) } let recorderHandler = EventRecorderHandler() let serverChannel = try serverTLSChannel(withContext: ctx, andHandlers: [SimpleEchoServer()], onGroup: group) defer { - _ = try! serverChannel.close().wait() + XCTAssertNoThrow(try serverChannel.close().wait()) } let clientChannel = try clientTLSChannel(withContext: ctx, @@ -529,7 +529,7 @@ class OpenSSLIntegrationTest: XCTestCase { onGroup: group, connectingTo: serverChannel.localAddress!) defer { - _ = try! clientChannel.close().wait() + XCTAssertNoThrow(try clientChannel.close().wait()) } // We're going to issue a number of small writes. Each of these should be coalesced together @@ -585,7 +585,7 @@ class OpenSSLIntegrationTest: XCTestCase { let ctx = try configuredSSLContext() let group = MultiThreadedEventLoopGroup(numThreads: 1) defer { - try! group.syncShutdownGracefully() + XCTAssertNoThrow(try group.syncShutdownGracefully()) } let recorderHandler: EventRecorderHandler = EventRecorderHandler() @@ -594,7 +594,7 @@ class OpenSSLIntegrationTest: XCTestCase { andHandlers: [recorderHandler, SimpleEchoServer(), channelActiveWaiter], onGroup: group) defer { - _ = try! serverChannel.close().wait() + XCTAssertNoThrow(try serverChannel.close().wait()) } // Create a client channel without TLS in it, and connect it. @@ -604,7 +604,7 @@ class OpenSSLIntegrationTest: XCTestCase { .channelInitializer({ $0.pipeline.add(handler: promiseOnReadHandler) }) .connect(to: serverChannel.localAddress!).wait() defer { - _ = try! clientChannel.close().wait() + XCTAssertNoThrow(try clientChannel.close().wait()) } // Wait until the channel comes up, then confirm that no handshake has been @@ -642,7 +642,7 @@ class OpenSSLIntegrationTest: XCTestCase { andHandlers: [], onGroup: group) defer { - _ = try! serverChannel.close().wait() + XCTAssertNoThrow(try serverChannel.close().wait()) } let errorHandler = ErrorCatcher() @@ -677,14 +677,14 @@ class OpenSSLIntegrationTest: XCTestCase { let group = MultiThreadedEventLoopGroup(numThreads: 1) defer { - try! group.syncShutdownGracefully() + XCTAssertNoThrow(try group.syncShutdownGracefully()) } let serverChannel = try serverTLSChannel(withContext: serverCtx, andHandlers: [], onGroup: group) defer { - _ = try! serverChannel.close().wait() + XCTAssertNoThrow(try serverChannel.close().wait()) } let eventHandler = EventRecorderHandler() @@ -754,7 +754,7 @@ class OpenSSLIntegrationTest: XCTestCase { let group = MultiThreadedEventLoopGroup(numThreads: 1) defer { - try! group.syncShutdownGracefully() + XCTAssertNoThrow(try group.syncShutdownGracefully()) } let completionPromise: EventLoopPromise = group.next().newPromise() @@ -790,14 +790,14 @@ class OpenSSLIntegrationTest: XCTestCase { let group = MultiThreadedEventLoopGroup(numThreads: 1) defer { - try! group.syncShutdownGracefully() + XCTAssertNoThrow(try group.syncShutdownGracefully()) } let serverChannel = try serverTLSChannel(withContext: serverCtx, andHandlers: [], onGroup: group) defer { - _ = try! serverChannel.close().wait() + XCTAssertNoThrow(try serverChannel.close().wait()) } let errorHandler = ErrorCatcher() diff --git a/Tests/NIOOpenSSLTests/TLSConfigurationTest.swift b/Tests/NIOOpenSSLTests/TLSConfigurationTest.swift index 882f6d37e..0217ee780 100644 --- a/Tests/NIOOpenSSLTests/TLSConfigurationTest.swift +++ b/Tests/NIOOpenSSLTests/TLSConfigurationTest.swift @@ -65,7 +65,7 @@ class TLSConfigurationTest: XCTestCase { let group = MultiThreadedEventLoopGroup(numThreads: 1) defer { - try! group.syncShutdownGracefully() + XCTAssertNoThrow(try group.syncShutdownGracefully()) } let eventHandler = ErrorCatcher() @@ -141,7 +141,7 @@ class TLSConfigurationTest: XCTestCase { let group = MultiThreadedEventLoopGroup(numThreads: 1) defer { - try! group.syncShutdownGracefully() + XCTAssertNoThrow(try group.syncShutdownGracefully()) } let eventHandler = EventRecorderHandler() diff --git a/Tests/NIOTests/ChannelTests.swift b/Tests/NIOTests/ChannelTests.swift index 35fb0b0cc..c4ab42288 100644 --- a/Tests/NIOTests/ChannelTests.swift +++ b/Tests/NIOTests/ChannelTests.swift @@ -70,7 +70,7 @@ public class ChannelTests: XCTestCase { func testBasicLifecycle() throws { let group = MultiThreadedEventLoopGroup(numThreads: 1) defer { - try! group.syncShutdownGracefully() + XCTAssertNoThrow(try group.syncShutdownGracefully()) } var serverAcceptedChannel: Channel? = nil @@ -106,7 +106,7 @@ public class ChannelTests: XCTestCase { func testManyManyWrites() throws { let group = MultiThreadedEventLoopGroup(numThreads: 1) defer { - try! group.syncShutdownGracefully() + XCTAssertNoThrow(try group.syncShutdownGracefully()) } let serverChannel = try ServerBootstrap(group: group) @@ -132,7 +132,7 @@ public class ChannelTests: XCTestCase { func testWritevLotsOfData() throws { let group = MultiThreadedEventLoopGroup(numThreads: 1) defer { - try! group.syncShutdownGracefully() + XCTAssertNoThrow(try group.syncShutdownGracefully()) } let serverChannel = try ServerBootstrap(group: group) @@ -167,7 +167,7 @@ public class ChannelTests: XCTestCase { func testParentsOfSocketChannels() throws { let group = MultiThreadedEventLoopGroup(numThreads: 1) defer { - try! group.syncShutdownGracefully() + XCTAssertNoThrow(try group.syncShutdownGracefully()) } let childChannelPromise: EventLoopPromise = group.next().newPromise() @@ -250,12 +250,12 @@ public class ChannelTests: XCTestCase { returns: [IOResult], promiseStates: [[Bool]], file: StaticString = #file, - line: UInt = #line) -> WriteResult { + line: UInt = #line) throws -> WriteResult { var everythingState = 0 var singleState = 0 var multiState = 0 var fileState = 0 - let (result, _) = try! pwm.triggerAppropriateWriteOperation(singleWriteOperation: { buf in + let (result, _) = try pwm.triggerAppropriateWriteOperation(singleWriteOperation: { buf in defer { singleState += 1 everythingState += 1 @@ -359,12 +359,12 @@ public class ChannelTests: XCTestCase { } /// Tests that writes of empty buffers work correctly and that we don't accidentally write buffers that haven't been flushed. - func testPendingWritesEmptyWritesWorkAndWeDontWriteUnflushedThings() { + func testPendingWritesEmptyWritesWorkAndWeDontWriteUnflushedThings() throws { let el = EmbeddedEventLoop() let alloc = ByteBufferAllocator() var buffer = alloc.buffer(capacity: 12) - withPendingWritesManager { pwm in + try withPendingWritesManager { pwm in buffer.clear() let ps: [EventLoopPromise<()>] = (0..<2).map { _ in el.newPromise() } _ = pwm.add(data: .byteBuffer(buffer), promise: ps[0]) @@ -379,7 +379,7 @@ public class ChannelTests: XCTestCase { _ = pwm.add(data: .byteBuffer(buffer), promise: ps[1]) - var result = assertExpectedWritability(pendingWritesManager: pwm, + var result = try assertExpectedWritability(pendingWritesManager: pwm, promises: ps, expectedSingleWritabilities: [0], expectedVectorWritabilities: nil, @@ -391,7 +391,7 @@ public class ChannelTests: XCTestCase { XCTAssertFalse(pwm.isFlushPending) XCTAssertEqual(.writtenCompletely, result) - result = assertExpectedWritability(pendingWritesManager: pwm, + result = try assertExpectedWritability(pendingWritesManager: pwm, promises: ps, expectedSingleWritabilities: nil, expectedVectorWritabilities: nil, @@ -402,7 +402,7 @@ public class ChannelTests: XCTestCase { pwm.markFlushCheckpoint(promise: nil) - result = assertExpectedWritability(pendingWritesManager: pwm, + result = try assertExpectedWritability(pendingWritesManager: pwm, promises: ps, expectedSingleWritabilities: [0], expectedVectorWritabilities: nil, @@ -414,21 +414,21 @@ public class ChannelTests: XCTestCase { } /// This tests that we do use the vector write operation if we have more than one flushed and still doesn't write unflushed buffers - func testPendingWritesUsesVectorWriteOperationAndDoesntWriteTooMuch() { + func testPendingWritesUsesVectorWriteOperationAndDoesntWriteTooMuch() throws { let el = EmbeddedEventLoop() let alloc = ByteBufferAllocator() var buffer = alloc.buffer(capacity: 12) let emptyBuffer = buffer _ = buffer.write(string: "1234") - withPendingWritesManager { pwm in + try withPendingWritesManager { pwm in let ps: [EventLoopPromise<()>] = (0..<3).map { _ in el.newPromise() } _ = pwm.add(data: .byteBuffer(buffer), promise: ps[0]) _ = pwm.add(data: .byteBuffer(buffer), promise: ps[1]) pwm.markFlushCheckpoint(promise: nil) _ = pwm.add(data: .byteBuffer(emptyBuffer), promise: ps[2]) - var result = assertExpectedWritability(pendingWritesManager: pwm, + var result = try assertExpectedWritability(pendingWritesManager: pwm, promises: ps, expectedSingleWritabilities: nil, expectedVectorWritabilities: [[4, 4]], @@ -439,7 +439,7 @@ public class ChannelTests: XCTestCase { pwm.markFlushCheckpoint(promise: nil) - result = assertExpectedWritability(pendingWritesManager: pwm, + result = try assertExpectedWritability(pendingWritesManager: pwm, promises: ps, expectedSingleWritabilities: [0], expectedVectorWritabilities: nil, @@ -451,13 +451,13 @@ public class ChannelTests: XCTestCase { } /// Tests that we can handle partial writes correctly. - func testPendingWritesWorkWithPartialWrites() { + func testPendingWritesWorkWithPartialWrites() throws { let el = EmbeddedEventLoop() let alloc = ByteBufferAllocator() var buffer = alloc.buffer(capacity: 12) _ = buffer.write(string: "1234") - withPendingWritesManager { pwm in + try withPendingWritesManager { pwm in let ps: [EventLoopPromise<()>] = (0..<4).map { _ in el.newPromise() } _ = pwm.add(data: .byteBuffer(buffer), promise: ps[0]) _ = pwm.add(data: .byteBuffer(buffer), promise: ps[1]) @@ -465,7 +465,7 @@ public class ChannelTests: XCTestCase { _ = pwm.add(data: .byteBuffer(buffer), promise: ps[3]) pwm.markFlushCheckpoint(promise: nil) - var result = assertExpectedWritability(pendingWritesManager: pwm, + var result = try assertExpectedWritability(pendingWritesManager: pwm, promises: ps, expectedSingleWritabilities: nil, expectedVectorWritabilities: [[4, 4, 4, 4], [3, 4, 4, 4]], @@ -474,7 +474,7 @@ public class ChannelTests: XCTestCase { promiseStates: [[false, false, false, false], [false, false, false, false]]) XCTAssertEqual(WriteResult.wouldBlock, result) - result = assertExpectedWritability(pendingWritesManager: pwm, + result = try assertExpectedWritability(pendingWritesManager: pwm, promises: ps, expectedSingleWritabilities: nil, expectedVectorWritabilities: [[3, 4, 4, 4], [4, 4]], @@ -485,7 +485,7 @@ public class ChannelTests: XCTestCase { ) XCTAssertEqual(WriteResult.wouldBlock, result) - result = assertExpectedWritability(pendingWritesManager: pwm, + result = try assertExpectedWritability(pendingWritesManager: pwm, promises: ps, expectedSingleWritabilities: nil, expectedVectorWritabilities: [[4, 4]], @@ -497,12 +497,12 @@ public class ChannelTests: XCTestCase { } /// Tests that the spin count works for one long buffer if small bits are written one by one. - func testPendingWritesSpinCountWorksForSingleWrites() { + func testPendingWritesSpinCountWorksForSingleWrites() throws { let el = EmbeddedEventLoop() let alloc = ByteBufferAllocator() var buffer = alloc.buffer(capacity: 12) - withPendingWritesManager { pwm in + try withPendingWritesManager { pwm in let numberOfBytes = Int(pwm.writeSpinCount + 1 /* so one byte remains at the end */) buffer.clear() buffer.write(bytes: Array(repeating: 0xff, count: numberOfBytes)) @@ -513,7 +513,7 @@ public class ChannelTests: XCTestCase { /* below, we'll write 1 byte at a time. So the number of bytes offered should decrease by one. The write operation should be repeated until we did it 1 + spin count times and then return `.writtenPartially`. After that, one byte will remain */ - var result = assertExpectedWritability(pendingWritesManager: pwm, + var result = try assertExpectedWritability(pendingWritesManager: pwm, promises: ps, expectedSingleWritabilities: Array((2...numberOfBytes).reversed()), expectedVectorWritabilities: nil, @@ -523,7 +523,7 @@ public class ChannelTests: XCTestCase { XCTAssertEqual(.writtenPartially, result) /* we'll now write the one last byte and assert that all the writes are complete */ - result = assertExpectedWritability(pendingWritesManager: pwm, + result = try assertExpectedWritability(pendingWritesManager: pwm, promises: ps, expectedSingleWritabilities: [1], expectedVectorWritabilities: nil, @@ -535,12 +535,12 @@ public class ChannelTests: XCTestCase { } /// Tests that the spin count works if we have many small buffers, which'll be written with the vector write op. - func testPendingWritesSpinCountWorksForVectorWrites() { + func testPendingWritesSpinCountWorksForVectorWrites() throws { let el = EmbeddedEventLoop() let alloc = ByteBufferAllocator() var buffer = alloc.buffer(capacity: 12) - withPendingWritesManager { pwm in + try withPendingWritesManager { pwm in let numberOfBytes = Int(pwm.writeSpinCount + 1 /* so one byte remains at the end */) buffer.clear() buffer.write(bytes: [0xff] as [UInt8]) @@ -568,7 +568,7 @@ public class ChannelTests: XCTestCase { /* below, we'll write 1 byte at a time. So the number of bytes offered should decrease by one. The write operation should be repeated until we did it 1 + spin count times and then return `.writtenPartially`. After that, one byte will remain */ - var result = assertExpectedWritability(pendingWritesManager: pwm, + var result = try assertExpectedWritability(pendingWritesManager: pwm, promises: ps, expectedSingleWritabilities: nil, expectedVectorWritabilities: expectedVectorWrites, @@ -578,7 +578,7 @@ public class ChannelTests: XCTestCase { XCTAssertEqual(.writtenPartially, result) /* we'll now write the one last byte and assert that all the writes are complete */ - result = assertExpectedWritability(pendingWritesManager: pwm, + result = try assertExpectedWritability(pendingWritesManager: pwm, promises: ps, expectedSingleWritabilities: [1], expectedVectorWritabilities: nil, @@ -590,21 +590,21 @@ public class ChannelTests: XCTestCase { } /// Test that cancellation of the Channel writes works correctly. - func testPendingWritesCancellationWorksCorrectly() { + func testPendingWritesCancellationWorksCorrectly() throws { let el = EmbeddedEventLoop() let alloc = ByteBufferAllocator() var buffer = alloc.buffer(capacity: 12) let emptyBuffer = buffer _ = buffer.write(string: "1234") - withPendingWritesManager { pwm in + try withPendingWritesManager { pwm in let ps: [EventLoopPromise<()>] = (0..<3).map { _ in el.newPromise() } _ = pwm.add(data: .byteBuffer(buffer), promise: ps[0]) _ = pwm.add(data: .byteBuffer(buffer), promise: ps[1]) pwm.markFlushCheckpoint(promise: nil) _ = pwm.add(data: .byteBuffer(emptyBuffer), promise: ps[2]) - let result = assertExpectedWritability(pendingWritesManager: pwm, + let result = try assertExpectedWritability(pendingWritesManager: pwm, promises: ps, expectedSingleWritabilities: nil, expectedVectorWritabilities: [[4, 4], [2, 4]], @@ -620,7 +620,7 @@ public class ChannelTests: XCTestCase { } /// Test that with a few massive buffers, we don't offer more than we should to `writev` if the individual chunks fit. - func testPendingWritesNoMoreThanWritevLimitIsWritten() { + func testPendingWritesNoMoreThanWritevLimitIsWritten() throws { let el = EmbeddedEventLoop() let alloc = ByteBufferAllocator(hookedMalloc: { _ in return UnsafeMutableRawPointer(bitPattern: 0xdeadbeef)! }, hookedRealloc: { _, _ in return UnsafeMutableRawPointer(bitPattern: 0xdeadbeef)! }, @@ -632,7 +632,7 @@ public class ChannelTests: XCTestCase { buffer.moveReaderIndex(to: 0) buffer.moveWriterIndex(to: halfTheWriteVLimit) - withPendingWritesManager { pwm in + try withPendingWritesManager { pwm in let ps: [EventLoopPromise<()>] = (0..<3).map { _ in el.newPromise() } /* add 1.5x the writev limit */ _ = pwm.add(data: .byteBuffer(buffer), promise: ps[0]) @@ -640,7 +640,7 @@ public class ChannelTests: XCTestCase { _ = pwm.add(data: .byteBuffer(buffer), promise: ps[2]) pwm.markFlushCheckpoint(promise: nil) - let result = assertExpectedWritability(pendingWritesManager: pwm, + let result = try assertExpectedWritability(pendingWritesManager: pwm, promises: ps, expectedSingleWritabilities: nil, expectedVectorWritabilities: [[halfTheWriteVLimit, halfTheWriteVLimit], [halfTheWriteVLimit]], @@ -652,7 +652,7 @@ public class ChannelTests: XCTestCase { } /// Test that with a massive buffers (bigger than writev size), we don't offer more than we should to `writev`. - func testPendingWritesNoMoreThanWritevLimitIsWrittenInOneMassiveChunk() { + func testPendingWritesNoMoreThanWritevLimitIsWrittenInOneMassiveChunk() throws { let el = EmbeddedEventLoop() let alloc = ByteBufferAllocator(hookedMalloc: { _ in return UnsafeMutableRawPointer(bitPattern: 0xdeadbeef)! }, hookedRealloc: { _, _ in return UnsafeMutableRawPointer(bitPattern: 0xdeadbeef)! }, @@ -664,7 +664,7 @@ public class ChannelTests: XCTestCase { buffer.moveReaderIndex(to: 0) buffer.moveWriterIndex(to: biggerThanWriteV) - withPendingWritesManager { pwm in + try withPendingWritesManager { pwm in let ps: [EventLoopPromise<()>] = (0..<3).map { _ in el.newPromise() } /* add 1.5x the writev limit */ _ = pwm.add(data: .byteBuffer(buffer), promise: ps[0]) @@ -675,7 +675,7 @@ public class ChannelTests: XCTestCase { let flushPromise1: EventLoopPromise<()> = el.newPromise() pwm.markFlushCheckpoint(promise: flushPromise1) - let result = assertExpectedWritability(pendingWritesManager: pwm, + let result = try assertExpectedWritability(pendingWritesManager: pwm, promises: ps, expectedSingleWritabilities: nil, expectedVectorWritabilities: [[Socket.writevLimitBytes], @@ -699,16 +699,16 @@ public class ChannelTests: XCTestCase { } } - func testPendingWritesFileRegion() { + func testPendingWritesFileRegion() throws { let el = EmbeddedEventLoop() - withPendingWritesManager { pwm in + try withPendingWritesManager { pwm in let ps: [EventLoopPromise<()>] = (0..<2).map { _ in el.newPromise() } _ = pwm.add(data: .fileRegion(FileRegion(descriptor: -1, readerIndex: 12, endIndex: 14)), promise: ps[0]) pwm.markFlushCheckpoint(promise: nil) _ = pwm.add(data: .fileRegion(FileRegion(descriptor: -2, readerIndex: 0, endIndex: 2)), promise: ps[1]) - var result = assertExpectedWritability(pendingWritesManager: pwm, + var result = try assertExpectedWritability(pendingWritesManager: pwm, promises: ps, expectedSingleWritabilities: nil, expectedVectorWritabilities: nil, @@ -717,7 +717,7 @@ public class ChannelTests: XCTestCase { promiseStates: [[true, false]]) XCTAssertEqual(.writtenCompletely, result) - result = assertExpectedWritability(pendingWritesManager: pwm, + result = try assertExpectedWritability(pendingWritesManager: pwm, promises: ps, expectedSingleWritabilities: nil, expectedVectorWritabilities: nil, @@ -728,7 +728,7 @@ public class ChannelTests: XCTestCase { pwm.markFlushCheckpoint(promise: nil) - result = assertExpectedWritability(pendingWritesManager: pwm, + result = try assertExpectedWritability(pendingWritesManager: pwm, promises: ps, expectedSingleWritabilities: nil, expectedVectorWritabilities: nil, @@ -739,15 +739,15 @@ public class ChannelTests: XCTestCase { } } - func testPendingWritesEmptyFileRegion() { + func testPendingWritesEmptyFileRegion() throws { let el = EmbeddedEventLoop() - withPendingWritesManager { pwm in + try withPendingWritesManager { pwm in let ps: [EventLoopPromise<()>] = (0..<1).map { _ in el.newPromise() } _ = pwm.add(data: .fileRegion(FileRegion(descriptor: -1, readerIndex: 99, endIndex: 99)), promise: ps[0]) pwm.markFlushCheckpoint(promise: nil) - let result = assertExpectedWritability(pendingWritesManager: pwm, + let result = try assertExpectedWritability(pendingWritesManager: pwm, promises: ps, expectedSingleWritabilities: nil, expectedVectorWritabilities: nil, @@ -758,13 +758,13 @@ public class ChannelTests: XCTestCase { } } - func testPendingWritesInterleavedBuffersAndFiles() { + func testPendingWritesInterleavedBuffersAndFiles() throws { let el = EmbeddedEventLoop() let alloc = ByteBufferAllocator() var buffer = alloc.buffer(capacity: 12) _ = buffer.write(string: "1234") - withPendingWritesManager { pwm in + try withPendingWritesManager { pwm in let ps: [EventLoopPromise<()>] = (0..<5).map { _ in el.newPromise() } _ = pwm.add(data: .byteBuffer(buffer), promise: ps[0]) @@ -775,7 +775,7 @@ public class ChannelTests: XCTestCase { pwm.markFlushCheckpoint(promise: nil) - var result = assertExpectedWritability(pendingWritesManager: pwm, + var result = try assertExpectedWritability(pendingWritesManager: pwm, promises: ps, expectedSingleWritabilities: nil, expectedVectorWritabilities: [[4, 4]], @@ -784,7 +784,7 @@ public class ChannelTests: XCTestCase { promiseStates: [[true, true, false, false, false]]) XCTAssertEqual(.writtenCompletely, result) - result = assertExpectedWritability(pendingWritesManager: pwm, + result = try assertExpectedWritability(pendingWritesManager: pwm, promises: ps, expectedSingleWritabilities: nil, expectedVectorWritabilities: nil, @@ -793,7 +793,7 @@ public class ChannelTests: XCTestCase { promiseStates: [[true, true, true, false, false]]) XCTAssertEqual(.writtenCompletely, result) - result = assertExpectedWritability(pendingWritesManager: pwm, + result = try assertExpectedWritability(pendingWritesManager: pwm, promises: ps, expectedSingleWritabilities: [4, 3, 2, 1], expectedVectorWritabilities: nil, @@ -805,7 +805,7 @@ public class ChannelTests: XCTestCase { [true, true, true, true, false]]) XCTAssertEqual(.writtenCompletely, result) - result = assertExpectedWritability(pendingWritesManager: pwm, + result = try assertExpectedWritability(pendingWritesManager: pwm, promises: ps, expectedSingleWritabilities: nil, expectedVectorWritabilities: nil, @@ -816,7 +816,7 @@ public class ChannelTests: XCTestCase { [true, true, true, true, false]]) XCTAssertEqual(.wouldBlock, result) - result = assertExpectedWritability(pendingWritesManager: pwm, + result = try assertExpectedWritability(pendingWritesManager: pwm, promises: ps, expectedSingleWritabilities: nil, expectedVectorWritabilities: nil, @@ -833,13 +833,13 @@ public class ChannelTests: XCTestCase { var buffer = alloc.buffer(capacity: 12) _ = buffer.write(string: "1234") - withPendingWritesManager { pwm in + try withPendingWritesManager { pwm in let ps: [EventLoopPromise<()>] = (0..<2).map { _ in el.newPromise() } pwm.markFlushCheckpoint(promise: ps[0]) /* let's start with no writes and just a promise */ - var result = assertExpectedWritability(pendingWritesManager: pwm, + var result = try assertExpectedWritability(pendingWritesManager: pwm, promises: ps, expectedSingleWritabilities: nil, expectedVectorWritabilities: nil, @@ -856,7 +856,7 @@ public class ChannelTests: XCTestCase { pwm.markFlushCheckpoint(promise: ps[1]) - result = assertExpectedWritability(pendingWritesManager: pwm, + result = try assertExpectedWritability(pendingWritesManager: pwm, promises: ps, expectedSingleWritabilities: nil, expectedVectorWritabilities: [[4, 4]], @@ -864,7 +864,7 @@ public class ChannelTests: XCTestCase { returns: [.processed(8)], promiseStates: [[true, false]]) XCTAssertEqual(WriteResult.writtenCompletely, result) - result = assertExpectedWritability(pendingWritesManager: pwm, + result = try assertExpectedWritability(pendingWritesManager: pwm, promises: ps, expectedSingleWritabilities: nil, expectedVectorWritabilities: nil, @@ -872,7 +872,7 @@ public class ChannelTests: XCTestCase { returns: [.processed(0)], promiseStates: [[true, false]]) XCTAssertEqual(WriteResult.writtenCompletely, result) - result = assertExpectedWritability(pendingWritesManager: pwm, + result = try assertExpectedWritability(pendingWritesManager: pwm, promises: ps, expectedSingleWritabilities: [4], expectedVectorWritabilities: nil, @@ -880,7 +880,7 @@ public class ChannelTests: XCTestCase { returns: [.processed(4)], promiseStates: [[true, false]]) XCTAssertEqual(WriteResult.writtenCompletely, result) - result = assertExpectedWritability(pendingWritesManager: pwm, + result = try assertExpectedWritability(pendingWritesManager: pwm, promises: ps, expectedSingleWritabilities: nil, expectedVectorWritabilities: nil, @@ -891,19 +891,19 @@ public class ChannelTests: XCTestCase { } } - func testPendingWritesWorksWithManyEmptyWrites() { + func testPendingWritesWorksWithManyEmptyWrites() throws { let el = EmbeddedEventLoop() let alloc = ByteBufferAllocator() let emptyBuffer = alloc.buffer(capacity: 12) - withPendingWritesManager { pwm in + try withPendingWritesManager { pwm in let ps: [EventLoopPromise<()>] = (0..<3).map { _ in el.newPromise() } _ = pwm.add(data: .byteBuffer(emptyBuffer), promise: ps[0]) _ = pwm.add(data: .byteBuffer(emptyBuffer), promise: ps[1]) pwm.markFlushCheckpoint(promise: nil) _ = pwm.add(data: .byteBuffer(emptyBuffer), promise: ps[2]) - var result = assertExpectedWritability(pendingWritesManager: pwm, + var result = try assertExpectedWritability(pendingWritesManager: pwm, promises: ps, expectedSingleWritabilities: nil, expectedVectorWritabilities: [[0, 0]], @@ -914,7 +914,7 @@ public class ChannelTests: XCTestCase { pwm.markFlushCheckpoint(promise: nil) - result = assertExpectedWritability(pendingWritesManager: pwm, + result = try assertExpectedWritability(pendingWritesManager: pwm, promises: ps, expectedSingleWritabilities: [0], expectedVectorWritabilities: nil, @@ -942,7 +942,7 @@ public class ChannelTests: XCTestCase { pwm.failAll(error: ChannelError.eof) } - let result = assertExpectedWritability(pendingWritesManager: pwm, + let result = try assertExpectedWritability(pendingWritesManager: pwm, promises: ps, expectedSingleWritabilities: nil, expectedVectorWritabilities: [[4, 4]], @@ -962,7 +962,7 @@ public class ChannelTests: XCTestCase { var buffer = alloc.buffer(capacity: 12) buffer.write(string: "1234") - withPendingWritesManager { pwm in + try withPendingWritesManager { pwm in let ps: [EventLoopPromise<()>] = (0...Socket.writevLimitIOVectors).map { _ in el.newPromise() } ps.forEach { p in _ = pwm.add(data: .byteBuffer(buffer), promise: p) @@ -970,7 +970,7 @@ public class ChannelTests: XCTestCase { let flushPromise: EventLoopPromise<()> = el.newPromise() pwm.markFlushCheckpoint(promise: flushPromise) - var result = assertExpectedWritability(pendingWritesManager: pwm, + var result = try assertExpectedWritability(pendingWritesManager: pwm, promises: ps, expectedSingleWritabilities: nil, expectedVectorWritabilities: [Array(repeating: 4, count: Socket.writevLimitIOVectors), [4]], @@ -980,7 +980,7 @@ public class ChannelTests: XCTestCase { Array(repeating: true, count: Socket.writevLimitIOVectors) + [false]]) XCTAssertEqual(WriteResult.wouldBlock, result) XCTAssertFalse(flushPromise.futureResult.fulfilled) - result = assertExpectedWritability(pendingWritesManager: pwm, + result = try assertExpectedWritability(pendingWritesManager: pwm, promises: ps, expectedSingleWritabilities: [4], expectedVectorWritabilities: nil, @@ -992,15 +992,15 @@ public class ChannelTests: XCTestCase { } } - func testPendingWritesIsHappyWhenSendfileReturnsWouldBlockButWroteFully() { + func testPendingWritesIsHappyWhenSendfileReturnsWouldBlockButWroteFully() throws { let el = EmbeddedEventLoop() - withPendingWritesManager { pwm in + try withPendingWritesManager { pwm in let ps: [EventLoopPromise<()>] = (0..<1).map { _ in el.newPromise() } _ = pwm.add(data: .fileRegion(FileRegion(descriptor: -1, readerIndex: 0, endIndex: 8192)), promise: ps[0]) pwm.markFlushCheckpoint(promise: nil) - let result = assertExpectedWritability(pendingWritesManager: pwm, + let result = try assertExpectedWritability(pendingWritesManager: pwm, promises: ps, expectedSingleWritabilities: nil, expectedVectorWritabilities: nil, @@ -1014,7 +1014,7 @@ public class ChannelTests: XCTestCase { func testConnectTimeout() throws { let group = MultiThreadedEventLoopGroup(numThreads: 1) defer { - try! group.syncShutdownGracefully() + XCTAssertNoThrow(try group.syncShutdownGracefully()) } do { diff --git a/Tests/NIOTests/EchoServerClientTest.swift b/Tests/NIOTests/EchoServerClientTest.swift index cf1ec15f7..53503252f 100644 --- a/Tests/NIOTests/EchoServerClientTest.swift +++ b/Tests/NIOTests/EchoServerClientTest.swift @@ -37,7 +37,7 @@ class EchoServerClientTest : XCTestCase { func testEcho() throws { let group = MultiThreadedEventLoopGroup(numThreads: 1) defer { - try! group.syncShutdownGracefully() + XCTAssertNoThrow(try group.syncShutdownGracefully()) } let numBytes = 16 * 1024 @@ -75,7 +75,7 @@ class EchoServerClientTest : XCTestCase { func testLotsOfUnflushedWrites() throws { let group = MultiThreadedEventLoopGroup(numThreads: 1) defer { - try! group.syncShutdownGracefully() + XCTAssertNoThrow(try group.syncShutdownGracefully()) } let serverChannel = try ServerBootstrap(group: group) @@ -85,7 +85,7 @@ class EchoServerClientTest : XCTestCase { }.bind(to: "127.0.0.1", on: 0).wait() defer { - _ = try! serverChannel.close().wait() + XCTAssertNoThrow(try serverChannel.close().wait()) } let promise: EventLoopPromise = group.next().newPromise() @@ -108,12 +108,12 @@ class EchoServerClientTest : XCTestCase { func testEchoUnixDomainSocket() throws { let group = MultiThreadedEventLoopGroup(numThreads: 1) defer { - try! group.syncShutdownGracefully() + XCTAssertNoThrow(try group.syncShutdownGracefully()) } let udsTempDir = buildTempDir() defer { - try! FileManager.default.removeItem(atPath: udsTempDir) + XCTAssertNoThrow(try FileManager.default.removeItem(atPath: udsTempDir)) } let numBytes = 16 * 1024 @@ -151,12 +151,12 @@ class EchoServerClientTest : XCTestCase { func testConnectUnixDomainSocket() throws { let group = MultiThreadedEventLoopGroup(numThreads: 1) defer { - try! group.syncShutdownGracefully() + XCTAssertNoThrow(try group.syncShutdownGracefully()) } let udsTempDir = buildTempDir() defer { - try! FileManager.default.removeItem(atPath: udsTempDir) + XCTAssertNoThrow(try FileManager.default.removeItem(atPath: udsTempDir)) } let numBytes = 16 * 1024 @@ -194,7 +194,7 @@ class EchoServerClientTest : XCTestCase { func testChannelActiveOnConnect() throws { let group = MultiThreadedEventLoopGroup(numThreads: 1) defer { - try! group.syncShutdownGracefully() + XCTAssertNoThrow(try group.syncShutdownGracefully()) } let handler = ChannelActiveHandler() @@ -220,7 +220,7 @@ class EchoServerClientTest : XCTestCase { func testWriteThenRead() throws { let group = MultiThreadedEventLoopGroup(numThreads: 1) defer { - try! group.syncShutdownGracefully() + XCTAssertNoThrow(try group.syncShutdownGracefully()) } let serverChannel = try ServerBootstrap(group: group) @@ -450,7 +450,7 @@ class EchoServerClientTest : XCTestCase { let group = MultiThreadedEventLoopGroup(numThreads: 1) defer { - try! group.syncShutdownGracefully() + XCTAssertNoThrow(try group.syncShutdownGracefully()) } let inactivePromise = group.next().newPromise() as EventLoopPromise<()> @@ -468,7 +468,7 @@ class EchoServerClientTest : XCTestCase { }.bind(to: "127.0.0.1", on: 0).wait() defer { - _ = try! serverChannel.close().wait() + XCTAssertNoThrow(try serverChannel.close().wait()) } let clientChannel = try ClientBootstrap(group: group).connect(to: serverChannel.localAddress!).wait() @@ -486,7 +486,7 @@ class EchoServerClientTest : XCTestCase { func testFlushOnEmpty() throws { let group = MultiThreadedEventLoopGroup(numThreads: 1) defer { - try! group.syncShutdownGracefully() + XCTAssertNoThrow(try group.syncShutdownGracefully()) } let writingBytes = "hello" @@ -500,7 +500,7 @@ class EchoServerClientTest : XCTestCase { }.bind(to: "127.0.0.1", on: 0).wait() defer { - _ = try! serverChannel.close().wait() + XCTAssertNoThrow(try serverChannel.close().wait()) } let clientChannel = try ClientBootstrap(group: group).connect(to: serverChannel.localAddress!).wait() @@ -534,7 +534,7 @@ class EchoServerClientTest : XCTestCase { func testWriteOnConnect() throws { let group = MultiThreadedEventLoopGroup(numThreads: 1) defer { - try! group.syncShutdownGracefully() + XCTAssertNoThrow(try group.syncShutdownGracefully()) } let serverChannel = try ServerBootstrap(group: group) @@ -544,7 +544,7 @@ class EchoServerClientTest : XCTestCase { }.bind(to: "127.0.0.1", on: 0).wait() defer { - _ = try! serverChannel.close().wait() + XCTAssertNoThrow(try serverChannel.close().wait()) } let stringToWrite = "hello" @@ -567,7 +567,7 @@ class EchoServerClientTest : XCTestCase { func testWriteOnAccept() throws { let group = MultiThreadedEventLoopGroup(numThreads: 1) defer { - try! group.syncShutdownGracefully() + XCTAssertNoThrow(try group.syncShutdownGracefully()) } let stringToWrite = "hello" @@ -578,7 +578,7 @@ class EchoServerClientTest : XCTestCase { }.bind(to: "127.0.0.1", on: 0).wait() defer { - _ = try! serverChannel.close().wait() + XCTAssertNoThrow(try serverChannel.close().wait()) } let promise: EventLoopPromise = group.next().newPromise() diff --git a/Tests/NIOTests/EventLoopTest.swift b/Tests/NIOTests/EventLoopTest.swift index ccd8bb5a0..2b19c8522 100644 --- a/Tests/NIOTests/EventLoopTest.swift +++ b/Tests/NIOTests/EventLoopTest.swift @@ -23,7 +23,7 @@ public class EventLoopTest : XCTestCase { let amount: TimeAmount = .seconds(1) let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) defer { - try! eventLoopGroup.syncShutdownGracefully() + XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) } let value = try eventLoopGroup.next().scheduleTask(in: amount) { return true @@ -38,7 +38,7 @@ public class EventLoopTest : XCTestCase { let longAmount: TimeAmount = .seconds(1) let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) defer { - try! eventLoopGroup.syncShutdownGracefully() + XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) } // First, we create a server and client channel, but don't connect them. @@ -71,7 +71,7 @@ public class EventLoopTest : XCTestCase { public func testScheduleCancelled() throws { let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) defer { - try! eventLoopGroup.syncShutdownGracefully() + XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) } let ran = Atomic(value: false) let scheduled = eventLoopGroup.next().scheduleTask(in: .seconds(2)) { diff --git a/Tests/NIOTests/FileRegionTest.swift b/Tests/NIOTests/FileRegionTest.swift index 912f11ee8..a22ff55b7 100644 --- a/Tests/NIOTests/FileRegionTest.swift +++ b/Tests/NIOTests/FileRegionTest.swift @@ -35,7 +35,7 @@ class FileRegionTest : XCTestCase { func testWriteFileRegion() throws { let group = MultiThreadedEventLoopGroup(numThreads: 1) defer { - try! group.syncShutdownGracefully() + XCTAssertNoThrow(try group.syncShutdownGracefully()) } let numBytes = 16 * 1024 @@ -78,7 +78,7 @@ class FileRegionTest : XCTestCase { func testWriteEmptyFileRegionDoesNotHang() throws { let group = MultiThreadedEventLoopGroup(numThreads: 1) defer { - try! group.syncShutdownGracefully() + XCTAssertNoThrow(try group.syncShutdownGracefully()) } let countingHandler = ByteCountingHandler(numBytes: 0, promise: group.next().newPromise()) @@ -148,7 +148,7 @@ class FileRegionTest : XCTestCase { func testOutstandingFileRegionsWork() throws { let group = MultiThreadedEventLoopGroup(numThreads: 1) defer { - try! group.syncShutdownGracefully() + XCTAssertNoThrow(try group.syncShutdownGracefully()) } let numBytes = 16 * 1024 @@ -183,7 +183,7 @@ class FileRegionTest : XCTestCase { try content.write(toFile: filePath, atomically: false, encoding: .ascii) do { () = try clientChannel.writeAndFlush(data: NIOAny(FileRegion(file: filePath, readerIndex: 0, endIndex: bytes.count))).then(callback: { _ in - let frFuture = try! clientChannel.write(data: NIOAny(FileRegion(file: filePath, readerIndex: 0, endIndex: bytes.count))) + let frFuture = try clientChannel.write(data: NIOAny(FileRegion(file: filePath, readerIndex: 0, endIndex: bytes.count))) var buffer = clientChannel.allocator.buffer(capacity: bytes.count) buffer.write(bytes: bytes) let bbFuture = clientChannel.write(data: NIOAny(buffer)) diff --git a/Tests/NIOTests/IdleStateHandlerTest.swift b/Tests/NIOTests/IdleStateHandlerTest.swift index 904236d16..9471a9d27 100644 --- a/Tests/NIOTests/IdleStateHandlerTest.swift +++ b/Tests/NIOTests/IdleStateHandlerTest.swift @@ -36,7 +36,7 @@ class IdleStateHandlerTest : XCTestCase { private func testIdle(_ handler: IdleStateHandler, _ writeToChannel: Bool, _ assertEventFn: @escaping (IdleStateHandler.IdleStateEvent) -> Bool) throws { let group = MultiThreadedEventLoopGroup(numThreads: 1) defer { - try! group.syncShutdownGracefully() + XCTAssertNoThrow(try group.syncShutdownGracefully()) } class TestWriteHandler: ChannelInboundHandler {