Skip to content

Commit 12c011e

Browse files
👷 remove watch_cookie_without_lock experimental feature flag (#3773)
1 parent 7fec7ea commit 12c011e

File tree

3 files changed

+101
-127
lines changed

3 files changed

+101
-127
lines changed

‎packages/core/src/domain/session/sessionStore.spec.ts‎

Lines changed: 89 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import type { Clock } from '../../../test'
2-
import { mockClock, createFakeSessionStoreStrategy, mockExperimentalFeatures } from '../../../test'
2+
import { mockClock, createFakeSessionStoreStrategy } from '../../../test'
33
import type { InitConfiguration, Configuration } from '../configuration'
44
import { display } from '../../tools/display'
5-
import { ExperimentalFeature } from '../../tools/experimentalFeatures'
65
import type { SessionStore } from './sessionStore'
76
import { STORAGE_POLL_DELAY, startSessionStore, selectSessionStoreStrategyType } from './sessionStore'
87
import {
@@ -466,115 +465,94 @@ describe('session store', () => {
466465
})
467466

468467
describe('regular watch', () => {
469-
;[true, false].forEach((useExperimentalFeature) => {
470-
describe(`when 'watch_cookie_without_lock' experimental feature is ${useExperimentalFeature}`, () => {
471-
beforeEach(() => {
472-
if (useExperimentalFeature) {
473-
mockExperimentalFeatures([ExperimentalFeature.WATCH_COOKIE_WITHOUT_LOCK])
474-
}
475-
})
476-
477-
it('when session not in cache and session not in store, should store the expired session', () => {
478-
setupSessionStore()
479-
480-
clock.tick(STORAGE_POLL_DELAY)
481-
482-
expectSessionToBeExpiredInStore()
483-
expect(sessionStoreManager.getSession().id).toBeUndefined()
484-
expect(expireSpy).not.toHaveBeenCalled()
485-
expect(sessionStoreStrategy.persistSession).toHaveBeenCalled()
486-
})
487-
488-
it('when session in cache and session not in store, should expire session', () => {
489-
setupSessionStore(createSessionState(FakeTrackingType.TRACKED, FIRST_ID))
490-
resetSessionInStore()
491-
492-
clock.tick(STORAGE_POLL_DELAY)
493-
494-
expect(sessionStoreManager.getSession().id).toBeUndefined()
495-
expectSessionToBeExpiredInStore()
496-
expect(expireSpy).toHaveBeenCalled()
497-
expect(sessionStoreStrategy.persistSession).toHaveBeenCalled()
498-
})
499-
500-
it('when session not in cache and session in store, should do nothing', () => {
501-
setupSessionStore()
502-
setSessionInStore(createSessionState(FakeTrackingType.TRACKED, FIRST_ID))
503-
504-
clock.tick(STORAGE_POLL_DELAY)
505-
506-
expect(sessionStoreManager.getSession().id).toBeUndefined()
507-
expect(expireSpy).not.toHaveBeenCalled()
508-
if (useExperimentalFeature) {
509-
expect(sessionStoreStrategy.persistSession).not.toHaveBeenCalled()
510-
}
511-
})
512-
513-
it('when session in cache is same session than in store, should synchronize session', () => {
514-
setupSessionStore(createSessionState(FakeTrackingType.TRACKED, FIRST_ID))
515-
setSessionInStore(
516-
createSessionState(FakeTrackingType.TRACKED, FIRST_ID, Date.now() + SESSION_TIME_OUT_DELAY + 10)
517-
)
518-
519-
clock.tick(STORAGE_POLL_DELAY)
520-
521-
expect(sessionStoreManager.getSession().id).toBe(FIRST_ID)
522-
expect(sessionStoreManager.getSession().expire).toBe(getStoreExpiration())
523-
expect(expireSpy).not.toHaveBeenCalled()
524-
if (useExperimentalFeature) {
525-
expect(sessionStoreStrategy.persistSession).not.toHaveBeenCalled()
526-
}
527-
})
528-
529-
it('when session id in cache is different than session id in store, should expire session and not touch the store', () => {
530-
setupSessionStore(createSessionState(FakeTrackingType.TRACKED, FIRST_ID))
531-
setSessionInStore(createSessionState(FakeTrackingType.TRACKED, SECOND_ID))
532-
533-
clock.tick(STORAGE_POLL_DELAY)
534-
535-
expect(sessionStoreManager.getSession().id).toBeUndefined()
536-
expect(expireSpy).toHaveBeenCalled()
537-
if (useExperimentalFeature) {
538-
expect(sessionStoreStrategy.persistSession).not.toHaveBeenCalled()
539-
}
540-
})
541-
542-
it('when session in store is expired first and then get updated by another tab, should expire session in cache and not touch the store', () => {
543-
setupSessionStore(createSessionState(FakeTrackingType.TRACKED, FIRST_ID))
544-
resetSessionInStore()
545-
546-
// Simulate a new session being written to the store by another tab during the watch
547-
// when the experimental feature is enabled, watch is reading the cookie twice so we need to plan the write of the cookie at the right index
548-
sessionStoreStrategy.planRetrieveSession(
549-
useExperimentalFeature ? 1 : 0,
550-
createSessionState(FakeTrackingType.TRACKED, SECOND_ID)
551-
)
552-
553-
clock.tick(STORAGE_POLL_DELAY)
554-
555-
// expires session in cache
556-
expect(sessionStoreManager.getSession().id).toBeUndefined()
557-
expect(expireSpy).toHaveBeenCalled()
558-
559-
// Does not touch the store
560-
// The two calls to persist session are for the lock management, these can be ignored
561-
expect(sessionStoreStrategy.persistSession).toHaveBeenCalledTimes(2)
562-
expect(sessionStoreStrategy.expireSession).not.toHaveBeenCalled()
563-
})
564-
565-
it('when session type in cache is different than session type in store, should expire session and not touch the store', () => {
566-
setupSessionStore(createSessionState(FakeTrackingType.NOT_TRACKED, FIRST_ID))
567-
setSessionInStore(createSessionState(FakeTrackingType.TRACKED, FIRST_ID))
568-
569-
clock.tick(STORAGE_POLL_DELAY)
570-
571-
expect(sessionStoreManager.getSession().id).toBeUndefined()
572-
expect(expireSpy).toHaveBeenCalled()
573-
if (useExperimentalFeature) {
574-
expect(sessionStoreStrategy.persistSession).not.toHaveBeenCalled()
575-
}
576-
})
577-
})
468+
it('when session not in cache and session not in store, should store the expired session', () => {
469+
setupSessionStore()
470+
471+
clock.tick(STORAGE_POLL_DELAY)
472+
473+
expectSessionToBeExpiredInStore()
474+
expect(sessionStoreManager.getSession().id).toBeUndefined()
475+
expect(expireSpy).not.toHaveBeenCalled()
476+
expect(sessionStoreStrategy.persistSession).toHaveBeenCalled()
477+
})
478+
479+
it('when session in cache and session not in store, should expire session', () => {
480+
setupSessionStore(createSessionState(FakeTrackingType.TRACKED, FIRST_ID))
481+
resetSessionInStore()
482+
483+
clock.tick(STORAGE_POLL_DELAY)
484+
485+
expect(sessionStoreManager.getSession().id).toBeUndefined()
486+
expectSessionToBeExpiredInStore()
487+
expect(expireSpy).toHaveBeenCalled()
488+
expect(sessionStoreStrategy.persistSession).toHaveBeenCalled()
489+
})
490+
491+
it('when session not in cache and session in store, should do nothing', () => {
492+
setupSessionStore()
493+
setSessionInStore(createSessionState(FakeTrackingType.TRACKED, FIRST_ID))
494+
495+
clock.tick(STORAGE_POLL_DELAY)
496+
497+
expect(sessionStoreManager.getSession().id).toBeUndefined()
498+
expect(expireSpy).not.toHaveBeenCalled()
499+
expect(sessionStoreStrategy.persistSession).not.toHaveBeenCalled()
500+
})
501+
502+
it('when session in cache is same session than in store, should synchronize session', () => {
503+
setupSessionStore(createSessionState(FakeTrackingType.TRACKED, FIRST_ID))
504+
setSessionInStore(
505+
createSessionState(FakeTrackingType.TRACKED, FIRST_ID, Date.now() + SESSION_TIME_OUT_DELAY + 10)
506+
)
507+
508+
clock.tick(STORAGE_POLL_DELAY)
509+
510+
expect(sessionStoreManager.getSession().id).toBe(FIRST_ID)
511+
expect(sessionStoreManager.getSession().expire).toBe(getStoreExpiration())
512+
expect(expireSpy).not.toHaveBeenCalled()
513+
expect(sessionStoreStrategy.persistSession).not.toHaveBeenCalled()
514+
})
515+
516+
it('when session id in cache is different than session id in store, should expire session and not touch the store', () => {
517+
setupSessionStore(createSessionState(FakeTrackingType.TRACKED, FIRST_ID))
518+
setSessionInStore(createSessionState(FakeTrackingType.TRACKED, SECOND_ID))
519+
520+
clock.tick(STORAGE_POLL_DELAY)
521+
522+
expect(sessionStoreManager.getSession().id).toBeUndefined()
523+
expect(expireSpy).toHaveBeenCalled()
524+
expect(sessionStoreStrategy.persistSession).not.toHaveBeenCalled()
525+
})
526+
527+
it('when session in store is expired first and then get updated by another tab, should expire session in cache and not touch the store', () => {
528+
setupSessionStore(createSessionState(FakeTrackingType.TRACKED, FIRST_ID))
529+
resetSessionInStore()
530+
531+
// Simulate a new session being written to the store by another tab during the watch.
532+
// Watch is reading the cookie twice so we need to plan the write of the cookie at the right index
533+
sessionStoreStrategy.planRetrieveSession(1, createSessionState(FakeTrackingType.TRACKED, SECOND_ID))
534+
535+
clock.tick(STORAGE_POLL_DELAY)
536+
537+
// expires session in cache
538+
expect(sessionStoreManager.getSession().id).toBeUndefined()
539+
expect(expireSpy).toHaveBeenCalled()
540+
541+
// Does not touch the store
542+
// The two calls to persist session are for the lock management, these can be ignored
543+
expect(sessionStoreStrategy.persistSession).toHaveBeenCalledTimes(2)
544+
expect(sessionStoreStrategy.expireSession).not.toHaveBeenCalled()
545+
})
546+
547+
it('when session type in cache is different than session type in store, should expire session and not touch the store', () => {
548+
setupSessionStore(createSessionState(FakeTrackingType.NOT_TRACKED, FIRST_ID))
549+
setSessionInStore(createSessionState(FakeTrackingType.TRACKED, FIRST_ID))
550+
551+
clock.tick(STORAGE_POLL_DELAY)
552+
553+
expect(sessionStoreManager.getSession().id).toBeUndefined()
554+
expect(expireSpy).toHaveBeenCalled()
555+
expect(sessionStoreStrategy.persistSession).not.toHaveBeenCalled()
578556
})
579557
})
580558

‎packages/core/src/domain/session/sessionStore.ts‎

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { throttle } from '../../tools/utils/functionUtils'
55
import { generateUUID } from '../../tools/utils/stringUtils'
66
import type { InitConfiguration, Configuration } from '../configuration'
77
import { display } from '../../tools/display'
8-
import { ExperimentalFeature, isExperimentalFeatureEnabled } from '../../tools/experimentalFeatures'
98
import { selectCookieStrategy, initCookieStrategy } from './storeStrategies/sessionInCookie'
109
import type { SessionStoreStrategy, SessionStoreStrategyType } from './storeStrategies/sessionStoreStrategy'
1110
import type { SessionState } from './sessionState'
@@ -135,21 +134,19 @@ export function startSessionStore<TrackingType extends string>(
135134
* - if the session is not active, clear the session store and expire the session cache
136135
*/
137136
function watchSession() {
138-
const sessionStoreOperation = {
139-
process: (sessionState: SessionState) =>
140-
isSessionInExpiredState(sessionState) ? getExpiredSessionState(sessionState, configuration) : undefined,
141-
after: synchronizeSession,
142-
} as const
143-
144-
if (isExperimentalFeatureEnabled(ExperimentalFeature.WATCH_COOKIE_WITHOUT_LOCK)) {
145-
const sessionState = sessionStoreStrategy.retrieveSession()
146-
if (isSessionInExpiredState(sessionState)) {
147-
processSessionStoreOperations(sessionStoreOperation, sessionStoreStrategy)
148-
} else {
149-
synchronizeSession(sessionState)
150-
}
137+
const sessionState = sessionStoreStrategy.retrieveSession()
138+
139+
if (isSessionInExpiredState(sessionState)) {
140+
processSessionStoreOperations(
141+
{
142+
process: (sessionState: SessionState) =>
143+
isSessionInExpiredState(sessionState) ? getExpiredSessionState(sessionState, configuration) : undefined,
144+
after: synchronizeSession,
145+
},
146+
sessionStoreStrategy
147+
)
151148
} else {
152-
processSessionStoreOperations(sessionStoreOperation, sessionStoreStrategy)
149+
synchronizeSession(sessionState)
153150
}
154151
}
155152

‎packages/core/src/tools/experimentalFeatures.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import { objectHasValue } from './utils/objectUtils'
1616
export enum ExperimentalFeature {
1717
TRACK_INTAKE_REQUESTS = 'track_intake_requests',
1818
WRITABLE_RESOURCE_GRAPHQL = 'writable_resource_graphql',
19-
WATCH_COOKIE_WITHOUT_LOCK = 'watch_cookie_without_lock',
2019
}
2120

2221
const enabledExperimentalFeatures: Set<ExperimentalFeature> = new Set()

0 commit comments

Comments
 (0)