Skip to content
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

fix: Refactor MPUploadBuilder to attempt to eliminate rare crash in withLocation: method #262

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions UnitTests/MPBackendControllerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -689,9 +689,9 @@ - (void)testRampUpload {
dispatch_async(messageQueue, ^{
MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]];

MPMessageBuilder *messageBuilder = [MPMessageBuilder newBuilderWithMessageType:MPMessageTypeEvent
session:session
messageInfo:@{@"MessageKey1":@"MessageValue1"}];
MPMessageBuilder *messageBuilder = [[MPMessageBuilder alloc] initWithMessageType:MPMessageTypeEvent
session:session
messageInfo:@{@"MessageKey1":@"MessageValue1"}];
MPMessage *message = [messageBuilder build];

MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController;
Expand Down Expand Up @@ -1397,9 +1397,9 @@ - (void)testMessageWithOptOut {

MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]];

MPMessageBuilder *messageBuilder = [MPMessageBuilder newBuilderWithMessageType:MPMessageTypeEvent
session:session
messageInfo:@{@"MessageKey1":@"MessageValue1"}];
MPMessageBuilder *messageBuilder = [[MPMessageBuilder alloc] initWithMessageType:MPMessageTypeEvent
session:session
messageInfo:@{@"MessageKey1":@"MessageValue1"}];
MPMessage *message = [messageBuilder build];
[[MParticle sharedInstance].backendController saveMessage:message updateSession:NO];

Expand All @@ -1418,7 +1418,7 @@ - (void)testMessageWithOptOutMessage {

MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]];

MPMessageBuilder *messageBuilder = [MPMessageBuilder newBuilderWithMessageType:MPMessageTypeOptOut session:session messageInfo:@{kMPOptOutStatus:(@"true")}];
MPMessageBuilder *messageBuilder = [[MPMessageBuilder alloc] initWithMessageType:MPMessageTypeOptOut session:session messageInfo:@{kMPOptOutStatus:(@"true")}];

