From 8775a45a38b4b2e770adbeee39045be3f5d3e69d Mon Sep 17 00:00:00 2001 From: Alex Hoppen Date: Wed, 19 Feb 2025 13:11:41 -0800 Subject: [PATCH] Do not measure perform performance in CI When executing in Swift CI, run the block to make sure it doesn't hit any assertions because we don't look at performance numbers in CI and CI nodes can have variable performance characteristics if they are not bare-metal. Anywhere else, run XCTest's `measure` function to measure the performance of the block. Fixes #939 rdar://145139964 --- .../WhitespaceLinterPerformanceTests.swift | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Tests/SwiftFormatPerformanceTests/WhitespaceLinterPerformanceTests.swift b/Tests/SwiftFormatPerformanceTests/WhitespaceLinterPerformanceTests.swift index c969d016a..b7c8b2110 100644 --- a/Tests/SwiftFormatPerformanceTests/WhitespaceLinterPerformanceTests.swift +++ b/Tests/SwiftFormatPerformanceTests/WhitespaceLinterPerformanceTests.swift @@ -5,11 +5,19 @@ import XCTest @_spi(Testing) import _SwiftFormatTestSupport final class WhitespaceLinterPerformanceTests: DiagnosingTestCase { + /// When executing in Swift CI, run the block to make sure it doesn't hit any assertions because we don't look at + /// performance numbers in CI and CI nodes can have variable performance characteristics if they are not bare-metal. + /// + /// Anywhere else, run XCTest's `measure` function to measure the performance of the block. + private func measureIfNotInCI(_ block: () -> Void) { + if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] != nil { + block() + } else { + measure { block() } + } + } + func testWhitespaceLinterPerformance() throws { - #if os(Windows) - // https://github.com/swiftlang/swift-format/issues/939 - throw XCTSkip("This test is flaky on Windows") - #endif let input = String( repeating: """ import SomeModule @@ -50,7 +58,7 @@ final class WhitespaceLinterPerformanceTests: DiagnosingTestCase { count: 20 ) - measure { performWhitespaceLint(input: input, expected: expected) } + measureIfNotInCI { performWhitespaceLint(input: input, expected: expected) } } /// Perform whitespace linting by comparing the input text from the user with the expected