Skip to content

Commit

Permalink
Merge pull request #979 from mixpanel/remove-nocilla
Browse files Browse the repository at this point in the history
Remove `nocilla` and `ocmock`
  • Loading branch information
zihejia authored Jan 31, 2022
2 parents b1ebd5a + 1fcfbbd commit b7d33fb
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 253 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/mixpanel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,16 @@ jobs:
runs-on: macos-latest
strategy:
matrix:
destination: ['OS=15.0,name="iPhone 11"']
destination: ['OS=15.2,name="iPhone 13 Pro"']
scheme: ['"[iOS] HelloMixpanel"']

steps:
- uses: actions/checkout@v2
- name: Install Dependencies
run: |
cd HelloMixpanel
pod install --repo-update
- name: Run Test
working-directory: HelloMixpanel
run: |
set -o pipefail
xcodebuild -workspace HelloMixpanel.xcworkspace -scheme ${{ matrix.scheme }} -derivedDataPath Build/ -destination ${{ matrix.destination }} -configuration Debug ONLY_ACTIVE_ARCH=NO ENABLE_TESTABILITY=YES test | xcpretty -c;
xcodebuild -scheme ${{ matrix.scheme }} -derivedDataPath Build/ -destination ${{ matrix.destination }} -configuration Debug ONLY_ACTIVE_ARCH=NO ENABLE_TESTABILITY=YES test | xcpretty -c;
- name: Pod Lint
run: pod lib lint --allow-warnings
- name: Code Coverage Report
Expand Down
141 changes: 0 additions & 141 deletions HelloMixpanel/HelloMixpanel.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

66 changes: 6 additions & 60 deletions HelloMixpanel/HelloMixpanelTests/HelloMixpanelTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,14 @@ @implementation HelloMixpanelTests

