-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
test(replay): Add tests for session expiration #7253
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
Conversation
Replay SDK metrics 🚀
develop |
Revision | LCP | CLS | CPU | JS heap avg | JS heap max | netTx | netRx | netCount | netTime |
---|---|---|---|---|---|---|---|---|---|
e60cd02 | +56.25 ms | -0.00 ms | +6.32 pp | +927.44 kB | +1.06 MB | +2.21 kB | +41 B | +1 | +117.55 ms |
e25c067 | +48.34 ms | +0.00 ms | +5.59 pp | +926.37 kB | +1.05 MB | +2.22 kB | +41 B | +1 | +65.23 ms |
b1b249b | +43.88 ms | +0.00 ms | +4.80 pp | +937.99 kB | +1.05 MB | +2.22 kB | +41 B | +1 | +111.56 ms |
12e34d4 | +28.57 ms | +0.00 ms | +5.77 pp | +930.12 kB | +1.04 MB | +2.26 kB | +41 B | +1 | +109.67 ms |
c46c56c | +65.45 ms | -0.00 ms | +5.38 pp | +930.26 kB | +1.07 MB | +2.21 kB | +41 B | +1 | +91.29 ms |
7f4c4ec | +56.64 ms | -0.00 ms | +5.57 pp | +927.42 kB | +1.06 MB | +2.21 kB | +41 B | +1 | +110.83 ms |
00d2360 | +55.18 ms | +0.00 ms | +2.23 pp | +934.14 kB | +1.05 MB | +2.22 kB | +41 B | +1 | +71.65 ms |
Last updated: Wed, 22 Feb 2023 15:46:50 GMT
size-limit report 📦
|
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 had some questions but overall LGTM. As I said I don't wanna block you too long with this so feel free to go with what we have right now.
expect(incrementalSnapshots1).toEqual( | ||
expect.arrayContaining([ | ||
{ | ||
source: 1, | ||
positions: [ | ||
{ | ||
id: 9, | ||
timeOffset: expect.any(Number), | ||
x: expect.any(Number), | ||
y: expect.any(Number), | ||
}, | ||
], | ||
}, | ||
]), | ||
); |
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'm not entirely sure what this snapshot element represents - should we add a comment what we're checking here?
Also related but no action required: Any specific reason why we're checking this explicitly over using toMatchSnapshot
? (not saying this needs to change)
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.
the reason was that I didn't want to test the exact x/y values as I figured they may be flaky - and the toMatchSnapshot
stuff does string comparison, basically 😬
I'll add a comment - not sure if this actually helps us at all, my thought was to test that something reasonable is sent, but since it is sadly not stable between browsers, it's pretty diluted now 😅
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.
Yeah, I also noticed that incremental snapshots are quite browser-specific... In the errors tests, I opted to check for "length of the incr. snapshot > SomeLowerBoundIObservedDuringTestFlakesMinusOne" 😅
RE flakes: My "replay across multiple pages" test snapshot-tests incr. snapshots and so far I haven't noticed flakes (🤞). Perhaps it's still worth a shot? Although, I'm only testing on chromium in this test...
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.
Jup, I suspect the reason it works well there is that it's chromium only 😅
const replay = await getReplaySnapshot(page); | ||
// @ts-ignore private api | ||
expect(replay._isEnabled).toEqual(true); | ||
// @ts-ignore private api | ||
expect(replay._isPaused).toEqual(false); | ||
|
||
// Now we trigger a blur event, which should move the session to paused mode | ||
await page.evaluate(() => { | ||
window.dispatchEvent(new Event('blur')); | ||
}); | ||
|
||
const replay2 = await getReplaySnapshot(page); | ||
// @ts-ignore private api | ||
expect(replay2._isEnabled).toEqual(true); | ||
// @ts-ignore private api | ||
expect(replay2._isPaused).toEqual(true); | ||
|
||
// Trigger an action, should re-start the recording | ||
await page.click('#button2'); | ||
|
||
const replay3 = await getReplaySnapshot(page); | ||
// @ts-ignore private api | ||
expect(replay3._isEnabled).toEqual(true); | ||
// @ts-ignore private api | ||
expect(replay3._isPaused).toEqual(false); | ||
|
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 know we already have such tests but I'm not sure if we want to add more of them: IMO we're inspecting intrinsics too much for an integration test by checking the internal state of the ReplayContainer
.
That being said, I get that it's hard to check that nothing happens in this situation otherwise. So my ramble is probably pointless 😅
IIRC we already have some unit integration tests for paused replays. Any chance we could use/adjust them instead?
But I don't want to block this too long so if there's no feasible option, let's just roll with this test instead!
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.
Yeah, I totally get you. I mean we do have some unitgration (xD) tests for this, so we may also skip this here - I figured this is a bit more "real" as it actually waits the correct time and we have less/no mocking/overwriting of stuff. IMHO it's "OK" to have this for now, but we should keep an eye on this so this doesn't go overboard 😅
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.
unitgration
I love it 😅
Sure, sounds fair - let's just try to minimize using this in the future whenever there's another possiblilty.
c87d7e9
to
1431a32
Compare
packages/replay/src/replay.ts
Outdated
public timeouts = { | ||
sessionIdle: SESSION_IDLE_DURATION, | ||
maxSessionLife: MAX_SESSION_LIFE, | ||
}; |
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.
Is there a way we only allow writes to these timeouts during tests? I worry some crafty people may change these values to something unsupported.
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.
you'd have to reach into a private object with no docs whatsover 😅 (e.g. replay._replay.timeouts
). I'll add @hidden
, actually. Other than this, not sure 😅 but at this point people could be overwriting anything in there basically xD
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.
Could we make this into getter/setter and have the setters check for an env var that's set during test? Maybe you're right though it's probably overkill
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.
IMHO if we do that users can still overwrite it as well if they really want 😅 and we'd have to look this up on window
etc. which IMHO would also be a bit weird, so I'd leave it like this for now. If we find this is abused we can still change it later, I'd say.
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've made this readonly
& const
, hopefully making it clear that this cannot/should not be overwritten!
bb75b72
to
cbd0c97
Compare
004549a
to
86746b5
Compare
So, finally I extracted the one new test that keeps flaking out, will make a new PR for this specific test so we can finally merge this at least 🙈 |
86746b5
to
9168095
Compare
This PR makes the session expiration overwritable, so we can test this without waiting for 30/60 mins 😜
I added three tests:
ref #7044