Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add toggle for time-sensitive tests. #677

Merged
merged 3 commits into from
Jan 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Tests/GRPCTests/FunctionalTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class FunctionalTestsInsecureTransport: EchoTestCaseBase {
}

func testUnaryLotsOfRequests() throws {
guard self.runTimeSensitiveTests() else { return }

// Sending that many requests at once can sometimes trip things up, it seems.
let clockStart = clock()
let numberOfRequests = 2_000
Expand Down Expand Up @@ -130,6 +132,7 @@ class FunctionalTestsInsecureTransport: EchoTestCaseBase {
}

func testClientStreamingLotsOfMessages() throws {
guard self.runTimeSensitiveTests() else { return }
self.defaultTestTimeout = 15.0
XCTAssertNoThrow(try doTestClientStreaming(messages: lotsOfStrings))
}
Expand Down Expand Up @@ -157,6 +160,7 @@ class FunctionalTestsInsecureTransport: EchoTestCaseBase {
}

func testServerStreamingLotsOfMessages() {
guard self.runTimeSensitiveTests() else { return }
self.defaultTestTimeout = 15.0
XCTAssertNoThrow(try doTestServerStreaming(messages: lotsOfStrings))
}
Expand Down Expand Up @@ -198,11 +202,13 @@ class FunctionalTestsInsecureTransport: EchoTestCaseBase {
}

func testBidirectionalStreamingLotsOfMessagesBatched() throws {
guard self.runTimeSensitiveTests() else { return }
self.defaultTestTimeout = 15.0
XCTAssertNoThrow(try doTestBidirectionalStreaming(messages: lotsOfStrings))
}

func testBidirectionalStreamingLotsOfMessagesPingPong() throws {
guard self.runTimeSensitiveTests() else { return }
self.defaultTestTimeout = 15.0
XCTAssertNoThrow(try doTestBidirectionalStreaming(messages: lotsOfStrings, waitForEachResponse: true))
}
Expand Down
32 changes: 31 additions & 1 deletion Tests/GRPCTests/GRPCTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,16 @@ class GRPCTestCase: XCTestCase {
// locally; conditionally enable it based on the environment.
//
// https://docs.travis-ci.com/user/environment-variables/#default-environment-variables
private static var isLoggingEnabled = ProcessInfo.processInfo.environment["CI"] != "true"
private static let isCI = Bool(
fromTruthLike: ProcessInfo.processInfo.environment["CI"],
defaultingTo: false
)
private static let isLoggingEnabled = !isCI

private static let runTimeSensitiveTests = Bool(
fromTruthLike: ProcessInfo.processInfo.environment["ENABLE_TIMING_TESTS"],
defaultingTo: true
)

// `LoggingSystem.bootstrap` must be called once per process. This is the suggested approach to
// workaround this for XCTestCase.
Expand All @@ -46,6 +55,14 @@ class GRPCTestCase: XCTestCase {
super.setUp()
XCTAssertTrue(GRPCTestCase.isLoggingConfigured)
}

func runTimeSensitiveTests() -> Bool {
let shouldRun = GRPCTestCase.runTimeSensitiveTests
if !shouldRun {
print("Skipping '\(self.name)' as ENABLE_TIMING_TESTS=false")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This side effect feels like a code small; at least convert this into a func? Also, what will self.name evaluate to?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, let's make it a func. I'm okay with the side effect as it's only a print message in tests.

self.name looks like "-[FunctionalTestsMutualAuthentication testUnaryLotsOfRequests]"

}
return shouldRun
}
}

/// A `LogHandler` which does nothing with log messages.
Expand All @@ -66,3 +83,16 @@ struct BlackHole: LogHandler {
var metadata: Logger.Metadata = [:]
var logLevel: Logger.Level = .critical
}

fileprivate extension Bool {
init(fromTruthLike value: String?, defaultingTo defaultValue: Bool) {
switch value?.lowercased() {
case "0", "false", "no":
self = false
case "1", "true", "yes":
self = true
default:
self = defaultValue
}
}
}
1 change: 1 addition & 0 deletions Tests/GRPCTests/ServerWebTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ extension ServerWebTests {
}

func testUnaryLotsOfRequests() {
guard self.runTimeSensitiveTests() else { return }
// Sending that many requests at once can sometimes trip things up, it seems.
let clockStart = clock()
let numberOfRequests = 2_000
Expand Down