Skip to content

Commit

Permalink
Chore : Fixing CI (#2889)
Browse files Browse the repository at this point in the history
Fixing CI

Co-authored-by: Philipp Hofmann <philipp.hofmann@sentry.io>
  • Loading branch information
brustolin and philipphofmann authored Apr 12, 2023
1 parent 7192d9e commit 89d72e7
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 57 deletions.
32 changes: 0 additions & 32 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -326,38 +326,6 @@ jobs:
~/Library/Logs/scan/*.log
./fastlane/test_output/**
# macos-11 doesn't have a simulator for iOS 12
ui-tests-swift-ios-12:
name: UI Tests on iOS 12 Simulator
runs-on: macos-11
strategy:
matrix:
target: ['ios_swift', 'ios_objc', 'tvos_swift']

steps:
- uses: actions/checkout@v3

# GH action images don't have an iOS 12.4 simulator. Therefore we have to download and install the simulator manually.
- name: Install iOS 12.4 simulator
run: |
gem install xcode-install
xcversion simulators --install='iOS 12.4'
xcrun simctl create custom-test-device "iPhone 8" "com.apple.CoreSimulator.SimRuntime.iOS-12-4"
# GitHub Actions sometimes fail to launch the UI tests. Therefore we retry
- name: Run Fastlane
run: for i in {1..2}; do fastlane ui_tests_${{matrix.target}} device:"iPhone 8 (12.4)" address_sanitizer:false && break ; done
shell: sh

- name: Archiving Raw Test Logs
uses: actions/upload-artifact@v3
if: ${{ failure() || cancelled() }}
with:
name: raw-uitest-output-${{matrix.target}}-ios-12
path: |
~/Library/Logs/scan/*.log
./fastlane/test_output/**
ui-tests-address-sanitizer:
name: UI Tests with Address Sanitizer
runs-on: macos-12
Expand Down
11 changes: 9 additions & 2 deletions Sources/Sentry/SentryAppStartTracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ - (instancetype)initWithCurrentDateProvider:(id<SentryCurrentDateProvider>)curre
self.wasInBackground = NO;
self.didFinishLaunchingTimestamp = [currentDateProvider date];
self.enablePreWarmedAppStartTracing = enablePreWarmedAppStartTracing;
self.isRunning = NO;
}
return self;
}
Expand Down Expand Up @@ -116,6 +117,8 @@ - (void)start
# if SENTRY_HAS_UIKIT
[self.appStateManager start];
# endif

self.isRunning = YES;
}

- (void)buildAppStartMeasurement
Expand Down Expand Up @@ -208,8 +211,8 @@ - (void)buildAppStartMeasurement
SentrySDK.appStartMeasurement = appStartMeasurement;
};

// With only running this once we know that the process is a new one when the following
// code is executed.
// With only running this once we know that the process is a new one when the following
// code is executed.
// We need to make sure the block runs on each test instead of only once
# if TEST
block();
Expand Down Expand Up @@ -285,6 +288,10 @@ - (void)stop
[NSNotificationCenter.defaultCenter removeObserver:self
name:UIApplicationDidEnterBackgroundNotification
object:nil];

# if TEST
self.isRunning = NO;
# endif
}

- (void)dealloc
Expand Down
2 changes: 2 additions & 0 deletions Sources/Sentry/include/SentryAppStartTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ NS_ASSUME_NONNULL_BEGIN
@interface SentryAppStartTracker : NSObject
SENTRY_NO_INIT

@property (nonatomic) BOOL isRunning;

- (instancetype)initWithCurrentDateProvider:(id<SentryCurrentDateProvider>)currentDateProvider
dispatchQueueWrapper:(SentryDispatchQueueWrapper *)dispatchQueueWrapper
appStateManager:(SentryAppStateManager *)appStateManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,57 +40,63 @@ class SentryAppStartTrackingIntegrationTests: NotificationCenterTestCase {
sut.stop()
}

func testAppStartMeasuringEnabledAndSampleRate_DoesUpdatesAppState() {
func testAppStartMeasuringEnabledAndSampleRate_properlySetupTracker() throws {
sut.install(with: fixture.options)

let tracker = try XCTUnwrap(Dynamic(sut).tracker.asObject as? SentryAppStartTracker, "SentryAppStartTrackingIntegration should have a tracker")
try assertTrackerSetupAndRunning(tracker)
}

func testUnistall_stopsTracker() throws {
sut.install(with: fixture.options)

let tracker = try XCTUnwrap(Dynamic(sut).tracker.asObject as? SentryAppStartTracker, "SentryAppStartTrackingIntegration should have a tracker")
try assertTrackerSetupAndRunning(tracker)
sut.uninstall()

uiWindowDidBecomeVisible()

XCTAssertNotNil(SentrySDK.getAppStartMeasurement())
let isRunning = Dynamic(tracker).isRunning.asBool ?? true
XCTAssertFalse(isRunning, "AppStartTracking should not be running")
}

func testNoSampleRate_DoesNotUpdatesAppState() {
func testNoSampleRate_noTracker() {
let options = fixture.options
options.tracesSampleRate = 0.0
options.tracesSampler = nil
sut.install(with: options)

uiWindowDidBecomeVisible()

XCTAssertNil(SentrySDK.getAppStartMeasurement())

let tracker = Dynamic(sut).tracker.asAnyObject as? SentryAppStartTracker
XCTAssertNil(tracker)
}

func testHybridSDKModeEnabled_DoesUpdatesAppState() {
func testHybridSDKModeEnabled_properlySetupTracker() throws {
PrivateSentrySDKOnly.appStartMeasurementHybridSDKMode = true

let options = fixture.options
options.tracesSampleRate = 0.0
options.tracesSampler = nil
sut.install(with: options)

uiWindowDidBecomeVisible()

XCTAssertNotNil(SentrySDK.getAppStartMeasurement())
let tracker = try XCTUnwrap(Dynamic(sut).tracker.asObject as? SentryAppStartTracker, "SentryAppStartTrackingIntegration should have a tracker")
try assertTrackerSetupAndRunning(tracker)
}

func testOnlyAppStartMeasuringEnabled_DoesNotUpdatesAppState() {
func testOnlyAppStartMeasuringEnabled_noTracker() {
let options = fixture.options
options.tracesSampleRate = 0.0
options.tracesSampler = nil
sut.install(with: options)

uiWindowDidBecomeVisible()

XCTAssertNil(SentrySDK.getAppStartMeasurement())
let tracker = Dynamic(sut).tracker.asAnyObject as? SentryAppStartTracker
XCTAssertNil(tracker)
}

func testAutoPerformanceTrackingDisabled_DoesNotUpdatesAppState() {
func testAutoPerformanceTrackingDisabled_noTracker() {
let options = fixture.options
options.enableAutoPerformanceTracing = false
sut.install(with: options)

uiWindowDidBecomeVisible()

XCTAssertNil(SentrySDK.getAppStartMeasurement())
let tracker = Dynamic(sut).tracker.asAnyObject as? SentryAppStartTracker
XCTAssertNil(tracker)
}

func test_PerformanceTrackingDisabled() {
Expand All @@ -100,6 +106,22 @@ class SentryAppStartTrackingIntegrationTests: NotificationCenterTestCase {

XCTAssertFalse(result)
}

func assertTrackerSetupAndRunning(_ tracker: SentryAppStartTracker) throws {
let dateProvider = Dynamic(tracker).currentDate.asObject as? DefaultCurrentDateProvider

XCTAssertEqual(dateProvider, DefaultCurrentDateProvider.sharedInstance())

_ = try XCTUnwrap(Dynamic(tracker).dispatchQueue.asAnyObject as? SentryDispatchQueueWrapper, "Tracker does not have a dispatch queue.")

let appStateManager = Dynamic(tracker).appStateManager.asObject as? SentryAppStateManager

XCTAssertEqual(appStateManager, SentryDependencyContainer.sharedInstance().appStateManager)

_ = try XCTUnwrap(Dynamic(tracker).sysctl.asObject as? SentrySysctl, "Tracker does not have a Sysctl")

XCTAssertTrue(tracker.isRunning, "AppStartTracking should be running")
}

}
#endif
19 changes: 17 additions & 2 deletions Tests/SentryTests/SentryViewHierarchyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import XCTest
#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
class SentryViewHierarchyTests: XCTestCase {
private class Fixture {

let uiApplication = TestSentryUIApplication()

var sut: SentryViewHierarchy {
Expand All @@ -16,10 +15,26 @@ class SentryViewHierarchyTests: XCTestCase {

override func setUp() {
super.setUp()

fixture = Fixture()
SentryDependencyContainer.sharedInstance().application = fixture.uiApplication
}

override func setUpWithError() throws {
try super.setUpWithError()

/**
* This test is making iOS 13 simulator hang in GH workflow,
* thats why we need to check for iOS 13 or later.
* By testing this in the other versions of iOS we guarantee the behavior
* mean while, running an iOS 12 sample with Saucelabs ensures this feature
* is not crashing the app.
*/
guard #available(iOS 13, *) else {
throw XCTSkip("Skipping for iOS < 13")
}
}

override func tearDown() {
super.tearDown()
clearTestState()
Expand Down Expand Up @@ -164,7 +179,7 @@ class SentryViewHierarchyTests: XCTestCase {
ex.fulfill()
XCTAssertTrue(Thread.isMainThread)
}

let dispatch = DispatchQueue(label: "background")
dispatch.async {
let _ = sut.fetch()
Expand Down

0 comments on commit 89d72e7

Please sign in to comment.