From 8b2adb39d3d9a643e64664d2124e4c0c95e0dcb0 Mon Sep 17 00:00:00 2001 From: Adam Fowler Date: Mon, 26 Oct 2020 16:17:53 +0000 Subject: [PATCH] Remove performance tests, they are all in the Benchmark app now --- Tests/SotoCoreTests/PerformanceTests.swift | 321 ------------------- Tests/SotoCoreTests/QueryEncoderTests.swift | 22 -- Tests/SotoSignerV4Tests/AWSSignerTests.swift | 25 -- 3 files changed, 368 deletions(-) delete mode 100644 Tests/SotoCoreTests/PerformanceTests.swift diff --git a/Tests/SotoCoreTests/PerformanceTests.swift b/Tests/SotoCoreTests/PerformanceTests.swift deleted file mode 100644 index 97878d51d..000000000 --- a/Tests/SotoCoreTests/PerformanceTests.swift +++ /dev/null @@ -1,321 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Soto for AWS open source project -// -// Copyright (c) 2017-2020 the Soto project authors -// Licensed under Apache License v2.0 -// -// See LICENSE.txt for license information -// See CONTRIBUTORS.txt for the list of Soto project authors -// -// SPDX-License-Identifier: Apache-2.0 -// -//===----------------------------------------------------------------------===// - -import AsyncHTTPClient -import NIO -import NIOHTTP1 -@testable import SotoCore -import SotoSignerV4 -import SotoTestUtils -import XCTest - -struct HeaderRequest: AWSEncodableShape { - static var _encoding: [AWSMemberEncoding] = [ - AWSMemberEncoding(label: "Header1", location: .header(locationName: "Header1")), - AWSMemberEncoding(label: "Header2", location: .header(locationName: "Header2")), - AWSMemberEncoding(label: "Header3", location: .header(locationName: "Header3")), - AWSMemberEncoding(label: "Header4", location: .header(locationName: "Header4")), - ] - - let header1: String - let header2: String - let header3: String - let header4: Date -} - -struct StandardRequest: AWSEncodableShape { - let item1: String - let item2: Int - let item3: Double - let item4: Date - let item5: [Int] -} - -struct PayloadRequest: AWSEncodableShape & AWSShapeWithPayload { - public static let _payloadPath: String = "payload" - - let payload: StandardRequest -} - -struct MixedRequest: AWSEncodableShape { - static var _encoding: [AWSMemberEncoding] = [ - AWSMemberEncoding(label: "item1", location: .header(locationName: "item1")), - ] - - let item1: String - let item2: Int - let item3: Double - let item4: Date -} - -struct StandardResponse: AWSDecodableShape { - let item1: String - let item2: Int - let item3: Double - let item4: Date - let item5: [Int] -} - -class PerformanceTests: XCTestCase { - @EnvironmentVariable("ENABLE_TIMING_TESTS", default: true) static var enableTimingTests: Bool - - func testHeaderRequest() { - guard Self.enableTimingTests == true else { return } - let config = createServiceConfig( - region: .useast1, - service: "Test", - serviceProtocol: .restxml, - apiVersion: "1.0" - ) - let date = Date() - let request = HeaderRequest(header1: "Header1", header2: "Header2", header3: "Header3", header4: date) - measure { - do { - for _ in 0..<1000 { - _ = try AWSRequest(operation: "Test", path: "/", httpMethod: .POST, input: request, configuration: config) - } - } catch { - XCTFail("Unexpected Error: \(error.localizedDescription)") - } - } - } - - func testXMLRequest() { - guard Self.enableTimingTests == true else { return } - let config = createServiceConfig( - region: .useast1, - service: "Test", - serviceProtocol: .restxml, - apiVersion: "1.0" - ) - let date = Date() - let request = StandardRequest(item1: "item1", item2: 45, item3: 3.14, item4: date, item5: [1, 2, 3, 4, 5]) - measure { - do { - for _ in 0..<1000 { - _ = try AWSRequest(operation: "Test", path: "/", httpMethod: .POST, input: request, configuration: config) - } - } catch { - XCTFail("Unexpected Error: \(error.localizedDescription)") - } - } - } - - func testXMLPayloadRequest() { - guard Self.enableTimingTests == true else { return } - let config = createServiceConfig( - region: .useast1, - service: "Test", - serviceProtocol: .restxml, - apiVersion: "1.0" - ) - let date = Date() - let request = PayloadRequest(payload: StandardRequest(item1: "item1", item2: 45, item3: 3.14, item4: date, item5: [1, 2, 3, 4, 5])) - measure { - do { - for _ in 0..<1000 { - _ = try AWSRequest(operation: "Test", path: "/", httpMethod: .POST, input: request, configuration: config) - } - } catch { - XCTFail("\(error)") - } - } - } - - func testJSONRequest() { - guard Self.enableTimingTests == true else { return } - let config = createServiceConfig( - region: .useast1, - service: "Test", - serviceProtocol: .restjson, - apiVersion: "1.0" - ) - let date = Date() - let request = StandardRequest(item1: "item1", item2: 45, item3: 3.14, item4: date, item5: [1, 2, 3, 4, 5]) - measure { - do { - for _ in 0..<1000 { - _ = try AWSRequest(operation: "Test", path: "/", httpMethod: .POST, input: request, configuration: config) - } - } catch { - XCTFail("\(error)") - } - } - } - - func testJSONPayloadRequest() { - guard Self.enableTimingTests == true else { return } - let config = createServiceConfig( - region: .useast1, - service: "Test", - serviceProtocol: .restjson, - apiVersion: "1.0" - ) - let date = Date() - let request = PayloadRequest(payload: StandardRequest(item1: "item1", item2: 45, item3: 3.14, item4: date, item5: [1, 2, 3, 4, 5])) - measure { - do { - for _ in 0..<1000 { - _ = try AWSRequest(operation: "Test", path: "/", httpMethod: .POST, input: request, configuration: config) - } - } catch { - XCTFail("\(error)") - } - } - } - - func testQueryRequest() { - guard Self.enableTimingTests == true else { return } - let config = createServiceConfig( - region: .useast1, - service: "Test", - serviceProtocol: .query, - apiVersion: "1.0" - ) - let date = Date() - let request = StandardRequest(item1: "item1", item2: 45, item3: 3.14, item4: date, item5: [1, 2, 3, 4, 5]) - measure { - do { - for _ in 0..<1000 { - _ = try AWSRequest(operation: "Test", path: "/", httpMethod: .POST, input: request, configuration: config) - } - } catch { - XCTFail("\(error)") - } - } - } - - func testUnsignedRequest() { - guard Self.enableTimingTests == true else { return } - let config = createServiceConfig( - region: .useast1, - service: "Test", - serviceProtocol: .json(version: "1.1"), - apiVersion: "1.0" - ) - - let request = try! AWSRequest( - operation: "Test", - path: "/", - httpMethod: .GET, - configuration: config - ) - - let signer = AWSSigner( - credentials: StaticCredential(accessKeyId: "", secretAccessKey: ""), - name: config.service, - region: config.region.rawValue - ) - let byteBufferAllocator = ByteBufferAllocator() - measure { - for _ in 0..<1000 { - _ = request.createHTTPRequest(signer: signer, byteBufferAllocator: byteBufferAllocator) - } - } - } - - func testSignedURLRequest() { - guard Self.enableTimingTests == true else { return } - let config = createServiceConfig() - let client = createAWSClient(credentialProvider: .static(accessKeyId: "MyAccessKeyId", secretAccessKey: "MySecretAccessKey")) - defer { - XCTAssertNoThrow(try client.syncShutdown()) - } - let awsRequest = try! AWSRequest( - operation: "Test", - path: "/", - httpMethod: .GET, - configuration: config - ).applyMiddlewares(config.middlewares + client.middlewares, config: config) - - let signer = try! client.createSigner(serviceConfig: config, logger: AWSClient.loggingDisabled).wait() - let byteBufferAllocator = ByteBufferAllocator() - measure { - for _ in 0..<1000 { - _ = awsRequest.createHTTPRequest(signer: signer, byteBufferAllocator: byteBufferAllocator) - } - } - } - - func testSignedHeadersRequest() { - guard Self.enableTimingTests == true else { return } - let config = createServiceConfig( - region: .useast1, - service: "Test", - serviceProtocol: .json(version: "1.1"), - apiVersion: "1.0" - ) - let date = Date() - let request = StandardRequest(item1: "item1", item2: 45, item3: 3.14, item4: date, item5: [1, 2, 3, 4, 5]) - let awsRequest = try! AWSRequest(operation: "Test", path: "/", httpMethod: .POST, input: request, configuration: config) - let signer = AWSSigner( - credentials: StaticCredential(accessKeyId: "", secretAccessKey: ""), - name: config.service, - region: config.region.rawValue - ) - let byteBufferAllocator = ByteBufferAllocator() - measure { - for _ in 0..<1000 { - _ = awsRequest.createHTTPRequest(signer: signer, byteBufferAllocator: byteBufferAllocator) - } - } - } - - func testValidateXMLResponse() { - guard Self.enableTimingTests == true else { return } - var buffer = ByteBufferAllocator().buffer(capacity: 0) - buffer.writeString("Hello53.1412001-12-23T15:34:12.590Z36325") - let response = HTTPClient.Response( - host: "localhost", - status: .ok, - version: .init(major: 1, minor: 1), - headers: HTTPHeaders(), - body: buffer - ) - - measure { - do { - for _ in 0..<1000 { - let awsResponse = try AWSResponse(from: response, serviceProtocol: .restxml, raw: false) - let _: StandardResponse = try awsResponse.generateOutputShape(operation: "Test") - } - } catch { - XCTFail("\(error)") - } - } - } - - func testValidateJSONResponse() { - guard Self.enableTimingTests == true else { return } - var buffer = ByteBufferAllocator().buffer(capacity: 0) - buffer.writeString("{\"item1\":\"Hello\", \"item2\":5, \"item3\":3.14, \"item4\":3345984444, \"item5\": [1,56,3,7]}") - let response = HTTPClient.Response( - host: "localhost", - status: .ok, - version: .init(major: 1, minor: 1), - headers: HTTPHeaders(), - body: buffer - ) - measure { - do { - for _ in 0..<1000 { - let awsResponse = try AWSResponse(from: response, serviceProtocol: .restjson, raw: false) - let _: StandardResponse = try awsResponse.generateOutputShape(operation: "Test") - } - } catch { - XCTFail("\(error)") - } - } - } -} diff --git a/Tests/SotoCoreTests/QueryEncoderTests.swift b/Tests/SotoCoreTests/QueryEncoderTests.swift index 4e3890a91..f5846c5f4 100644 --- a/Tests/SotoCoreTests/QueryEncoderTests.swift +++ b/Tests/SotoCoreTests/QueryEncoderTests.swift @@ -186,28 +186,6 @@ class QueryEncoderTests: XCTestCase { testQuery(test, query: "A.1.entry=1&A.1.name=first") } - // array performance in QueryEncoder is slower than expected - func testQueryArrayPerformance() { - guard Self.enableTimingTests == true else { return } - struct Test: AWSEncodableShape { - let a: [Int] - - private enum CodingKeys: String, CodingKey { - case a = "A" - } - } - let test = Test(a: [9, 8, 7, 6, 5, 4, 3]) - measure { - do { - for _ in 1...1000 { - _ = try QueryEncoder().encode(test) - } - } catch { - XCTFail("\(error)") - } - } - } - func testDataBlobEncode() { struct Test: AWSEncodableShape { let a: Data diff --git a/Tests/SotoSignerV4Tests/AWSSignerTests.swift b/Tests/SotoSignerV4Tests/AWSSignerTests.swift index 269ba9919..140ae87b4 100644 --- a/Tests/SotoSignerV4Tests/AWSSignerTests.swift +++ b/Tests/SotoSignerV4Tests/AWSSignerTests.swift @@ -99,29 +99,4 @@ final class AWSSignerTests: XCTestCase { XCTAssertEqual(headers1["Authorization"].first, headers2["Authorization"].first) XCTAssertEqual(headers2["Authorization"].first, headers3["Authorization"].first) } - - func testPerformanceSignedURL() { - guard Self.enableTimingTests == true else { return } - - let signer = AWSSigner(credentials: credentials, name: "s3", region: "eu-west-1") - - measure { - for _ in 0..<1000 { - _ = signer.signURL(url: URL(string: "https://test-bucket.s3.amazonaws.com/test-put.txt")!, method: .GET, expires: .hours(24)) - } - } - } - - func testPerformanceSignedHeaders() { - guard Self.enableTimingTests == true else { return } - - let string = "testing, testing, 1,2,1,2" - let signer = AWSSigner(credentials: credentials, name: "s3", region: "eu-west-1") - - measure { - for _ in 0..<1000 { - _ = signer.signHeaders(url: URL(string: "https://test-bucket.s3.amazonaws.com/test-put.txt")!, method: .GET, headers: ["Content-Type": "application/x-www-form-urlencoded; charset=utf-8"], body: .string(string)) - } - } - } }