-
Notifications
You must be signed in to change notification settings - Fork 135
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
RUMM-1765 Fix foreground app state reporting in AppStateListener
- part 5 🏁
#696
Conversation
…ion on app foreground state as `.active` is not enough to infer if app is in foreground. It might be also in foreground while the app state is `.inactive`.
1dacc68
to
7a6548a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch 👌
|
||
XCTAssertEqual(history2.currentState.date.timeIntervalSince(history1.currentState.date), 1.0) | ||
// When | ||
(0..<1).forEach { _ in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will do a single iteration :)
(0..<1).forEach { _ in | |
(0..<10).forEach { _ in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one need to be addressed before merging. All good otherwise!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ops! Fixed, good catch 💪
) | ||
func testWhenAppTransitionsBetweenForegroundAndBackground_itComputesTotalForegroundDuration() { | ||
let numberOfForegroundSnapshots: Int = .mockRandom(min: 0, max: 20) | ||
let numberOfBackgroundSnapshots: Int = .mockRandom(min: numberOfForegroundSnapshots == 0 ? 1 : 0, max: 20) // must include at least one snapshot |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just
let numberOfBackgroundSnapshots: Int = .mockRandom(min: numberOfForegroundSnapshots == 0 ? 1 : 0, max: 20) // must include at least one snapshot | |
let numberOfBackgroundSnapshots: Int = .mockRandom(min: 1, max: 20) // must include at least one snapshot |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to also cover scenario where numberOfBackgroundSnapshots
is 0
. And this couldn't be done if numberOfForegroundSnapshots
is 0
too, because we need at least one snapshot for:
initialSnapshot: allSnapshots[0],
In general, in this fuzzy test I wanted to cover all possibilities:
- app only in foreground,
- app only in background,
- app in both foreground and background.
What and why?
📦 This is the final PR closing topic of tracking app launch events (and crashes). While testing it (with new options added to debug UI 👇), I found a bug 🐞 in
AppStateListener
, which I'm solving in this PR.How?
Problem was that
AppStateListener
was only consideringUIApplication.State.active
as "foreground" application state, whereas app lifecycle is more complex than that and it can be also in "foreground" while in.inactive
state:Because
.inactive
was not considered "foreground", any event tracked during application launch (e.g. fromapplication(_:didFinishLaunching:)
) was starting "Background" instead of "ApplicationLaunch" view. I fixed this issue by exposingAppState
directly fromAppStateListener
and letting other components decide by their own on handling particular states.🏁 Final Testing
With all logic in place, I made last tests, ensuring everything works as expected. Here are some explored scenarios:
Review checklist