Skip to content

Conversation

@mokagio
Copy link
Contributor

@mokagio mokagio commented Apr 20, 2023

  • Makes a few tests XCTestCase subclasses instead of ParselyTestCase. They didn't need access to the tracker test instance
  • Removes state from EventQueueTests and EngagedTimeTests. Now each test methods create objects whose lifecycle ends together with the test. They will not survive in memory after the test finished.
  • To make that possible, refactors ParselyTestCase to offer a single API to generate a Parsely instance for tests configured to call hardShutdown() when the test finishes.

My editor removed whitespaces from the files. I recommend hiding them when reviewing to reduce the noise. Also, commit by commit review might be clearer.

CI runs only on PRs against master. I obviously run the tests locally and verified everything still works but feel free to doublecheck 😄

Comment on lines +12 to 22
func makePareslyTracker() -> Parsely {
let tracker = Parsely.getInstance()

// Note that because we call addTeardownBlock, this method needs to be defined within an
// XCTestCase
addTeardownBlock {
tracker.hardShutdown()
}

return tracker
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using addTeardownBlock in the context of makeParselyTracker() makes sure that any test calling this method will call hardShutdown() on completion. This gives us the ability to call the method and assign its return value to an instance scoped at the test method without the risk of it remaining in memory after the test finishes.

@mokagio mokagio changed the title Remove state from EventQueueTests Remove state from EventQueueTests and other test refinements Apr 20, 2023
@mokagio mokagio requested a review from crazytonyli April 20, 2023 05:26
@mokagio mokagio added this to the 0.2.2 milestone Apr 20, 2023
Copy link
Contributor

@crazytonyli crazytonyli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@crazytonyli crazytonyli changed the base branch from mokagio/spm-tests to master April 23, 2023 23:54
@crazytonyli crazytonyli reopened this Apr 23, 2023
@crazytonyli
Copy link
Contributor

ParselyTrackerTests.SamplerTests
testBackoff, Asynchronous wait failed: Exceeded timeout of 13.5 seconds, with unfulfilled expectations: "Wait for heartbeat".
/Users/runner/work/AnalyticsSDK-iOS/AnalyticsSDK-iOS/Tests/SamplerTests.swift:64

      }
      waitForExpectations(timeout: heartbeatDeliveryInterval, handler: nil)

The first GitHub Action run failed at a flaky test which should be fixed in #79

@mokagio mokagio force-pushed the mokagio/test-without-shared-instance branch from 4c09a85 to ec6b4bd Compare April 25, 2023 10:25
@mokagio mokagio merged commit 3b49cd8 into master Apr 26, 2023
@mokagio mokagio deleted the mokagio/test-without-shared-instance branch April 26, 2023 01:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants