Skip to content

Commit

Permalink
feat: Dispatch operations to internal queue
Browse files Browse the repository at this point in the history
  • Loading branch information
crleona committed May 6, 2024
1 parent 0cd014a commit d2b4cce
Show file tree
Hide file tree
Showing 17 changed files with 426 additions and 104 deletions.
5 changes: 5 additions & 0 deletions Amplitude-Swift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
3E281B8C2B967F19009D913B /* Diagonostics.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E281B8B2B967F19009D913B /* Diagonostics.swift */; };
3E281B8E2B96833D009D913B /* DiagnosticsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E281B8D2B96833D009D913B /* DiagnosticsTests.swift */; };
3E281B912B9BCC14009D913B /* DispatchQueueHolder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E281B902B9BCC14009D913B /* DispatchQueueHolder.swift */; };
4E05BB942BE41AEB009DE475 /* Amplitude+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E05BB932BE41AEB009DE475 /* Amplitude+Extensions.swift */; };
4E2B646B2BA127460010E6F8 /* UIKitScreenViewsPluginTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E2B646A2BA127460010E6F8 /* UIKitScreenViewsPluginTests.swift */; };
4E3871622BB34DBC002890AB /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = B6DF481F2B5B45BE00B3E6AA /* PrivacyInfo.xcprivacy */; };
8EDEC02B99EE2092B567A61D /* ObjCIngestionMetadata.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8EDEC500EBDA8B813056E2DB /* ObjCIngestionMetadata.swift */; };
Expand Down Expand Up @@ -150,6 +151,7 @@
3E281B8B2B967F19009D913B /* Diagonostics.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Diagonostics.swift; sourceTree = "<group>"; };
3E281B8D2B96833D009D913B /* DiagnosticsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiagnosticsTests.swift; sourceTree = "<group>"; };
3E281B902B9BCC14009D913B /* DispatchQueueHolder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DispatchQueueHolder.swift; sourceTree = "<group>"; };
4E05BB932BE41AEB009DE475 /* Amplitude+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Amplitude+Extensions.swift"; sourceTree = "<group>"; };
4E2B646A2BA127460010E6F8 /* UIKitScreenViewsPluginTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIKitScreenViewsPluginTests.swift; sourceTree = "<group>"; };
8EDEC0630C3B587334275D9B /* AmplitudeSessionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AmplitudeSessionTests.swift; sourceTree = "<group>"; };
8EDEC1160D95DC3F0E48DDF7 /* ObjCPlugin.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ObjCPlugin.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -466,6 +468,7 @@
8EDECBC5925DC68913C7CB89 /* Migration */,
BA1EC0F32A9F2FC700C2D547 /* DefaultTrackingOptionsTests.swift */,
BA1EC0F52A9F63FD00C2D547 /* AmplitudeIOSTests.swift */,
4E05BB932BE41AEB009DE475 /* Amplitude+Extensions.swift */,
);
name = Tests;
path = Tests/AmplitudeTests;
Expand Down Expand Up @@ -662,6 +665,7 @@
/* Begin PBXShellScriptBuildPhase section */
3E281B8F2B98EC92009D913B /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand Down Expand Up @@ -713,6 +717,7 @@
OBJ_156 /* HttpClientTests.swift in Sources */,
D01043612B6C5A8500F8173C /* SandboxHelperTests.swift in Sources */,
OBJ_157 /* PersistentStorageResponseHandlerTests.swift in Sources */,
4E05BB942BE41AEB009DE475 /* Amplitude+Extensions.swift in Sources */,
OBJ_158 /* UrlExtensionTests.swift in Sources */,
8EDEC4EE0DE1C89889F451B5 /* QueueTimeTests.swift in Sources */,
BA1EC0F62A9F63FD00C2D547 /* AmplitudeIOSTests.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
archiveVersion = 1;
classes = {
};
objectVersion = 56;
objectVersion = 63;
objects = {

/* Begin PBXBuildFile section */
4E890A202BAB82DF00B3F736 /* Amplitude_Swift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4E890A142BAB814A00B3F736 /* Amplitude_Swift.framework */; };
4E3ECB742BE5B96400FD5CC0 /* TestAmplitude.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E3ECB732BE5B96400FD5CC0 /* TestAmplitude.swift */; };
4E890A202BAB82DF00B3F736 /* AmplitudeSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4E890A142BAB814A00B3F736 /* AmplitudeSwift.framework */; };
BA2E1DA42AC1EA220074E74F /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = BA2E1DA32AC1EA220074E74F /* AppDelegate.m */; };
BA2E1DA72AC1EA220074E74F /* SceneDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = BA2E1DA62AC1EA220074E74F /* SceneDelegate.m */; };
BA2E1DAA2AC1EA220074E74F /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = BA2E1DA92AC1EA220074E74F /* ViewController.m */; };
Expand Down Expand Up @@ -50,6 +51,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
4E3ECB732BE5B96400FD5CC0 /* TestAmplitude.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestAmplitude.swift; sourceTree = "<group>"; };
4E890A0C2BAB814A00B3F736 /* Amplitude-Swift.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = "Amplitude-Swift.xcodeproj"; path = "../../Amplitude-Swift.xcodeproj"; sourceTree = "<group>"; };
BA2E1D9F2AC1EA220074E74F /* AmplitudeObjCExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AmplitudeObjCExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
BA2E1DA22AC1EA220074E74F /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
Expand All @@ -72,7 +74,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
4E890A202BAB82DF00B3F736 /* Amplitude_Swift.framework in Frameworks */,
4E890A202BAB82DF00B3F736 /* AmplitudeSwift.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -89,7 +91,7 @@
4E890A0D2BAB814A00B3F736 /* Products */ = {
isa = PBXGroup;
children = (
4E890A142BAB814A00B3F736 /* Amplitude_Swift.framework */,
4E890A142BAB814A00B3F736 /* AmplitudeSwift.framework */,
4E890A162BAB814A00B3F736 /* Amplitude_SwiftTests.xctest */,
);
name = Products;
Expand Down Expand Up @@ -137,6 +139,7 @@
isa = PBXGroup;
children = (
BA2E1DBE2AC1EA240074E74F /* AmplitudeObjCExampleTests.m */,
4E3ECB732BE5B96400FD5CC0 /* TestAmplitude.swift */,
);
path = AmplitudeObjCExampleTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -205,12 +208,12 @@
};
BA2E1DB92AC1EA230074E74F = {
CreatedOnToolsVersion = 14.2;
TestTargetID = BA2E1D9E2AC1EA220074E74F;
LastSwiftMigration = 1530;
};
};
};
buildConfigurationList = BA2E1D9A2AC1EA220074E74F /* Build configuration list for PBXProject "AmplitudeObjCExample" */;
compatibilityVersion = "Xcode 14.0";
compatibilityVersion = "Xcode 15.3";
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
Expand All @@ -237,10 +240,9 @@
/* End PBXProject section */