MPMessage *message = [messageBuilder build];
[[MParticle sharedInstance].backendController saveMessage:message updateSession:NO];
Expand All @@ -1437,9 +1437,9 @@ - (void)testBatchAndMessageLimitsMessagesPerBatch {

NSMutableArray *unlimitedMessages = [NSMutableArray array];
for (int i=0; i<10; i++) {
MPMessageBuilder *messageBuilder = [MPMessageBuilder newBuilderWithMessageType:MPMessageTypeEvent
session:session
messageInfo:@{@"MessageKey1":@"MessageValue1"}];
MPMessageBuilder *messageBuilder = [[MPMessageBuilder alloc] initWithMessageType:MPMessageTypeEvent
session:session
messageInfo:@{@"MessageKey1":@"MessageValue1"}];
MPMessage *message = [messageBuilder build];
[unlimitedMessages addObject:message];
}
Expand All @@ -1457,9 +1457,9 @@ - (void)testBatchAndMessageLimitsMultipleMessagesPerBatch {

NSMutableArray *unlimitedMessages = [NSMutableArray array];
for (int i=0; i<10; i++) {
MPMessageBuilder *messageBuilder = [MPMessageBuilder newBuilderWithMessageType:MPMessageTypeEvent
session:session
messageInfo:@{@"MessageKey1":@"MessageValue1"}];
MPMessageBuilder *messageBuilder = [[MPMessageBuilder alloc] initWithMessageType:MPMessageTypeEvent
session:session
messageInfo:@{@"MessageKey1":@"MessageValue1"}];
MPMessage *message = [messageBuilder build];
[unlimitedMessages addObject:message];
}
Expand All @@ -1474,9 +1474,9 @@ - (void)testBatchAndMessageLimitsMultipleMessagesPerBatch {

- (void)testBatchAndMessageLimitsBytesPerBatch {
MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]];
MPMessageBuilder *messageBuilder = [MPMessageBuilder newBuilderWithMessageType:MPMessageTypeEvent
session:session
messageInfo:@{@"MessageKey1":@"MessageValue1"}];
MPMessageBuilder *messageBuilder = [[MPMessageBuilder alloc] initWithMessageType:MPMessageTypeEvent
session:session
messageInfo:@{@"MessageKey1":@"MessageValue1"}];
MPMessage *message = [messageBuilder build];

NSMutableArray *unlimitedMessages = [NSMutableArray array];
Expand All @@ -1503,9 +1503,9 @@ - (void)testBatchAndMessageLimitsBytesPerMessage {
while (longString.length < 1000) {
longString = [NSString stringWithFormat:@"%@%@", longString, longString];
}
MPMessageBuilder *messageBuilder = [MPMessageBuilder newBuilderWithMessageType:MPMessageTypeEvent
session:session
messageInfo:@{@"MessageKey1":longString}];
MPMessageBuilder *messageBuilder = [[MPMessageBuilder alloc] initWithMessageType:MPMessageTypeEvent
session:session
messageInfo:@{@"MessageKey1":longString}];
MPMessage *message = [messageBuilder build];
NSMutableArray *unlimitedMessages = [NSMutableArray array];
for (int i=0; i<10; i++) {
Expand Down Expand Up @@ -1534,9 +1534,9 @@ - (MPMessage *)messageWithType:(MPMessageType)type andLength:(NSInteger)length {
while (longString.length < length) {
longString = [NSString stringWithFormat:@"%@%@", longString, longString];
}
MPMessageBuilder *messageBuilder = [MPMessageBuilder newBuilderWithMessageType:type
session:session
messageInfo:@{@"MessageKey1":longString}];
MPMessageBuilder *messageBuilder = [[MPMessageBuilder alloc] initWithMessageType:type
session:session
messageInfo:@{@"MessageKey1":longString}];
MPMessage *message = [messageBuilder build];
NSInteger bytesToTruncate = message.messageData.length - length;
NSInteger bytesLongString = longString.length - bytesToTruncate;
Expand Down
36 changes: 18 additions & 18 deletions UnitTests/MPDataModelTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ - (void)testSessionInstance {
- (void)testMessageInstance {
MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]];

MPMessageBuilder *messageBuilder = [MPMessageBuilder newBuilderWithMessageType:MPMessageTypeEvent
session:session
messageInfo:@{@"MessageKey1":@"MessageValue1"}];
MPMessageBuilder *messageBuilder = [[MPMessageBuilder alloc] initWithMessageType:MPMessageTypeEvent
session:session
messageInfo:@{@"MessageKey1":@"MessageValue1"}];
XCTAssertNotNil(messageBuilder, @"Should not have been nil.");

MPMessage *message = [messageBuilder build];
Expand Down Expand Up @@ -159,9 +159,9 @@ - (void)testMessageInstanceWithInfinite {

double four = 4.0;
double zed = 0.0;
MPMessageBuilder *messageBuilder = [MPMessageBuilder newBuilderWithMessageType:MPMessageTypeEvent
session:session
messageInfo:@{@"MessageKey1":@(four/zed)}];
MPMessageBuilder *messageBuilder = [[MPMessageBuilder alloc] initWithMessageType:MPMessageTypeEvent
session:session
messageInfo:@{@"MessageKey1":@(four/zed)}];
XCTAssertNotNil(messageBuilder, @"Should not have been nil.");

MPMessage *message = [messageBuilder build];
Expand Down Expand Up @@ -193,9 +193,9 @@ - (void)testMessageInstanceWithInfinite {
- (void)testUploadInstance {
MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]];

MPMessageBuilder *messageBuilder = [MPMessageBuilder newBuilderWithMessageType:MPMessageTypeEvent
session:session
messageInfo:@{@"MessageKey1":@"MessageValue1"}];
MPMessageBuilder *messageBuilder = [[MPMessageBuilder alloc] initWithMessageType:MPMessageTypeEvent
session:session
messageInfo:@{@"MessageKey1":@"MessageValue1"}];
MPMessage *message = [messageBuilder build];

NSDictionary *uploadDictionary = @{kMPOptOutKey:@NO,
Expand Down Expand Up @@ -235,9 +235,9 @@ - (void)testUploadInstance {
- (void)testBreadcrumbInstance {
MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]];

MPMessageBuilder *messageBuilder = [MPMessageBuilder newBuilderWithMessageType:MPMessageTypeEvent
session:session
messageInfo:@{@"MessageKey1":@"MessageValue1"}];
MPMessageBuilder *messageBuilder = [[MPMessageBuilder alloc] initWithMessageType:MPMessageTypeEvent
session:session
messageInfo:@{@"MessageKey1":@"MessageValue1"}];
MPMessage *message = [messageBuilder build];

MPBreadcrumb *breadcrumb = [[MPBreadcrumb alloc] initWithSessionUUID:session.uuid
Expand Down Expand Up @@ -283,9 +283,9 @@ - (void)testBreadcrumbInstance {
- (void)testMessageEncoding {
MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]];

MPMessageBuilder *messageBuilder = [MPMessageBuilder newBuilderWithMessageType:MPMessageTypeEvent
session:session
messageInfo:@{@"MessageKey1":@"MessageValue1"}];
MPMessageBuilder *messageBuilder = [[MPMessageBuilder alloc] initWithMessageType:MPMessageTypeEvent
session:session
messageInfo:@{@"MessageKey1":@"MessageValue1"}];
MPMessage *message = [messageBuilder build];

XCTAssertNotNil(message, @"Should not have been nil.");
Expand All @@ -298,9 +298,9 @@ - (void)testMessageEncoding {
- (void)testBreadcrumbEncoding {
MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]];

MPMessageBuilder *messageBuilder = [MPMessageBuilder newBuilderWithMessageType:MPMessageTypeEvent
session:session
messageInfo:@{@"MessageKey1":@"MessageValue1"}];
MPMessageBuilder *messageBuilder = [[MPMessageBuilder alloc] initWithMessageType:MPMessageTypeEvent
session:session
messageInfo:@{@"MessageKey1":@"MessageValue1"}];
MPMessage *message = [messageBuilder build];

MPBreadcrumb *breadcrumb = [[MPBreadcrumb alloc] initWithSessionUUID:session.uuid
Expand Down
Loading