-
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-1218 App going background stops active RUM view #479
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,8 +59,8 @@ class UIKitRUMViewsHandlerTests: XCTestCase { | |
|
||
// Given | ||
predicate.resultByViewController = [ | ||
view1: .init(name: .mockRandom()), | ||
view2: .init(name: .mockRandom()), | ||
view1: .init(name: .mockRandom(), attributes: ["key1": "val1"]), | ||
view2: .init(name: .mockRandom(), attributes: ["key2": "val2"]), | ||
] | ||
|
||
// When | ||
|
@@ -74,8 +74,11 @@ class UIKitRUMViewsHandlerTests: XCTestCase { | |
let stopCommand = try XCTUnwrap(commandSubscriber.receivedCommands[1] as? RUMStopViewCommand) | ||
let startCommand2 = try XCTUnwrap(commandSubscriber.receivedCommands[2] as? RUMStartViewCommand) | ||
XCTAssertTrue(startCommand1.identity.equals(view1)) | ||
XCTAssertEqual(startCommand1.attributes as? [String: String], ["key1": "val1"]) | ||
XCTAssertTrue(stopCommand.identity.equals(view1)) | ||
XCTAssertEqual(stopCommand.attributes.count, 0) | ||
XCTAssertTrue(startCommand2.identity.equals(view2)) | ||
XCTAssertEqual(startCommand2.attributes as? [String: String], ["key2": "val2"]) | ||
} | ||
|
||
func testGivenAcceptingPredicate_whenViewDidAppear_itDoesNotStartTheSameRUMViewTwice() { | ||
|
@@ -193,4 +196,57 @@ class UIKitRUMViewsHandlerTests: XCTestCase { | |
// Then | ||
XCTAssertEqual(predicate.numberOfCalls, 1) | ||
} | ||
|
||
func testGivenRUMViewStarted_whenAppStateChanges_itStopsAndRestartsRUMView() throws { | ||
let viewName: String = .mockRandom() | ||
let viewControllerClassName: String = .mockRandom() | ||
let view = createMockView(viewControllerClassName: viewControllerClassName) | ||
|
||
// Given | ||
predicate.result = .init(name: viewName, attributes: ["foo": "bar"]) | ||
handler.notify_viewDidAppear(viewController: view, animated: .mockAny()) | ||
|
||
// When | ||
for _ in 0..<3 { | ||
NotificationCenter.default.post(name: UIApplication.willResignActiveNotification, object: nil) | ||
} | ||
dateProvider.advance(bySeconds: 1) | ||
for _ in 0..<3 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's quite unclear why we call it 3 times - I guess it's just for sanity, no? Maybe it's worth expressing somehow (either with an inline comment or by labelling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed ✅ |
||
NotificationCenter.default.post(name: UIApplication.didBecomeActiveNotification, object: nil) | ||
} | ||
|
||
// Then | ||
XCTAssertEqual(commandSubscriber.receivedCommands.count, 3) | ||
|
||
let stopCommand = try XCTUnwrap(commandSubscriber.receivedCommands[1] as? RUMStopViewCommand) | ||
XCTAssertTrue(stopCommand.identity.equals(view)) | ||
XCTAssertEqual(stopCommand.attributes.count, 0) | ||
XCTAssertEqual(stopCommand.time, .mockDecember15th2019At10AMUTC()) | ||
|
||
let startCommand = try XCTUnwrap(commandSubscriber.receivedCommands[2] as? RUMStartViewCommand) | ||
XCTAssertTrue(startCommand.identity.equals(view)) | ||
XCTAssertEqual(startCommand.path, viewControllerClassName) | ||
XCTAssertEqual(startCommand.name, viewName) | ||
XCTAssertEqual(startCommand.attributes as? [String: String], ["foo": "bar"]) | ||
XCTAssertEqual(startCommand.time, .mockDecember15th2019At10AMUTC() + 1) | ||
} | ||
|
||
func testGivenRUMViewDidNotStart_whenAppStateChanges_itDoesNothing() throws { | ||
let viewName: String = .mockRandom() | ||
|
||
// Given | ||
predicate.result = .init(name: viewName, attributes: ["foo": "bar"]) | ||
|
||
// When | ||
for _ in 0..<3 { | ||
NotificationCenter.default.post(name: UIApplication.willResignActiveNotification, object: nil) | ||
} | ||
dateProvider.advance(bySeconds: 1) | ||
for _ in 0..<3 { | ||
NotificationCenter.default.post(name: UIApplication.didBecomeActiveNotification, object: nil) | ||
} | ||
|
||
// Then | ||
XCTAssertEqual(commandSubscriber.receivedCommands.count, 0) | ||
} | ||
} |
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.
What if the
lastActiveAppVC
is notnil
but doesn't match thelastStartedViewController
? When the app comes back in background, won't you be starting the wrong RUM View ?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.
Also, I'm wondering if we need the
lastActiveAppVC
property at all. As far as I can see, we either set it tolastStartedViewController
or tonil
, so can't we simply do:lastStartedViewController
,lastStartedViewController
?
If there's sth special about
lastActiveAppVC
that I miss, I think it's worth adding it in the property comment.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.
@xgouchet good point.
now i remove
lastActiveAppVC
along with @ncreated comments below. it was introduced to guard against multiple notifications received but probably not really needed.