Skip to content

Commit

Permalink
E2E tests for impressions toggling (#600)
Browse files Browse the repository at this point in the history
  • Loading branch information
gthea authored Dec 20, 2024
1 parent 0d3785f commit 326a176
Show file tree
Hide file tree
Showing 10 changed files with 421 additions and 72 deletions.
8 changes: 8 additions & 0 deletions Split.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,8 @@
C5A3F5212BEBDAD6009FACD3 /* HttpParameter.swift in Sources */ = {isa = PBXBuildFile; fileRef = C5A3F5202BEBDAD6009FACD3 /* HttpParameter.swift */; };
C5BD1E4C2D11A993008EF198 /* DecoratedImpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = C5BD1E4B2D11A98E008EF198 /* DecoratedImpression.swift */; };
C5BD1E4D2D11A993008EF198 /* DecoratedImpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = C5BD1E4B2D11A98E008EF198 /* DecoratedImpression.swift */; };
C5BD1E4F2D130EAF008EF198 /* ImpressionsToggleTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C5BD1E4E2D130EA7008EF198 /* ImpressionsToggleTest.swift */; };
C5BD1E522D130FB6008EF198 /* splitchanges_toggle.json in Resources */ = {isa = PBXBuildFile; fileRef = C5BD1E512D130FB6008EF198 /* splitchanges_toggle.json */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -1922,6 +1924,8 @@
C5A3F51E2BEBD893009FACD3 /* Spec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Spec.swift; sourceTree = "<group>"; };
C5A3F5202BEBDAD6009FACD3 /* HttpParameter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HttpParameter.swift; sourceTree = "<group>"; };
C5BD1E4B2D11A98E008EF198 /* DecoratedImpression.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DecoratedImpression.swift; sourceTree = "<group>"; };
C5BD1E4E2D130EA7008EF198 /* ImpressionsToggleTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImpressionsToggleTest.swift; sourceTree = "<group>"; };
C5BD1E512D130FB6008EF198 /* splitchanges_toggle.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = splitchanges_toggle.json; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -2832,6 +2836,7 @@
C5977C312BF4031A003E293A /* split_changes_semver.json */,
C58F33722BDAC4AC00D66549 /* split_unsupported_matcher.json */,
C5977C582BF53F43003E293A /* splitchanges_unsupported.json */,
C5BD1E512D130FB6008EF198 /* splitchanges_toggle.json */,
);
path = Resources;
sourceTree = "<group>";
Expand Down Expand Up @@ -3124,6 +3129,7 @@
953911AB267A648F0040433A /* Impressions */ = {
isa = PBXGroup;
children = (
C5BD1E4E2D130EA7008EF198 /* ImpressionsToggleTest.swift */,
955AAB912840182800ADFB07 /* ImpressionsNoneTest.swift */,
95CC53C52695F68500A07A04 /* ImpressionsDedupTest.swift */,
953911AC267A64FE0040433A /* ImpresionsObserverTest.swift */,
Expand Down Expand Up @@ -3784,6 +3790,7 @@
5912D14D2199FD4D00BC698C /* legacy_1.csv in Resources */,
95737E142ADEC71A007FD15C /* push_msg-splits_updV2.txt in Resources */,
95F7BBDE2C1A27C200C5F2E4 /* rsa_3072_public_01.pem in Resources */,
C5BD1E522D130FB6008EF198 /* splitchanges_toggle.json in Resources */,
95F7BBDA2C1A27C200C5F2E4 /* rsa_2048_public_01.pem in Resources */,
592C6AED211CBBB0002D120C /* splitchanges_2.json in Resources */,
950F72FF292E8D6C008A0040 /* SplitiOSFull.xctestplan in Resources */,
Expand Down Expand Up @@ -4351,6 +4358,7 @@
59F4AAA124FFC94100A1C69A /* NotificationManagerKeeperTest.swift in Sources */,
955E12372BFCDEAC00AE6D10 /* HashedImpressionDaoMock.swift in Sources */,
95ABF4FC29369B73006ED016 /* TelemetrySynchronizerStub.swift in Sources */,
C5BD1E4F2D130EAF008EF198 /* ImpressionsToggleTest.swift in Sources */,
95715A8529D353C100A1B2F9 /* DbCipherTest.swift in Sources */,
59D84BDC2215CD52003DA248 /* LocalhostSplitLoaderTests.swift in Sources */,
956D17D1260D266E0037F575 /* SplitsChangesCheckerTest.swift in Sources */,
Expand Down
23 changes: 8 additions & 15 deletions Split/Api/SplitApiFacade.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ struct SplitApiFacade {
let splitsFetcher: HttpSplitFetcher
let mySegmentsFetcher: HttpMySegmentsFetcher
let impressionsRecorder: HttpImpressionsRecorder?
let impressionsCountRecorder: HttpImpressionsCountRecorder?
let impressionsCountRecorder: HttpImpressionsCountRecorder
let eventsRecorder: HttpEventsRecorder
let streamingHttpClient: HttpClient?
let sseAuthenticator: SseAuthenticator
let telemetryConfigRecorder: HttpTelemetryConfigRecorder?
let telemetryStatsRecorder: HttpTelemetryStatsRecorder?
let uniqueKeysRecorder: HttpUniqueKeysRecorder?
let uniqueKeysRecorder: HttpUniqueKeysRecorder
}

class SplitApiFacadeBuilder {
Expand Down Expand Up @@ -129,22 +129,15 @@ class SplitApiFacadeBuilder {
return nil
}

private func getImpressionsCountRecorder(restClient: RestClientImpressionsCount) -> HttpImpressionsCountRecorder? {
if impressionsMode() == .optimized ||
impressionsMode() == .none {
let syncHelper = DefaultSyncHelper(telemetryProducer: telemetryStorage)
return DefaultHttpImpressionsCountRecorder(restClient: restClient,
syncHelper: syncHelper)
}
return nil
private func getImpressionsCountRecorder(restClient: RestClientImpressionsCount) -> HttpImpressionsCountRecorder {
let syncHelper = DefaultSyncHelper(telemetryProducer: telemetryStorage)
return DefaultHttpImpressionsCountRecorder(restClient: restClient,
syncHelper: syncHelper)
}

private func getUniqueKeysRecorder(restClient: RestClientUniqueKeys) -> HttpUniqueKeysRecorder? {
if impressionsMode() == .none {
return DefaultHttpUniqueKeysRecorder(restClient: restClient,
private func getUniqueKeysRecorder(restClient: RestClientUniqueKeys) -> HttpUniqueKeysRecorder {
return DefaultHttpUniqueKeysRecorder(restClient: restClient,
syncHelper: DefaultSyncHelper(telemetryProducer: telemetryStorage))
}
return nil
}

private func impressionsMode() -> ImpressionsMode {
Expand Down
5 changes: 1 addition & 4 deletions Split/Api/SplitDatabaseHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,9 @@ struct SplitDatabaseHelper {
let attributesStorage = openAttributesStorage(database: splitDatabase,
splitClientConfig: splitClientConfig)

var uniqueKeyStorage: PersistentUniqueKeysStorage?
if splitClientConfig.$impressionsMode == .none {
uniqueKeyStorage =
let uniqueKeyStorage: PersistentUniqueKeysStorage =
DefaultPersistentUniqueKeysStorage(database: splitDatabase,
expirationPeriod: kExpirationPeriod)
}

let persistentHashedImpressionsStorage = DefaultPersistentHashedImpressionsStorage(database: splitDatabase)
let hashedImpressionsStorage = DefaultHashedImpressionsStorage(
Expand Down
7 changes: 2 additions & 5 deletions Split/Initialization/SplitComponentFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,8 @@ class SplitComponentFactory {

func buildImpressionsTracker(notificationHelper: NotificationHelper?) throws -> ImpressionsTracker {
let storageContainer = try getSplitStorageContainer()
var uniqueKeyTracker: UniqueKeyTracker?
if splitClientConfig.$impressionsMode == .none,
let uniqueKeyStorage = storageContainer.uniqueKeyStorage {
uniqueKeyTracker = DefaultUniqueKeyTracker(persistentUniqueKeyStorage: uniqueKeyStorage)
}
var uniqueKeyTracker = DefaultUniqueKeyTracker(persistentUniqueKeyStorage: storageContainer.uniqueKeyStorage)

let component: ImpressionsTracker
= DefaultImpressionsTracker(
splitConfig: splitClientConfig,
Expand Down
47 changes: 15 additions & 32 deletions Split/Network/Streaming/RetryableSplitsUpdateWorkerFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ protocol SyncWorkerFactory {

func createImpressionsRecorderWorker(syncHelper: ImpressionsRecorderSyncHelper?) -> RecorderWorker?

func createImpressionsCountRecorderWorker() -> RecorderWorker?
func createImpressionsCountRecorderWorker() -> RecorderWorker

func createPeriodicImpressionsCountRecorderWorker() -> PeriodicRecorderWorker?
func createPeriodicImpressionsCountRecorderWorker() -> PeriodicRecorderWorker

func createPeriodicEventsRecorderWorker(syncHelper: EventsRecorderSyncHelper?) -> PeriodicRecorderWorker

func createEventsRecorderWorker(syncHelper: EventsRecorderSyncHelper?) -> RecorderWorker

func createUniqueKeyRecorderWorker(flusherChecker: RecorderFlushChecker?) -> RecorderWorker?
func createUniqueKeyRecorderWorker(flusherChecker: RecorderFlushChecker?) -> RecorderWorker

func createPeriodicUniqueKeyRecorderWorker(flusherChecker: RecorderFlushChecker?) -> PeriodicRecorderWorker?
func createPeriodicUniqueKeyRecorderWorker(flusherChecker: RecorderFlushChecker?) -> PeriodicRecorderWorker

func createTelemetryConfigRecorderWorker() -> RecorderWorker?

Expand Down Expand Up @@ -145,24 +145,14 @@ class DefaultSyncWorkerFactory: SyncWorkerFactory {
impressionsSyncHelper: syncHelper)
}

func createImpressionsCountRecorderWorker() -> RecorderWorker? {

guard let impressionsCountRecorder = apiFacade.impressionsCountRecorder else {
return nil
}

func createImpressionsCountRecorderWorker() -> RecorderWorker {
return ImpressionsCountRecorderWorker(countsStorage: storageContainer.impressionsCountStorage,
countsRecorder: impressionsCountRecorder)
countsRecorder: apiFacade.impressionsCountRecorder)
}

func createPeriodicImpressionsCountRecorderWorker() -> PeriodicRecorderWorker? {

guard let impressionsCountRecorder = apiFacade.impressionsCountRecorder else {
return nil
}

func createPeriodicImpressionsCountRecorderWorker() -> PeriodicRecorderWorker {
let recorderWorker = ImpressionsCountRecorderWorker(countsStorage: storageContainer.impressionsCountStorage,
countsRecorder: impressionsCountRecorder)
countsRecorder: apiFacade.impressionsCountRecorder)
let timer = DefaultPeriodicTimer(deadline: 0, interval: splitConfig.impressionsCountsRefreshRate)
return DefaultPeriodicRecorderWorker(timer: timer, recorderWorker: recorderWorker)
}
Expand Down Expand Up @@ -240,23 +230,16 @@ class DefaultSyncWorkerFactory: SyncWorkerFactory {
return DefaultPeriodicRecorderWorker(timer: timer, recorderWorker: telemetryStatsWorker)
}

func createUniqueKeyRecorderWorker(flusherChecker: RecorderFlushChecker?) -> RecorderWorker? {
if let recorder = apiFacade.uniqueKeysRecorder, let storage = storageContainer.uniqueKeyStorage {
return UniqueKeysRecorderWorker(uniqueKeyStorage: storage,
uniqueKeysRecorder: recorder,
func createUniqueKeyRecorderWorker(flusherChecker: RecorderFlushChecker?) -> RecorderWorker {
return UniqueKeysRecorderWorker(uniqueKeyStorage: storageContainer.uniqueKeyStorage,
uniqueKeysRecorder: apiFacade.uniqueKeysRecorder,
flushChecker: flusherChecker)
}
return nil
}

func createPeriodicUniqueKeyRecorderWorker(flusherChecker: RecorderFlushChecker?) -> PeriodicRecorderWorker? {
if let worker = createUniqueKeyRecorderWorker(flusherChecker: flusherChecker) {
let timer = DefaultPeriodicTimer(deadline: splitConfig.uniqueKeysRefreshRate,
interval: splitConfig.uniqueKeysRefreshRate)
return DefaultPeriodicRecorderWorker(timer: timer,
recorderWorker: worker)
}
return nil
func createPeriodicUniqueKeyRecorderWorker(flusherChecker: RecorderFlushChecker?) -> PeriodicRecorderWorker {
return DefaultPeriodicRecorderWorker(timer: DefaultPeriodicTimer(deadline: splitConfig.uniqueKeysRefreshRate,
interval: splitConfig.uniqueKeysRefreshRate),
recorderWorker: createUniqueKeyRecorderWorker(flusherChecker: flusherChecker))
}
}

Expand Down
15 changes: 4 additions & 11 deletions Split/Network/Sync/ImpressionsTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -207,18 +207,11 @@ class DefaultImpressionsTracker: ImpressionsTracker {

private func setupImpressionsMode() {

switch splitConfig.$impressionsMode {
case .optimized:
createImpressionsRecorder()
createUniqueKeysRecorder()
createImpressionsCountRecorder()
case .debug:
createUniqueKeysRecorder()
createImpressionsCountRecorder()

if splitConfig.$impressionsMode == .debug || splitConfig.$impressionsMode == .optimized {
createImpressionsRecorder()
createUniqueKeysRecorder()
createImpressionsCountRecorder()
case .none:
createUniqueKeysRecorder()
createImpressionsCountRecorder()
}
}

Expand Down
2 changes: 1 addition & 1 deletion Split/Network/Sync/SyncCommons.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct SplitStorageContainer {
let mySegmentsStorage: MySegmentsStorage
let myLargeSegmentsStorage: MySegmentsStorage
let attributesStorage: AttributesStorage
let uniqueKeyStorage: PersistentUniqueKeysStorage?
let uniqueKeyStorage: PersistentUniqueKeysStorage
let flagSetsCache: FlagSetsCache
let persistentHashedImpressionsStorage: PersistentHashedImpressionsStorage
let hashedImpressionsStorage: HashedImpressionsStorage
Expand Down
8 changes: 4 additions & 4 deletions SplitTests/Fake/SyncWorkerFactoryStub.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ class SyncWorkerFactoryStub: SyncWorkerFactory {
return impressionsRecorderWorker
}

func createPeriodicImpressionsCountRecorderWorker() -> PeriodicRecorderWorker? {
func createPeriodicImpressionsCountRecorderWorker() -> PeriodicRecorderWorker {
return periodicImpressionsCountRecorderWorker
}

func createImpressionsCountRecorderWorker() -> RecorderWorker? {
func createImpressionsCountRecorderWorker() -> RecorderWorker {
return impressionsCountRecorderWorker
}

Expand All @@ -93,11 +93,11 @@ class SyncWorkerFactoryStub: SyncWorkerFactory {
return periodicTelemetryStatsRecorderWorker
}

func createUniqueKeyRecorderWorker(flusherChecker: RecorderFlushChecker?) -> RecorderWorker? {
func createUniqueKeyRecorderWorker(flusherChecker: RecorderFlushChecker?) -> RecorderWorker {
return uniqueKeysRecorderWorker
}

func createPeriodicUniqueKeyRecorderWorker(flusherChecker: RecorderFlushChecker?) -> PeriodicRecorderWorker? {
func createPeriodicUniqueKeyRecorderWorker(flusherChecker: RecorderFlushChecker?) -> PeriodicRecorderWorker {
return periodicUniqueKeysRecorderWorker
}
}
Loading

0 comments on commit 326a176

Please sign in to comment.