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

tests: fixed execution and compilation of SentrySwiftUI tests #4809

Merged
merged 10 commits into from
Feb 10, 2025
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
22 changes: 11 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,23 @@ jobs:
test-destination-os: "16.4"
device: "iPhone 14"
scheme: "Sentry"

# iOS 17
- runs-on: macos-14
platform: "iOS"
xcode: "15.4"
test-destination-os: "17.2"
device: "iPhone 15"
scheme: "Sentry"

# iOS 18
- runs-on: macos-15
platform: "iOS"
xcode: "16.2"
test-destination-os: "18.2"
device: "iPhone 16"
scheme: "Sentry"

# We don't run the unit tests on macOS 13 cause we run them on all on GH actions available iOS versions.
# The chance of missing a bug solely on tvOS 16 that doesn't occur on iOS, macOS 12 or macOS 14 is minimal.
# We are running tests on macOS 14 and later, as there were OS-internal changes introduced in succeeding versions.
Expand All @@ -112,14 +112,14 @@ jobs:
xcode: "15.4"
test-destination-os: "latest"
scheme: "Sentry"

# macOS 15
- runs-on: macos-15
platform: "macOS"
xcode: "16.2"
test-destination-os: "latest"
scheme: "Sentry"

# Catalyst. We test the latest version, as the risk something breaking on Catalyst and not
# on an older iOS or macOS version is low.
# In addition we are running tests on macOS 14, as there were OS-internal changes introduced in succeeding versions.
Expand All @@ -128,7 +128,7 @@ jobs:
xcode: "15.4"
test-destination-os: "latest"
scheme: "Sentry"

- runs-on: macos-15
platform: "Catalyst"
xcode: "16.2"
Expand All @@ -145,8 +145,8 @@ jobs:
xcode: "15.4"
test-destination-os: "17.5"
scheme: "Sentry"
# iOS 17

# iOS 17
- runs-on: macos-14
platform: "iOS"
xcode: "15.4"
Expand Down Expand Up @@ -185,14 +185,14 @@ jobs:
# We split building and running tests in two steps so we know how long running the tests takes.
- name: Build tests
id: build_tests
run: ./scripts/xcode-test.sh ${{matrix.platform}} ${{matrix.test-destination-os}} $GITHUB_REF_NAME build-for-testing "${{matrix.device}}" TestCI ${{matrix.scheme}}
run: ./scripts/xcode-test.sh ${{matrix.platform}} ${{matrix.test-destination-os}} $GITHUB_REF_NAME build-for-testing "${{matrix.device}}" TestCI "" ${{matrix.scheme}}

- name: Run tests
# We call a script with the platform so the destination
# passed to xcodebuild doesn't end up in the job name,
# because GitHub Actions don't provide an easy way of
# manipulating string in expressions.
run: ./scripts/xcode-test.sh ${{matrix.platform}} ${{matrix.test-destination-os}} $GITHUB_REF_NAME test-without-building "${{matrix.device}}" TestCI ${{matrix.scheme}}
run: ./scripts/xcode-test.sh ${{matrix.platform}} ${{matrix.test-destination-os}} $GITHUB_REF_NAME test-without-building "${{matrix.device}}" TestCI "" ${{matrix.scheme}}

- name: Slowest Tests
if: ${{ always() }}
Expand Down Expand Up @@ -255,7 +255,7 @@ jobs:
runs-on: macos-13
timeout-minutes: 20
needs: [build-test-server]

# There are several ways this test can flake. Sometimes threaded tests will just hang and the job will time out, other times waiting on expectations will take much longer than in a non-TSAN run and the test case will fail. We're making this nonfailable and will grep the logs to extract any actual thread sanitizer warnings to push to the PR, and ignore everything else.
continue-on-error: true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
buildConfiguration = "Test"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
<Testables>
<TestableReference
skipped = "NO">
Expand Down
33 changes: 31 additions & 2 deletions Tests/SentrySwiftUITests/SentryRedactModifierTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,44 @@ import XCTest

class SentryRedactModifierTests: XCTestCase {
func testViewMask() throws {
// -- Arrange --
let text = Text("Hello, World!")
// -- Act --
let redactedText = text.sentryReplayMask()
XCTAssertTrue(redactedText is ModifiedContent<Text, SentryReplayModifier>)
// -- Assert --
// We can not use the `type(of:)` or `is` to compare the response, because the type is erased to `AnyView`.
let typeOfRedactedText = String(describing: redactedText)

// As the actual type is part of SwiftUI and somewhat unpredictable, we need to have multiple assertions.
// Eventually this can be replaced with a more stable solution.
let candidates = [
"ModifiedContent<Text, SentryReplayModifier>",
"SwiftUI.ModifiedContent<SwiftUI.Text, SentrySwiftUI.SentryReplayModifier>"
]
XCTAssertTrue(
candidates.contains(where: { typeOfRedactedText.contains($0) }),
"Type did not match candidates: \(typeOfRedactedText)"
)
}

func testViewUnmask() throws {
// -- Arrange --
let text = Text("Hello, World!")
// -- Act --
let redactedText = text.sentryReplayUnmask()
XCTAssertTrue(redactedText is ModifiedContent<Text, SentryReplayModifier>)
// -- Assert --
// We can not use the `type(of:)` or `is` to compare the response, because the type is erased to `AnyView`.
let typeOfRedactedText = String(describing: redactedText)
// As the actual type is part of SwiftUI and somewhat unpredictable, we need to have multiple assertions.
// Eventually this can be replaced with a more stable solution.
let candidates = [
"ModifiedContent<Text, SentryReplayModifier>",
"SwiftUI.ModifiedContent<SwiftUI.Text, SentrySwiftUI.SentryReplayModifier>"
]
XCTAssertTrue(
candidates.contains(where: { typeOfRedactedText.contains($0) }),
"Type did not match candidates: \(typeOfRedactedText)"
)
}
}

Expand Down
10 changes: 9 additions & 1 deletion Tests/SentrySwiftUITests/SentryTraceViewModelTest.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#if canImport(UIKit) && canImport(SwiftUI)
@testable import Sentry
@_implementationOnly import SentryInternal
@testable import SentrySwiftUI
import XCTest

Expand Down Expand Up @@ -78,7 +79,14 @@ class SentryTraceViewModelTestCase: XCTestCase {

viewModel.finishSpan(spanId)
viewModel.viewDidAppear()


// The span is finished in the next main cycle, therefore we need to wait for it.
philprime marked this conversation as resolved.
Show resolved Hide resolved
let expectation = XCTestExpectation(description: "Wait for span to be finished.")
DispatchQueue.main.async {
expectation.fulfill()
}
wait(for: [expectation], timeout: 0.5)

// Verify that the span was popped and finished
XCTAssertNil(SentryPerformanceTracker.shared.activeSpanId(), "Active span should be nil after finishing the span.")

Expand Down
2 changes: 1 addition & 1 deletion scripts/xcode-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,5 @@ if [ $RUN_TEST_WITHOUT_BUILDING == true ]; then
test-without-building 2>&1 |
tee raw-test-output.log |
xcbeautify --quieter --renderer github-actions &&
slather coverage --configuration "$CONFIGURATION"
slather coverage --configuration "$CONFIGURATION" --scheme "$TEST_SCHEME"
fi
Loading