Files
swift-mirror/validation-test/stdlib/ErrorProtocol.swift
David Zarzycki 283713d61d [Testing] Formalize stress tests
Stress tests are, by definition, stressful. They intentionally burn a
lot of resources by using randomness to hopefully surface state machine
bugs. Additionally, many stress tests are multi-threaded these days and
they may attempt to use all of the available CPUs to better uncover
bugs. In isolation, this is not a problem, but the test suite as a whole
assumes that individual tests are single threaded and therefore running
multiple stress tests at once can quickly spiral out of control.

This change formalizes stress tests and then treats them like long
tests, i.e. tested via 'check-swift-all' and otherwise opt-in.

Finally, with this change, the CI build bots might need to change if
they are still only testing 'validation' instead of all of the tests.
I see three options:

1) Run all of the tests. -- There are very few long tests left these
   days, and the additional costs seems small relative to the cost of
   the whole validation test suite before this change.
2) Continue checking 'validation', now sans stress tests.
3) Check 'validation', *then* the stress tests. If the former doesn't
   pass, then there is no point in the latter, and by running the stress
   tests separately, they stand a better chance of uncovering bugs and
   not overwhelming build bot resources.
2018-03-20 21:45:28 -04:00

56 lines
1.5 KiB
Swift

// RUN: %target-run-simple-swift
// REQUIRES: executable_test
// REQUIRES: stress_test
// REQUIRES: objc_interop
// UNSUPPORTED: nonatomic_rc
import SwiftPrivate
import StdlibUnittest
import Foundation
enum SomeError : Error {
case GoneToFail
}
struct ErrorAsNSErrorRaceTest : RaceTestWithPerTrialData {
class RaceData {
let error: Error
init(error: Error) {
self.error = error
}
}
func makeRaceData() -> RaceData {
return RaceData(error: SomeError.GoneToFail)
}
func makeThreadLocalData() {}
func thread1(_ raceData: RaceData, _: inout Void) -> Observation3Int {
let ns = raceData.error as NSError
// Use valueForKey to bypass bridging, so we can verify that the identity
// of the unbridged NSString object is stable.
let domainInt: Int = unsafeBitCast(ns.value(forKey: "domain").map { $0 as AnyObject },
to: Int.self)
let code: Int = ns.code
let userInfoInt: Int = unsafeBitCast(ns.value(forKey: "userInfo").map { $0 as AnyObject },
to: Int.self)
return Observation3Int(domainInt, code, userInfoInt)
}
func evaluateObservations(
_ observations: [Observation3Int],
_ sink: (RaceTestObservationEvaluation) -> Void
) {
sink(evaluateObservationsAllEqual(observations))
}
}
var ErrorRaceTestSuite = TestSuite("Error races")
ErrorRaceTestSuite.test("NSError bridging") {
runRaceTest(ErrorAsNSErrorRaceTest.self, operations: 1000)
}
runAllTests()