From 128f12adf25c036725d0ebbb64feaed8d8749cdc Mon Sep 17 00:00:00 2001 From: Dhiogo Brustolin Date: Thu, 30 Jun 2022 11:04:04 +0200 Subject: [PATCH 1/4] Update SentryANRTrackerTests.swift --- .../Integrations/ANR/SentryANRTrackerTests.swift | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Tests/SentryTests/Integrations/ANR/SentryANRTrackerTests.swift b/Tests/SentryTests/Integrations/ANR/SentryANRTrackerTests.swift index f23098b0753..ec4b7abb3d6 100644 --- a/Tests/SentryTests/Integrations/ANR/SentryANRTrackerTests.swift +++ b/Tests/SentryTests/Integrations/ANR/SentryANRTrackerTests.swift @@ -136,18 +136,19 @@ class SentryANRTrackerTests: XCTestCase, SentryANRTrackerDelegate { secondListener.anrDetectedExpectation.isInverted = true anrDetectedExpectation.isInverted = true - let mainBlockExpectation = expectation(description: "Main Block") - + //We cant use expectation because we don't control how many times blockBeforeMainBlock is called + var beforeMainCalled = false + fixture.dispatchQueue.blockBeforeMainBlock = { self.sut.clear() - mainBlockExpectation.fulfill() + beforeMainCalled = true return true } sut.addListener(secondListener) start() - - wait(for: [anrDetectedExpectation, anrStoppedExpectation, mainBlockExpectation, secondListener.anrStoppedExpectation, secondListener.anrDetectedExpectation], timeout: waitTimeout) + wait(for: [anrDetectedExpectation, anrStoppedExpectation, secondListener.anrStoppedExpectation, secondListener.anrDetectedExpectation], timeout: waitTimeout) + XCTAssertTrue(beforeMainCalled) } func anrDetected() { From 1299a3a7979e0aba05d3798afccc7cd4d95b2271 Mon Sep 17 00:00:00 2001 From: Dhiogo Brustolin Date: Thu, 30 Jun 2022 12:29:39 +0200 Subject: [PATCH 2/4] Update SentryANRTrackerTests.swift --- Tests/SentryTests/Integrations/ANR/SentryANRTrackerTests.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Tests/SentryTests/Integrations/ANR/SentryANRTrackerTests.swift b/Tests/SentryTests/Integrations/ANR/SentryANRTrackerTests.swift index ec4b7abb3d6..9a83a8a7eca 100644 --- a/Tests/SentryTests/Integrations/ANR/SentryANRTrackerTests.swift +++ b/Tests/SentryTests/Integrations/ANR/SentryANRTrackerTests.swift @@ -137,6 +137,8 @@ class SentryANRTrackerTests: XCTestCase, SentryANRTrackerDelegate { anrDetectedExpectation.isInverted = true //We cant use expectation because we don't control how many times blockBeforeMainBlock is called + //Having a second Listener may cause the APP Hang tracker to execute more than once before the end of the test + var beforeMainCalled = false fixture.dispatchQueue.blockBeforeMainBlock = { From 782bfb287cbe6ad562710a61287edaa6c087ce92 Mon Sep 17 00:00:00 2001 From: Dhiogo Brustolin Date: Thu, 30 Jun 2022 12:35:59 +0200 Subject: [PATCH 3/4] Update SentryANRTrackerTests.swift --- .../Integrations/ANR/SentryANRTrackerTests.swift | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Tests/SentryTests/Integrations/ANR/SentryANRTrackerTests.swift b/Tests/SentryTests/Integrations/ANR/SentryANRTrackerTests.swift index 9a83a8a7eca..5be77e0395f 100644 --- a/Tests/SentryTests/Integrations/ANR/SentryANRTrackerTests.swift +++ b/Tests/SentryTests/Integrations/ANR/SentryANRTrackerTests.swift @@ -136,21 +136,21 @@ class SentryANRTrackerTests: XCTestCase, SentryANRTrackerDelegate { secondListener.anrDetectedExpectation.isInverted = true anrDetectedExpectation.isInverted = true - //We cant use expectation because we don't control how many times blockBeforeMainBlock is called - //Having a second Listener may cause the APP Hang tracker to execute more than once before the end of the test - - var beforeMainCalled = false + let mainBlockExpectation = expectation(description: "Main Block") + //Having a second Listener may cause the tracker to execute more than once before the end of the test + mainBlockExpectation.assertForOverFulfill = true + fixture.dispatchQueue.blockBeforeMainBlock = { self.sut.clear() - beforeMainCalled = true + mainBlockExpectation.fulfill() return true } sut.addListener(secondListener) start() - wait(for: [anrDetectedExpectation, anrStoppedExpectation, secondListener.anrStoppedExpectation, secondListener.anrDetectedExpectation], timeout: waitTimeout) - XCTAssertTrue(beforeMainCalled) + wait(for: [anrDetectedExpectation, anrStoppedExpectation, mainBlockExpectation, secondListener.anrStoppedExpectation, secondListener.anrDetectedExpectation], timeout: waitTimeout) + } func anrDetected() { From 61451fd7393961a507a60aa29e33ca943817fb71 Mon Sep 17 00:00:00 2001 From: Dhiogo Brustolin Date: Thu, 30 Jun 2022 12:48:19 +0200 Subject: [PATCH 4/4] Update SentryANRTrackerTests.swift --- Tests/SentryTests/Integrations/ANR/SentryANRTrackerTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/SentryTests/Integrations/ANR/SentryANRTrackerTests.swift b/Tests/SentryTests/Integrations/ANR/SentryANRTrackerTests.swift index 5be77e0395f..84c02a64e14 100644 --- a/Tests/SentryTests/Integrations/ANR/SentryANRTrackerTests.swift +++ b/Tests/SentryTests/Integrations/ANR/SentryANRTrackerTests.swift @@ -139,7 +139,7 @@ class SentryANRTrackerTests: XCTestCase, SentryANRTrackerDelegate { let mainBlockExpectation = expectation(description: "Main Block") //Having a second Listener may cause the tracker to execute more than once before the end of the test - mainBlockExpectation.assertForOverFulfill = true + mainBlockExpectation.assertForOverFulfill = false fixture.dispatchQueue.blockBeforeMainBlock = { self.sut.clear()