#pragma mark - Network
- (void)test5XXResponse {
[[LSNocilla sharedInstance] clearStubs];
[[LSNocilla sharedInstance] start];
stubEngage();
Mixpanel *testMixpanel = [[Mixpanel alloc] initWithToken:[self randomTokenId] andFlushInterval:60];

stubTrack().andReturn(503);

[testMixpanel setServerURL:kFakeServerUrl];
[testMixpanel track:@"Fake Event"];

[testMixpanel flush];
[self waitForMixpanelQueues:testMixpanel];

[testMixpanel flush];
[[LSNocilla sharedInstance] start];
[self waitForMixpanelQueues:testMixpanel];

// Failure count should be 3
Expand All @@ -47,28 +41,6 @@ - (void)test5XXResponse {
[self removeDBfile:testMixpanel.apiToken];
}

- (void)testRetryAfterHTTPHeader {
[[LSNocilla sharedInstance] clearStubs];
[[LSNocilla sharedInstance] start];
Mixpanel *testMixpanel = [[Mixpanel alloc] initWithToken:[self randomTokenId] andFlushInterval:60];
stubTrack().andReturn(200).withHeader(@"Retry-After", @"60");

[testMixpanel track:@"Fake Event"];

[testMixpanel flush];
[self waitForMixpanelQueues:testMixpanel];

[testMixpanel flush];
[self waitForMixpanelQueues:testMixpanel];

// Failure count should be 3
NSLog(@"Delta wait time is %.3f", testMixpanel.network.requestsDisabledUntilTime - [[NSDate date] timeIntervalSince1970]);
NSTimeInterval deltaWaitTime = testMixpanel.network.requestsDisabledUntilTime - [[NSDate date] timeIntervalSince1970];
XCTAssert(fabs(60 - deltaWaitTime) < 5, @"Mixpanel did not respect 'Retry-After' HTTP header");
XCTAssert(testMixpanel.network.consecutiveFailures == 0, @"Network failures did not equal 0");
[self removeDBfile:testMixpanel.apiToken];
}

- (void)testFlushEvents {
Mixpanel *testMixpanel = [[Mixpanel alloc] initWithToken:[self randomTokenId] andFlushInterval:60];
[testMixpanel identify:@"d1"];
Expand Down Expand Up @@ -105,12 +77,8 @@ - (void)testFlushPeople {
}

- (void)testFlushNetworkFailure {
[[LSNocilla sharedInstance] stop];
[[LSNocilla sharedInstance] clearStubs];
[[LSNocilla sharedInstance] start];
Mixpanel *testMixpanel = [[Mixpanel alloc] initWithToken:[self randomTokenId] andFlushInterval:60];
stubTrack().andFailWithError([NSError errorWithDomain:@"com.mixpanel.sdk.testing" code:1 userInfo:nil]);

[testMixpanel setServerURL:kFakeServerUrl];
for (NSUInteger i=0, n=50; i<n; i++) {
[testMixpanel track:[NSString stringWithFormat:@"event %lu", (unsigned long)i]];
}
Expand All @@ -123,7 +91,6 @@ - (void)testFlushNetworkFailure {
}

- (void)testIdentify {
// stub needed because reset flushes
for (NSInteger i = 0; i < 2; i++) { // run this twice to test reset works correctly wrt to distinct ids
NSString *testToken = [self randomTokenId];
Mixpanel *testMixpanel = [[Mixpanel alloc] initWithToken:testToken andFlushInterval:60];
Expand Down Expand Up @@ -181,7 +148,6 @@ - (void)testIdentify {
}

- (void)testIdentifyTrack {
// stub needed because reset flushes
Mixpanel *testMixpanel = [[Mixpanel alloc] initWithToken:[self randomTokenId] andFlushInterval:60];
NSString *distinctIdBeforeidentify = testMixpanel.distinctId;

Expand All @@ -208,7 +174,6 @@ - (void)testIdentifyTrack {
}

- (void)testIdentifyResetTrack {
// stub needed because reset flushes
Mixpanel *testMixpanel = [[Mixpanel alloc] initWithToken:[self randomTokenId] andFlushInterval:60];

testMixpanel.anonymousId = nil;
Expand Down Expand Up @@ -260,7 +225,6 @@ - (void)testUseUniqueDistinctI {
- (void)testHadPersistedDistinctId {
NSString *randomTokenId = [self randomTokenId];
Mixpanel *testMixpanel = [[Mixpanel alloc] initWithToken:randomTokenId andFlushInterval:60];
// stub needed because reset flushes
NSString *distinctIdBeforeidentify = testMixpanel.distinctId;

Mixpanel *testMixpanel2 = [[Mixpanel alloc] initWithToken:randomTokenId andFlushInterval:60];
Expand Down Expand Up @@ -393,7 +357,6 @@ - (void)testRegisterSuperProperties {
}

- (void)testInvalidPropertiesTrack {
stubTrack();
Mixpanel *testMixpanel = [[Mixpanel alloc] initWithToken:[self randomTokenId] andFlushInterval:60];
NSDictionary *p = @{ @"data": [NSData data] };
XCTAssertThrows([testMixpanel track:@"e1" properties:p], @"property type should not be allowed");
Expand Down Expand Up @@ -426,12 +389,6 @@ - (void)testValidSuperProperties {
}

- (void)testReset {
// stub needed because reset flushes
[[LSNocilla sharedInstance] start];
stubTrack();
stubEngage();
stubGroups();
stubDecide();
NSString *testToken = [self randomTokenId];
Mixpanel *testMixpanel = [[Mixpanel alloc] initWithToken:testToken andFlushInterval:60];
[testMixpanel identify:@"d1"];
Expand Down Expand Up @@ -466,11 +423,6 @@ - (void)testReset {
}

- (void)testArchive {
[[LSNocilla sharedInstance] start];
stubTrack();
stubEngage();
stubGroups();
stubDecide();
NSString *testToken = [self randomTokenId];
Mixpanel *testMixpanel = [[Mixpanel alloc] initWithToken:testToken andFlushInterval:60];
[testMixpanel archive];
Expand Down Expand Up @@ -652,31 +604,26 @@ - (void)testEventTiming {
}

- (void)testNetworkingWithStress {
[[LSNocilla sharedInstance] stop];
[[LSNocilla sharedInstance] clearStubs];
[[LSNocilla sharedInstance] start];
Mixpanel *testMixpanel = [[Mixpanel alloc] initWithToken:[self randomTokenId] andFlushInterval:60];
self.mixpanelWillFlush = NO;
stubTrack().andReturn(503);
for (NSInteger i = 1; i <= 500; i++) {
[testMixpanel track:@"Track Call"];
}
[testMixpanel setServerURL:kFakeServerUrl];
[self flushAndWaitForMixpanelQueues:testMixpanel];
XCTAssertTrue([self eventQueue:testMixpanel.apiToken].count == 500, @"none supposed to be flushed");
[[LSNocilla sharedInstance] clearStubs];
stubTrack().andReturn(200);
testMixpanel.network.requestsDisabledUntilTime = 0;
[testMixpanel setServerURL:kDefaultServerString];
[self flushAndWaitForMixpanelQueues:testMixpanel];
XCTAssertTrue([self eventQueue:testMixpanel.apiToken].count == 0, @"supposed to all be flushed");
[self removeDBfile:testMixpanel.apiToken];
}

- (void)testConcurrentTracking {
[[LSNocilla sharedInstance] start];
Mixpanel *testMixpanel = [[Mixpanel alloc] initWithToken:[self randomTokenId] andFlushInterval:60];

self.mixpanelWillFlush = NO;
stubTrack().andReturn(503);
[testMixpanel setServerURL:kFakeServerUrl];
dispatch_queue_t concurrentQueue = dispatch_queue_create("test_concurrent_queue", DISPATCH_QUEUE_CONCURRENT);
dispatch_group_t trackGroup = dispatch_group_create();
for (int i = 0; i < 500; i++) {
Expand All @@ -696,8 +643,7 @@ - (void)testConcurrentTracking {
}
XCTAssertTrue(found, @"event that was tracked not found in eventsQueue");
}
[[LSNocilla sharedInstance] clearStubs];
stubTrack().andReturn(200);
[testMixpanel setServerURL:kDefaultServerString];
testMixpanel.network.requestsDisabledUntilTime = 0;
[self flushAndWaitForMixpanelQueues:testMixpanel];
XCTAssertTrue([self eventQueue:testMixpanel.apiToken].count == 0, @"supposed to all be flushed");
Expand Down
10 changes: 1 addition & 9 deletions HelloMixpanel/HelloMixpanelTests/MixpanelBaseTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Copyright © Mixpanel. All rights reserved.
//

#import <Nocilla/Nocilla.h>

#import "MixpanelBaseTests.h"
#import "TestConstants.h"
#import "MixpanelPrivate.h"
Expand All @@ -17,18 +17,10 @@ @implementation MixpanelBaseTests
- (void)setUp {
[super setUp];

// HTTP Stubs
[[LSNocilla sharedInstance] start];

self.mixpanelWillFlush = NO;
stubTrack();
stubEngage();
stubGroups();
stubDecide();
}

- (void)tearDown {
[[LSNocilla sharedInstance] start];
[NSThread sleepForTimeInterval:1.0];
[super tearDown];
}
Expand Down
1 change: 0 additions & 1 deletion HelloMixpanel/HelloMixpanelTests/MixpanelOptOutTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#import "MixpanelPrivate.h"
#import "TestConstants.h"
#import "MixpanelPeoplePrivate.h"
#import <OCMock/OCMock.h>


@interface MixpanelOptOutTests : MixpanelBaseTests
Expand Down
22 changes: 2 additions & 20 deletions HelloMixpanel/HelloMixpanelTests/TestConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,8 @@
// Copyright © Mixpanel. All rights reserved.
//

#import <Nocilla/Nocilla.h>

#pragma mark - Constants
static NSString *const kTestToken = @"abc123";
static NSString *const kDefaultServerString = @"https://api.mixpanel.com";

#pragma mark - Stub Helpers
static inline LSStubRequestDSL *stubEngage() {
return stubRequest(@"POST", @"https://api.mixpanel.com/engage/".regex).withHeader(@"Content-Type", @"application/json");
}

static inline LSStubRequestDSL *stubTrack() {
return stubRequest(@"POST", @"https://api.mixpanel.com/track/".regex).withHeader(@"Content-Type", @"application/json");
}

static inline LSStubRequestDSL *stubGroups() {
return stubRequest(@"POST", @"https://api.mixpanel.com/groups/".regex).withHeader(@"Content-Type", @"application/json");
}

static inline LSStubRequestDSL *stubDecide() {
return stubRequest(@"POST", @"https://api.mixpanel.com/decide(.*?)".regex).withHeader(@"Content-Type", @"application/json");
}
static NSString *const kFakeServerUrl = @"https://34a272abf23d.com";

static NSString *const kDefaultServerString = @"https://api.mixpanel.com";
16 changes: 0 additions & 16 deletions HelloMixpanel/Podfile

This file was deleted.

0 comments on commit b7d33fb

Please sign in to comment.