/* Begin PBXReferenceProxy section */
4E890A142BAB814A00B3F736 /* Amplitude_Swift.framework */ = {
4E890A142BAB814A00B3F736 /* AmplitudeSwift.framework */ = {
isa = PBXReferenceProxy;
fileType = wrapper.framework;
name = Amplitude_Swift.framework;
path = AmplitudeSwift.framework;
remoteRef = 4E890A132BAB814A00B3F736 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
Expand Down Expand Up @@ -292,6 +294,7 @@
buildActionMask = 2147483647;
files = (
BA2E1DBF2AC1EA240074E74F /* AmplitudeObjCExampleTests.m in Sources */,
4E3ECB742BE5B96400FD5CC0 /* TestAmplitude.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -495,7 +498,7 @@
BA2E1DD22AC1EA240074E74F /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -504,15 +507,16 @@
PRODUCT_BUNDLE_IDENTIFIER = com.amplitude.AmplitudeObjCExampleTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/AmplitudeObjCExample.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/AmplitudeObjCExample";
};
name = Debug;
};
BA2E1DD32AC1EA240074E74F /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -521,8 +525,8 @@
PRODUCT_BUNDLE_IDENTIFIER = com.amplitude.AmplitudeObjCExampleTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/AmplitudeObjCExample.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/AmplitudeObjCExample";
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#import <AmplitudeObjCExampleTests-Swift.h>
#import <XCTest/XCTest.h>
@import AmplitudeSwift;

Expand All @@ -21,8 +22,14 @@ - (void)testTrack {
@"prop-bool-array": @[@true, @false, @true],
@"prop-object": @{@"nested-prop-1": @555, @"nested-prop-2": @"nested-string"}
};
[amplitude track:@"Event-A" eventProperties:eventProperties];

AMPBaseEvent *event = [[AMPBaseEvent alloc] initWithEventType:@"Event-A"
eventProperties:eventProperties];
XCTestExpectation *expectation = [[XCTestExpectation alloc] initWithDescription:@"event tracked"];
[amplitude track:event callback:^(AMPBaseEvent *event, NSInteger code, NSString *message) {
[expectation fulfill];
}];
[self waitForExpectations:@[expectation]];

NSArray<NSString*>* eventsStrings = [amplitude.storage getEventsStrings];
NSArray* events = [self parseEvents:eventsStrings];
XCTAssertEqual(events.count, 1);
Expand All @@ -40,8 +47,16 @@ - (void)testTrack_Options {
@"prop-string": @"string-value",
@"prop-int": @111
};
[amplitude track:@"Event-A" eventProperties:eventProperties options:eventOptions];

AMPBaseEvent *event = [[AMPBaseEvent alloc] initWithEventType:@"Event-A"
eventProperties:eventProperties];
XCTestExpectation *expectation = [[XCTestExpectation alloc] initWithDescription:@"event tracked"];
[amplitude track:event
options:eventOptions
callback:^(AMPBaseEvent *event, NSInteger code, NSString *message) {
[expectation fulfill];
}];
[self waitForExpectations:@[expectation]];

NSArray<NSString*>* eventsStrings = [amplitude.storage getEventsStrings];
NSArray* events = [self parseEvents:eventsStrings];
XCTAssertEqual(events.count, 1);
Expand All @@ -62,8 +77,15 @@ - (void)testIdentify {
[identify add:@"user-sum-prop" valueInt:7];
[identify remove:@"user-agg-prop" value: @"item1"];
[identify unset:@"user-deprecated-prop"];
[amplitude identify:identify];


XCTestExpectation *expectation = [[XCTestExpectation alloc] initWithDescription:@"identify tracked"];
AMPEventOptions *options = [[AMPEventOptions alloc] init];
options.callback = ^(AMPBaseEvent *event, NSInteger code, NSString *message) {
[expectation fulfill];
};
[amplitude identify:identify options:options];
[self waitForExpectations:@[expectation]];

NSDictionary* expectedUserProperties = @{
@"$set": @{@"user-string-prop": @"string-value"},
@"$setOnce": @{@"user-int-prop": @111},
Expand All @@ -86,8 +108,15 @@ - (void)testIdentify_ClearAll {

AMPIdentify* identify = [AMPIdentify new];
[identify clearAll];
[amplitude identify:identify];


XCTestExpectation *expectation = [[XCTestExpectation alloc] initWithDescription:@"identify tracked"];
AMPEventOptions *options = [[AMPEventOptions alloc] init];
options.callback = ^(AMPBaseEvent *event, NSInteger code, NSString *message) {
[expectation fulfill];
};
[amplitude identify:identify options:options];
[self waitForExpectations:@[expectation]];

NSDictionary* expectedUserProperties = @{
@"$clearAll": @"-"
};
Expand All @@ -101,14 +130,28 @@ - (void)testIdentify_ClearAll {

- (void)testIdentify_InterceptedIdentifies {
Amplitude* amplitude = [self getAmplitude:@"identify-interceptedIdentifies"];

AMPIdentify* identify1 = [AMPIdentify new];
[identify1 set:@"user-string-prop" value:@"string-value"];
[amplitude identify:identify1];


XCTestExpectation *expectation1 = [[XCTestExpectation alloc] initWithDescription:@"identify 1 tracked"];
AMPEventOptions *options1 = [[AMPEventOptions alloc] init];
options1.callback = ^(AMPBaseEvent *event, NSInteger code, NSString *message) {
[expectation1 fulfill];
};
[amplitude identify:identify1 options:options1];

AMPIdentify* identify2 = [AMPIdentify new];
[identify2 set:@"user-int-prop" value:@111];
[amplitude identify:identify2];

XCTestExpectation *expectation2 = [[XCTestExpectation alloc] initWithDescription:@"identify 1 tracked"];
AMPEventOptions *options2 = [[AMPEventOptions alloc] init];
options2.callback = ^(AMPBaseEvent *event, NSInteger code, NSString *message) {
[expectation2 fulfill];
};
[amplitude identify:identify2 options:options2];

[self waitForExpectations:@[expectation1, expectation2]];

NSDictionary* expectedUserProperties1 = @{
@"$set": @{@"user-string-prop": @"string-value"}
Expand Down Expand Up @@ -138,8 +181,15 @@ - (void)testGroupIdentify {
[identify add:@"user-sum-prop" valueInt:7];
[identify remove:@"user-agg-prop" value: @"item1"];
[identify unset:@"user-deprecated-prop"];
[amplitude groupIdentify:@"type-1" groupName:@"name-1" identify:identify];


XCTestExpectation *expectation = [[XCTestExpectation alloc] initWithDescription:@"group identify tracked"];
AMPEventOptions *options = [[AMPEventOptions alloc] init];
options.callback = ^(AMPBaseEvent *event, NSInteger code, NSString *message) {
[expectation fulfill];
};
[amplitude groupIdentify:@"type-1" groupName:@"name-1" identify:identify options:options];
[self waitForExpectations:@[expectation]];

NSDictionary* expectedGroupProperties = @{
@"$set": @{@"user-string-prop": @"string-value"},
@"$setOnce": @{@"user-int-prop": @111},
Expand All @@ -160,10 +210,16 @@ - (void)testGroupIdentify {

- (void)testSetGroup {
Amplitude* amplitude = [self getAmplitude:@"setGroup"];

NSString* groupName = @"name-1";
[amplitude setGroup:@"type-1" groupName:groupName];


XCTestExpectation *expectation = [[XCTestExpectation alloc] initWithDescription:@"set group tracked"];
AMPEventOptions *options = [[AMPEventOptions alloc] init];
options.callback = ^(AMPBaseEvent *event, NSInteger code, NSString *message) {
[expectation fulfill];
};
NSString *groupName = @"name-1";
[amplitude setGroup:@"type-1" groupName:groupName options:options];
[self waitForExpectations:@[expectation]];

NSArray<NSString*>* eventsStrings = [amplitude.storage getEventsStrings];
NSArray* events = [self parseEvents:eventsStrings];
XCTAssertEqual(events.count, 1);
Expand All @@ -174,10 +230,16 @@ - (void)testSetGroup {

- (void)testSetGroup_Multiple {
Amplitude* amplitude = [self getAmplitude:@"setGroup_Multiple"];


XCTestExpectation *expectation = [[XCTestExpectation alloc] initWithDescription:@"set group tracked"];
AMPEventOptions *options = [[AMPEventOptions alloc] init];
options.callback = ^(AMPBaseEvent *event, NSInteger code, NSString *message) {
[expectation fulfill];
};
NSArray<NSString*>* groupNames = @[@"name-1", @"name-2"];
[amplitude setGroup:@"type-1" groupNames:groupNames];

[amplitude setGroup:@"type-1" groupNames:groupNames options:options];
[self waitForExpectations:@[expectation]];

NSArray<NSString*>* eventsStrings = [amplitude.storage getEventsStrings];
NSArray* events = [self parseEvents:eventsStrings];
XCTAssertEqual(events.count, 1);
Expand All @@ -195,11 +257,16 @@ - (void)testPlugin {
return event;
}]];

[amplitude track:@"Event-A" eventProperties:@{
@"prop-string": @"string-value",
@"prop-int": @111
}];

XCTestExpectation *expectation = [[XCTestExpectation alloc] initWithDescription:@"group identify tracked"];
AMPEventOptions *options = [[AMPEventOptions alloc] init];
options.callback = ^(AMPBaseEvent *event, NSInteger code, NSString *message) {
[expectation fulfill];
};
[amplitude track:@"Event-A"
eventProperties: @{@"prop-string": @"string-value", @"prop-int": @111}
options:options];
[self waitForExpectations:@[expectation]];

NSDictionary* expectedEventProperties = @{
@"prop-string": @"string-value",
@"prop-int": @111,
Expand Down Expand Up @@ -259,7 +326,7 @@ - (Amplitude *)getAmplitude:(NSString *)instancePrefix {
NSString* instanceName = [NSString stringWithFormat:@"%@-%f", instancePrefix, [[NSDate date] timeIntervalSince1970]];
AMPConfiguration* configuration = [AMPConfiguration initWithApiKey:@"API-KEY" instanceName:instanceName];
configuration.defaultTracking = AMPDefaultTrackingOptions.NONE;
Amplitude* amplitude = [Amplitude initWithConfiguration:configuration];
Amplitude *amplitude = [[TestAmplitude alloc] initWithConfiguration:configuration];
return amplitude;
}

Expand Down
Loading

0 comments on commit d2b4cce

Please sign in to comment.