From fde6b39966add5a60a2a1eeee22f42de23e03216 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20R=C3=B6nnqvist?= Date: Fri, 20 Sep 2024 10:53:37 +0200 Subject: [PATCH] Remove long disabled integration test There's no reasonable expectation for reenabling this test because the attributes that make it unsuitable for running in CI won't change --- .../PreviewActionIntegrationTests.swift | 159 ------------- .../PreviewServer/HTTPClient.swift | 102 --------- .../PreviewServer/PreviewServerTests.swift | 210 ------------------ 3 files changed, 471 deletions(-) delete mode 100644 Tests/SwiftDocCUtilitiesTests/PreviewServer/HTTPClient.swift delete mode 100644 Tests/SwiftDocCUtilitiesTests/PreviewServer/PreviewServerTests.swift diff --git a/Tests/SwiftDocCUtilitiesTests/PreviewActionIntegrationTests.swift b/Tests/SwiftDocCUtilitiesTests/PreviewActionIntegrationTests.swift index b507e902c0..22f3a306b0 100644 --- a/Tests/SwiftDocCUtilitiesTests/PreviewActionIntegrationTests.swift +++ b/Tests/SwiftDocCUtilitiesTests/PreviewActionIntegrationTests.swift @@ -15,15 +15,6 @@ import XCTest import SwiftDocCTestUtilities class PreviewActionIntegrationTests: XCTestCase { - func json(contentsOf url: URL) throws -> [String: Any] { - let data = try Data(contentsOf: url) - guard let result = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] else { - XCTFail("Failed to load JSON from \(url.path)") - return [:] - } - return result - } - private func createMinimalDocsBundle() -> Folder { let overviewURL = Bundle.module.url( forResource: "Overview", withExtension: "tutorial", subdirectory: "Test Resources")! @@ -72,156 +63,6 @@ class PreviewActionIntegrationTests: XCTestCase { return (sourceURL: sourceURL, outputURL: outputURL, templateURL: templateURL) } - /// Test the fix for . - func testWatchRecoversAfterConversionErrors() throws { - #if os(macOS) - throw XCTSkip("This test is flaky rdar://90866510") - -// // Source files. -// let source = createMinimalDocsBundle() -// let (sourceURL, outputURL, templateURL) = try createPreviewSetup(source: source) -// -// let logStorage = LogHandle.LogStorage() -// var logHandle = LogHandle.memory(logStorage) -// -// let convertActionTempDirectory = try createTemporaryDirectory() -// let createConvertAction = { -// try ConvertAction( -// documentationBundleURL: sourceURL, -// outOfProcessResolver: nil, -// analyze: false, -// targetDirectory: outputURL, -// htmlTemplateDirectory: templateURL, -// emitDigest: false, -// currentPlatforms: nil, -// fileManager: FileManager.default, -// temporaryDirectory: convertActionTempDirectory) -// } -// -// guard let preview = try? PreviewAction( -// tlsCertificateKey: nil, -// tlsCertificateChain: nil, -// serverUsername: nil, -// serverPassword: nil, -// port: 8080, // We ignore this value when we set the `bindServerToSocketPath` property below. -// createConvertAction: createConvertAction) else { -// XCTFail("Could not create preview action from parameters") -// return -// } -// -// let socketURL = try createTemporaryDirectory().appendingPathComponent("sock") -// preview.bindServerToSocketPath = socketURL.path -// -// // The technology output file URL -// let convertedOverviewURL = outputURL -// .appendingPathComponent("data") -// .appendingPathComponent("tutorials") -// .appendingPathComponent("Overview.json") -// -// // Start watching the source and get the initial (successful) state. -// do { -// let logOutputExpectation = asyncLogExpectation(log: logStorage, description: "Did produce log output") { $0.contains("=======") } -// -// // Start the preview and keep it running for the asserts that follow inside this test. -// DispatchQueue.global().async { -// var action = preview as Action -// do { -// let result = try action.perform(logHandle: logHandle) -// -// guard !result.problems.containsErrors else { -// throw ErrorsEncountered() -// } -// -// if !result.problems.isEmpty { -// print(result.problems.localizedDescription, to: &logHandle) -// } -// } catch { -// XCTFail(error.localizedDescription) -// } -// } -// -// wait(for: [logOutputExpectation], timeout: 20.0) -// -// // Check the log output to confirm that expected informational -// // text is printed -// let logOutput = logStorage.text -// -// // rdar://71318888 -// let expectedLogIntroductoryOutput = """ -// Input: \(sourceURL.path) -// Template: \(templateURL.path) -// """ -// XCTAssertTrue(logOutput.hasPrefix(expectedLogIntroductoryOutput), """ -// Missing expected input and template information in log/print output -// """) -// -// if let previewInfoStart = logOutput.range(of: "=====\n")?.upperBound, -// let previewInfoEnd = logOutput[previewInfoStart...].range(of: "\n=====")?.lowerBound { -// XCTAssertEqual(logOutput[previewInfoStart..Bool) { self.storage = storage diff --git a/Tests/SwiftDocCUtilitiesTests/PreviewServer/HTTPClient.swift b/Tests/SwiftDocCUtilitiesTests/PreviewServer/HTTPClient.swift deleted file mode 100644 index a675a5aa55..0000000000 --- a/Tests/SwiftDocCUtilitiesTests/PreviewServer/HTTPClient.swift +++ /dev/null @@ -1,102 +0,0 @@ -/* - This source file is part of the Swift.org open source project - - Copyright (c) 2021 Apple Inc. and the Swift project authors - Licensed under Apache License v2.0 with Runtime Library Exception - - See https://swift.org/LICENSE.txt for license information - See https://swift.org/CONTRIBUTORS.txt for Swift project authors -*/ - -#if canImport(NIOHTTP1) -import Foundation -import NIO -import NIOHTTP1 - -/// A full testing http client that requests a given path on a given destination - either host or socket -/// and records the response. -final class HTTPClient { - - /// A handler to make a GET request and store the response. - final class HTTPGetHandler: ChannelInboundHandler { - public typealias InboundIn = HTTPClientResponsePart - public typealias OutboundOut = HTTPClientRequestPart - - let path: String - init(path: String) { - self.path = path - } - - var response: String? - var statusCode: UInt = 0 - - public func channelActive(context: ChannelHandlerContext) { - let requestHead = HTTPRequestHead(version: HTTPVersion(major: 1, minor: 1), method: .GET, uri: path) - - context.write(self.wrapOutboundOut(.head(requestHead)), promise: nil) - context.write(self.wrapOutboundOut(.body(.byteBuffer(ByteBuffer.init()))), promise: nil) - context.writeAndFlush(self.wrapOutboundOut(.end(nil)), promise: nil) - } - - public func channelRead(context: ChannelHandlerContext, data: NIOAny) { - - let clientResponse = self.unwrapInboundIn(data) - - switch clientResponse { - case .head(let responseHead): - statusCode = responseHead.status.code - case .body(let byteBuffer): - response = String(buffer: byteBuffer) - case .end: - context.close(promise: nil) - } - } - - public func errorCaught(context: ChannelHandlerContext, error: Error) { - context.close(promise: nil) - } - } - - enum Bind { - case ip(host: String, port: Int) - case unixDomainSocket(path: String) - } - - let group: MultiThreadedEventLoopGroup - let to: Bind - let handler: HTTPGetHandler - - init(to: Bind, path: String) { - self.group = MultiThreadedEventLoopGroup(numberOfThreads: 1) - self.to = to - self.handler = HTTPGetHandler(path: path) - } - - /// Makes a GET request and waits until it gets a response. - func connect() throws { - let handler = self.handler - - let bootstrap = ClientBootstrap(group: group) - .channelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) - .channelInitializer { channel in - channel.pipeline.addHTTPClientHandlers(position: .first, - leftOverBytesStrategy: .fireError).flatMap { - channel.pipeline.addHandler(handler) - } - } - - let channel: Channel - switch to { - case .ip(let host, let port): - channel = try bootstrap.connect(host: host, port: port).wait() - case .unixDomainSocket(let path): - channel = try bootstrap.connect(unixDomainSocketPath: path).wait() - } - try channel.closeFuture.wait() - } - - deinit { - try? group.syncShutdownGracefully() - } -} -#endif diff --git a/Tests/SwiftDocCUtilitiesTests/PreviewServer/PreviewServerTests.swift b/Tests/SwiftDocCUtilitiesTests/PreviewServer/PreviewServerTests.swift deleted file mode 100644 index db3ea62910..0000000000 --- a/Tests/SwiftDocCUtilitiesTests/PreviewServer/PreviewServerTests.swift +++ /dev/null @@ -1,210 +0,0 @@ -/* - This source file is part of the Swift.org open source project - - Copyright (c) 2021 Apple Inc. and the Swift project authors - Licensed under Apache License v2.0 with Runtime Library Exception - - See https://swift.org/LICENSE.txt for license information - See https://swift.org/CONTRIBUTORS.txt for Swift project authors -*/ - -#if canImport(NIOHTTP1) -import XCTest -import Foundation - -@testable import SwiftDocCUtilities -@testable import SwiftDocC -import SwiftDocCTestUtilities - -@testable import NIO -@testable import NIOHTTP1 - -// rdar85046362 -// Disabling this test due to accessing the temp directory and -// making network calls. The temp directories are accessible by all jobs on a -// bot, so they are subject to noise. Network calls are slow and can also be -// very noisy. -// class PreviewServerTests: XCTestCase { -class PreviewServerTests { - - func createTemporaryDirectory( - fileManager: FileManager = .default - ) throws -> URL { - fatalError("This test is disabled by not conforming to XCTestCase. This helper is added here to make the code compile. This should never be called.") - } - - public func createTempFolder(content: [File]) throws -> URL { - fatalError("This test is disabled by not conforming to XCTestCase. This helper is added here to make the code compile. This should never be called.") - } - - func testPreviewServerBeforeStarted() throws { - // Create test content - let tempFolderURL = try createTempFolder(content: [ - TextFile(name: "index.html", utf8Content: "index"), - ]) - - let socketURL = try createTemporaryDirectory().appendingPathComponent("sock") - - // Run test server - var log = LogHandle.none - let server = try PreviewServer(contentURL: tempFolderURL, bindTo: .socket(path: socketURL.path), logHandle: &log) - - // Assert server starts - let expectationStarted = AsynchronousExpectation(description: "Server before start") - DispatchQueue.global().async { - do { - try server.start() { - expectationStarted.fulfill() - } - } catch { - XCTFail(error.localizedDescription) - } - } - - XCTAssertNotEqual(expectationStarted.wait(timeout: 5.0), .timedOut) - - do { - try server.stop() - } catch { - XCTFail(error.localizedDescription) - } - } - - private func assertServer(socketPath: String, path: String, matchesContent expectedContent: String, file: StaticString = #file, line: UInt = #line) { - let client = HTTPClient(to: .unixDomainSocket(path: socketPath), path: path) - XCTAssertNoThrow(try client.connect(), file: (file), line: line) - XCTAssertEqual(client.handler.statusCode, 200, file: (file), line: line) - XCTAssertEqual(client.handler.response, expectedContent, file: (file), line: line) - } - - private func assertServerError(socketPath: String, path: String, errorStatusCode: UInt, file: StaticString = #file, line: UInt = #line) { - let client = HTTPClient(to: .unixDomainSocket(path: socketPath), path: path) - XCTAssertNoThrow(try client.connect(), file: (file), line: line) - XCTAssertNil(client.handler.response, file: (file), line: line) - XCTAssertEqual(client.handler.statusCode, errorStatusCode, file: (file), line: line) - } - - private func makeTempFolder() throws -> URL { - // Create test content - try createTempFolder(content: [ - TextFile(name: "index.html", utf8Content: "index"), - TextFile(name: "theme-settings.js", utf8Content: "java script content"), - TextFile(name: "theme-settings.json", utf8Content: "JSON content"), - TextFile(name: "favicon.ico", utf8Content: "icon content"), - TextFile(name: "apple-logo.svg", utf8Content: "svg content"), - Folder(name: "data", content: [ - TextFile(name: "test.js", utf8Content: "data content"), - ]), - Folder(name: "css", content: [ - TextFile(name: "test.css", utf8Content: "css content"), - ]), - Folder(name: "js", content: [ - TextFile(name: "test.js", utf8Content: "js content"), - ]), - Folder(name: "fonts", content: [ - TextFile(name: "test.tff", utf8Content: "fonts content"), - ]), - Folder(name: "images", content: [ - TextFile(name: "test.png", utf8Content: "images content"), - ]), - Folder(name: "img", content: [ - TextFile(name: "test.gif", utf8Content: "img content"), - ]), - Folder(name: "videos", content: [ - TextFile(name: "test.mov", utf8Content: "videos content"), - ]), - Folder(name: "downloads", content: [ - TextFile(name: "test.zip", utf8Content: "downloads content"), - ]) - ]) - } - - func testPreviewServerPaths() throws { - let tempFolderURL = try makeTempFolder() - - // Socket URL - let socketURL = try createTemporaryDirectory().appendingPathComponent("sock") - - // Create the server - var log = LogHandle.none - let server = try PreviewServer(contentURL: tempFolderURL, bindTo: .socket(path: socketURL.path), logHandle: &log) - - // Start the server - let expectationStarted = AsynchronousExpectation(description: "Server before start") - DispatchQueue.global().async { - do { - try server.start() { - expectationStarted.fulfill() - } - } catch { - XCTFail(error.localizedDescription) - } - } - XCTAssertNotEqual(expectationStarted.wait(timeout: 5.0), .timedOut) - - // Test server paths - assertServer(socketPath: socketURL.path, path: "/", matchesContent: "index") - assertServer(socketPath: socketURL.path, path: "/theme-settings.js", matchesContent: "java script content") - assertServer(socketPath: socketURL.path, path: "/theme-settings.json", matchesContent: "JSON content") - assertServer(socketPath: socketURL.path, path: "/favicon.ico", matchesContent: "icon content") - assertServer(socketPath: socketURL.path, path: "/apple-logo.svg", matchesContent: "svg content") - assertServer(socketPath: socketURL.path, path: "/data/test.js", matchesContent: "data content") - assertServer(socketPath: socketURL.path, path: "/css/test.css", matchesContent: "css content") - assertServer(socketPath: socketURL.path, path: "/js/test.js", matchesContent: "js content") - assertServer(socketPath: socketURL.path, path: "/fonts/test.tff", matchesContent: "fonts content") - assertServer(socketPath: socketURL.path, path: "/images/test.png", matchesContent: "images content") - assertServer(socketPath: socketURL.path, path: "/img/test.gif", matchesContent: "img content") - assertServer(socketPath: socketURL.path, path: "/videos/test.mov", matchesContent: "videos content") - assertServer(socketPath: socketURL.path, path: "/downloads/test.zip", matchesContent: "downloads content") - - assertServerError(socketPath: socketURL.path, path: "/downloads/NOTFOUND.zip", errorStatusCode: 404) - - // Verify that the server stops serving content. - XCTAssertNoThrow(try server.stop()) - - let client = HTTPClient(to: .unixDomainSocket(path: socketURL.path), path: "/") - XCTAssertThrowsError(try client.connect()) - } - - func testConcurrentRequests() throws { - let tempFolderURL = try makeTempFolder() - - // Socket URL - let socketURL = try createTemporaryDirectory().appendingPathComponent("sock") - - // Create the server - var log = LogHandle.none - let server = try PreviewServer(contentURL: tempFolderURL, bindTo: .socket(path: socketURL.path), logHandle: &log) - - // Start the server - let expectationStarted = AsynchronousExpectation(description: "Server before start") - DispatchQueue.global().async { - do { - try server.start() { - expectationStarted.fulfill() - } - } catch { - XCTFail(error.localizedDescription) - } - } - XCTAssertNotEqual(expectationStarted.wait(timeout: 5.0), .timedOut) - - // Make 5000 HTTP requests; 1000 concurrent batches x 5 requests - DispatchQueue.concurrentPerform(iterations: 1000) { _ in - assertServer(socketPath: socketURL.path, path: "/data/test.js", matchesContent: "data content") - assertServer(socketPath: socketURL.path, path: "/css/test.css", matchesContent: "css content") - assertServer(socketPath: socketURL.path, path: "/js/test.js", matchesContent: "js content") - assertServer(socketPath: socketURL.path, path: "/fonts/test.tff", matchesContent: "fonts content") - assertServerError(socketPath: socketURL.path, path: "/js/NotFound.js", errorStatusCode: 404) - } - XCTAssertNoThrow(try server.stop()) - } - - func testPreviewServerBindDescription() { - let localhostBind = PreviewServer.Bind.localhost(port: 1234) - XCTAssertEqual("\(localhostBind)", "localhost:1234") - let socketBind = PreviewServer.Bind.socket(path: "/tmp/file.sock") - XCTAssertEqual("\(socketBind)", "/tmp/file.sock") - } -} -#endif