10000 Remove unnecessary rmq database operations in unit tests. (#4236) · firebase/firebase-ios-sdk@c3d948e · GitHub
[go: up one dir, main page]

Skip to content

Commit c3d948e

Browse files
charlotteliangwu-hui
authored andcommitted
Remove unnecessary rmq database operations in unit tests. (#4236)
1 parent 623e277 commit c3d948e

9 files changed

+149
-125
lines changed

.travis.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -720,10 +720,6 @@ jobs:
720720
- PROJECT=Firestore PLATFORM=iOS METHOD=xcodebuild SANITIZERS=tsan
721721
- env:
722722
- PROJECT=GoogleDataTransportIntegrationTest PLATFORM=iOS METHOD=xcodebuild
723-
- env:
724-
- PROJECT=Messaging METHOD=pod-lib-lint
725-
- env:
726-
- PROJECT=MessagingCron METHOD=pod-lib-lint
727723

728724
# TODO(varconst): enable if it's possible to make this flag work on build
729725
# stages. It's supposed to avoid waiting for jobs that are allowed to fail

Example/Messaging/Tests/FIRInstanceIDWithFCMTest.m

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,55 +27,52 @@
2727
@interface FIRInstanceID (ExposedForTest)
2828
- (BOOL)isFCMAutoInitEnabled;
2929
- (instancetype)initPrivately;
30-
- (void)start;
31-
@end
32-
33-
@interface FIRMessaging ()
34-
+ (FIRMessaging *)messagingForTests;
3530
@end
3631

3732
@interface FIRInstanceIDTest : XCTestCase
3833

3934
@property(nonatomic, readwrite, strong) FIRInstanceID *instanceID;
4035
@property(nonatomic, readwrite, strong) id mockFirebaseApp;
36+
@property(nonatomic, readwrite, strong) FIRMessagingTestUtilities *testUtil;
37+
@property(nonatomic, strong) FIRMessaging *messaging;
38+
4139

4240
@end
4341

4442
@implementation FIRInstanceIDTest
4543

4644
- (void)setUp {
4745
[super setUp];
48-
_instanceID = [[FIRInstanceID alloc] initPrivately];
49-
[_instanceID start];
46+
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
47+
_testUtil = [[FIRMessagingTestUtilities alloc] initWithUserDefaults:defaults withRMQManager:NO];
48+
_instanceID = _testUtil.instanceID;
49+
_messaging = _testUtil.messaging;
5050
_mockFirebaseApp = OCMClassMock([FIRApp class]);
5151
OCMStub([_mockFirebaseApp defaultApp]).andReturn(_mockFirebaseApp);
5252
}
5353

5454
- (void)tearDown {
55-
self.instanceID = nil;
55+
[_testUtil cleanupAfterTest];
56+
_instanceID = nil;
57+
_messaging = nil;
5658
[_mockFirebaseApp stopMocking];
5759
[super tearDown];
5860
}
5961

6062
- (void)testFCMAutoInitEnabled {
61-
// Use the standardUserDefaults since that's what IID expects and depends on.
62-
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
63-
FIRMessaging *messaging = [FIRMessagingTestUtilities messagingForTestsWithUserDefaults:defaults];
64-
id classMock = OCMClassMock([FIRMessaging class]);
6563
OCMStub([_mockFirebaseApp isDataCollectionDefaultEnabled]).andReturn(YES);
66-
messaging.autoInitEnabled = YES;
64+
_messaging.autoInitEnabled = YES;
6765
XCTAssertTrue(
6866
[_instanceID isFCMAutoInitEnabled],
6967
@"When FCM is available, FCM Auto Init Enabled should be FCM's autoInitEnable property.");
7068

71-
messaging.autoInitEnabled = NO;
69+
_messaging.autoInitEnabled = NO;
7270
XCTAssertFalse(
7371
[_instanceID isFCMAutoInitEnabled],
7472
@"When FCM is available, FCM Auto Init Enabled should be FCM's autoInitEnable property.");
7573

76-
messaging.autoInitEnabled = YES;
74+
_messaging.autoInitEnabled = YES;
7775
XCTAssertTrue([_instanceID isFCMAutoInitEnabled]);
78-
[classMock stopMocking];
7976
}
8077

8178
@end

Example/Messaging/Tests/FIRMessagingHandlingTest.m

Lines changed: 46 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ @interface FIRMessaging ()
3838

3939
@property(nonatomic, readwrite, strong) NSString *defaultFcmToken;
4040
@property(nonatomic, readwrite, strong) FIRInstanceID *instanceID;
41-
@property(nonatomic, readwrite, strong) FIRMessagingRmqManager *rmq2Manager;
4241

4342
- (BOOL)handleContextManagerMessage:(NSDictionary *)message;
4443
- (void)handleIncomingLinkIfNeededFromMessage:(NSDictionary *)message;
@@ -52,12 +51,10 @@ - (void)handleIncomingLinkIfNeededFromMessage:(NSDictionary *)message;
5251
*/
5352
@interface FIRMessagingHandlingTest : XCTestCase
5453

55-
@property(nonatomic, readonly, strong) FIRMessaging *messaging;
5654
@property(nonatomic, strong) FIRMessagingAnalytics *messageAnalytics;
57-
@property(nonatomic, strong) id mockMessaging;
58-
@property(nonatomic, strong) id mockInstanceID;
5955
@property(nonatomic, strong) id mockFirebaseApp;
6056
@property(nonatomic, strong) id mockMessagingAnalytics;
57+
@property(nonatomic, strong) FIRMessagingTestUtilities *testUtil;
6158

6259
@end
6360

@@ -69,30 +66,23 @@ - (void)setUp {
6966
// Create the messaging instance with all the necessary dependencies.
7067
NSUserDefaults *defaults =
7168
EF2F [[NSUserDefaults alloc] initWithSuiteName:kFIRMessagingDefaultsTestDomain];
72-
_messaging = [FIRMessagingTestUtilities messagingForTestsWithUserDefaults:defaults];
69+
_testUtil = [[FIRMessagingTestUtilities alloc] initWithUserDefaults:defaults withRMQManager:YES];
7370
_mockFirebaseApp = OCMClassMock([FIRApp class]);
7471
OCMStub([_mockFirebaseApp defaultApp]).andReturn(_mockFirebaseApp);
75-
_mockInstanceID = OCMPartialMock(self.messaging.instanceID);
7672
[[NSUserDefaults standardUserDefaults]
7773
removePersistentDomainForName:[NSBundle mainBundle].bundleIdentifier];
78-
_mockMessaging = OCMPartialMock(_messaging);
7974
_mockMessagingAnalytics = OCMClassMock([FIRMessagingAnalytics class]);
8075
}
8176

8277
- (void)tearDown {
83-
[self.messaging.messagingUserDefaults removePersistentDomainForName:kFIRMessagingDefaultsTestDomain];
84-
self.messaging.shouldEstablishDirectChannel = NO;
85-
self.messaging.defaultFcmToken = nil;
78+
[_testUtil cleanupAfterTest];
8679
[_mockMessagingAnalytics stopMocking];
87-
[_mockMessaging stopMocking];
88-
[_mockInstanceID stopMocking];
8980
[_mockFirebaseApp stopMocking];
90-
_messaging = nil;
9181
[super tearDown];
9282
}
9383

9484
-(void)testEmptyNotification {
95-
XCTAssertEqualObjects(@(FIRMessagingMessageStatusUnknown), @([_mockMessaging appDidReceiveMessage:@{}].status));
85+
XCTAssertEqualObjects(@(FIRMessagingMessageStatusUnknown), @([_testUtil.mockMessaging appDidReceiveMessage:@{}].status));
9686
}
9787

9888
-(void)testAPNSDisplayNotification {
@@ -110,22 +100,21 @@ -(void)testAPNSDisplayNotification {
110100
@"google.c.a.ts" : @1566515009,
111101
@"google.c.a.udt" : @0
112102
};
113-
OCMExpect([_mockMessaging handleContextManagerMessage:notificationPayload]);
114-
OCMExpect([_mockMessaging handleIncomingLinkIfNeededFromMessage:notificationPayload]);
103+
OCMExpect([_testUtil.mockMessaging handleContextManagerMessage:notificationPayload]);
104+
OCMExpect([_testUtil.mockMessaging handleIncomingLinkIfNeededFromMessage:notificationPayload]);
115105
OCMExpect([_mockMessagingAnalytics logMessage:notificationPayload toAnalytics:[OCMArg any]]);
116106
XCTAssertEqualObjects(@(FIRMessagingMessageStatusNew),
117-
@([_messaging appDidReceiveMessage:notificationPayload].status));
118-
OCMVerifyAll(_mockMessaging);
107+
@([_testUtil.messaging appDidReceiveMessage:notificationPayload].status));
108+
OCMVerifyAll(_testUtil.mockMessaging);
119109

120-
OCMReject([_mockMessaging handleContextManagerMessage:notificationPayload]);
121-
OCMReject([_mockMessaging handleIncomingLinkIfNeededFromMessage:notificationPayload]);
110+
OCMReject([_testUtil.mockMessaging handleContextManagerMessage:notificationPayload]);
111+
OCMReject([_testUtil.mockMessaging handleIncomingLinkIfNeededFromMessage:notificationPayload]);
122112
OCMReject([_mockMessagingAnalytics logMessage:notificationPayload toAnalytics:[OCMArg any]]);
123113

124114
XCTAssertEqualObjects(@(FIRMessagingMessageStatusNew),
125-
@([_messaging appDidReceiveMessage:notificationPayload].status));
126-
OCMVerifyAll(_mockMessaging);
127-
// Clear database
128-
[_messaging.rmq2Manager deleteSyncMessageWithRmqID:@"1566515013484879"];
115+
@([_testUtil.messaging appDidReceiveMessage:notificationPayload].status));
116+
OCMVerifyAll(_testUtil.mockMessaging);
117+
129118
}
130119

131120
-(void)testAPNSContentAvailableNotification {
@@ -137,25 +126,25 @@ -(void)testAPNSContentAvailableNotification {
137126
@"image" : @"bunny.png",
138127
@"google.c.a.e" : @1
139128
};
140-
OCMExpect([_mockMessaging handleContextManagerMessage:notificationPayload]);
141-
OCMExpect([_mockMessaging handleIncomingLinkIfNeededFromMessage:notificationPayload]);
129+
OCMExpect([_testUtil.mockMessaging handleContextManagerMessage:notificationPayload]);
130+
OCMExpect([_testUtil.mockMessaging handleIncomingLinkIfNeededFromMessage:notificationPayload]);
142131
OCMExpect([_mockMessagingAnalytics logMessage:notificationPayload toAnalytics:[OCMArg any]]);
143132
XCTAssertEqualObjects(@(FIRMessagingMessageStatusNew),
144-
@([_messaging appDidReceiveMessage:notificationPayload].status));
145-
OCMVerifyAll(_mockMessaging);
133+
@([_testUtil.messaging appDidReceiveMessage:notificationPayload].status));
134+
OCMVerifyAll(_testUtil.mockMessaging);
146135

147-
OCMReject([_mockMessaging handleContextManagerMessage:notificationPayload]);
148-
OCMReject([_mockMessaging handleIncomingLinkIfNeededFromMessage:notificationPayload]);
136+
OCMReject([_testUtil.mockMessaging handleContextManagerMessage:notificationPayload]);
137+
OCMReject([_testUtil.mockMessaging handleIncomingLinkIfNeededFromMessage:notificationPayload]);
149138
OCMReject([_mockMessagingAnalytics logMessage:notificationPayload toAnalytics:[OCMArg any]]);
150139

151140
XCTAssertEqualObjects(@(FIRMessagingMessageStatusNew),
152-
@([_messaging appDidReceiveMessage:notificationPayload].status));
153-
OCMVerifyAll(_mockMessaging);
154-
[_messaging.rmq2Manager deleteSyncMessageWithRmqID:@"1566513591299872"];
141+
@([_testUtil.messaging appDidReceiveMessage:notificationPayload].status));
142+
OCMVerifyAll(_testUtil.mockMessaging);
155143

156144
}
157145

158146
-(void)testAPNSContentAvailableContextualNotification {
147+
159148
NSDictionary *notificationPayload = @{
160149
@"aps" : @{
161150
@"content-available": @1
@@ -173,21 +162,20 @@ -(void)testAPNSContentAvailableContextualNotification {
173162
@"google.c.cm.lt_end" : @"2019-09-20 13:12:00",
174163
@"google.c.cm.lt_start" : @"2019-08-23 13:12:00",
175164
};
176-
OCMExpect([_mockMessaging handleContextManagerMessage:notificationPayload]);
177-
OCMExpect([_mockMessaging handleIncomingLinkIfNeededFromMessage:notificationPayload]);
165+
OCMExpect([_testUtil.mockMessaging handleContextManagerMessage:notificationPayload]);
166+
OCMExpect([_testUtil.mockMessaging handleIncomingLinkIfNeededFromMessage:notificationPayload]);
178167
OCMExpect([_mockMessagingAnalytics logMessage:notificationPayload toAnalytics:[OCMArg any]]);
179168
XCTAssertEqualObjects(@(FIRMessagingMessageStatusNew),
180-
@([_messaging appDidReceiveMessage:notificationPayload].status));
181-
OCMVerifyAll(_mockMessaging);
169+
@([_testUtil.messaging appDidReceiveMessage:notificationPayload].status));
170+
OCMVerifyAll(_testUtil.mockMessaging);
182171

183-
OCMReject([_mockMessaging handleContextManagerMessage:notificationPayload]);
184-
OCMReject([_mockMessaging handleIncomingLinkIfNeededFromMessage:notificationPayload]);
172+
OCMReject([_testUtil.mockMessaging handleContextManagerMessage:notificationPayload]);
173+
OCMReject([_testUtil.mockMessaging handleIncomingLinkIfNeededFromMessage:notificationPayload]);
185174
OCMReject([_mockMessagingAnalytics logMessage:notificationPayload toAnalytics:[OCMArg any]]);
186175

187176
XCTAssertEqualObjects(@(FIRMessagingMessageStatusNew),
188-
@([_messaging appDidReceiveMessage:notificationPayload].status));
189-
OCMVerifyAll(_mockMessaging);
190-
[_messaging.rmq2Manager deleteSyncMessageWithRmqID:@"1566515531287827"];
177+
@([_testUtil.messaging appDidReceiveMessage:notificationPayload].status));
178+
OCMVerifyAll(_testUtil.mockMessaging);
191179

192180
}
193181

@@ -203,42 +191,41 @@ -(void)testContextualLocalNotification {
203191
@"google.c.a.ts" : @1566565920,
204192
@"google.c.a.udt" : @1,
205193
};
206-
OCMExpect([_mockMessaging handleContextManagerMessage:notificationPayload]);
207-
OCMExpect([_mockMessaging handleIncomingLinkIfNeededFromMessage:notificationPayload]);
194+
OCMExpect([_testUtil.mockMessaging handleContextManagerMessage:notificationPayload]);
195+
OCMExpect([_testUtil.mockMessaging handleIncomingLinkIfNeededFromMessage:notificationPayload]);
208196
OCMExpect([_mockMessagingAnalytics logMessage:notificationPayload toAnalytics:[OCMArg any]]);
209197
XCTAssertEqualObjects(@(FIRMessagingMessageStatusNew),
210-
@([_messaging appDidReceiveMessage:notificationPayload].status));
211-
OCMVerifyAll(_mockMessaging);
198+
@([_testUtil.messaging appDidReceiveMessage:notificationPayload].status));
199+
OCMVerifyAll(_testUtil.mockMessaging);
212200

213-
OCMReject([_mockMessaging handleContextManagerMessage:notificationPayload]);
214-
OCMReject([_mockMessaging handleIncomingLinkIfNeededFromMessage:notificationPayload]);
201+
OCMReject([_testUtil.mockMessaging handleContextManagerMessage:notificationPayload]);
202+
OCMReject([_testUtil.mockMessaging handleIncomingLinkIfNeededFromMessage:notificationPayload]);
215203
OCMReject([_mockMessagingAnalytics logMessage:notificationPayload toAnalytics:[OCMArg any]]);
216204

217205
XCTAssertEqualObjects(@(FIRMessagingMessageStatusNew),
218-
@([_messaging appDidReceiveMessage:notificationPayload].status));
219-
OCMVerifyAll(_mockMessaging);
220-
[_messaging.rmq2Manager deleteSyncMessageWithRmqID:@"1566515531281975"];
206+
@([_testUtil.messaging appDidReceiveMessage:notificationPayload].status));
207+
OCMVerifyAll(_testUtil.mockMessaging);
221208
}
222209

223210
-(void)testMCSNotification {
224211
NSDictionary *notificationPayload = @{
225212
@"from" : @"35006771263",
226< A839 /td>213
@"image" : @"bunny.png"
227214
};
228-
OCMExpect([_mockMessaging handleContextManagerMessage:notificationPayload]);
229-
OCMExpect([_mockMessaging handleIncomingLinkIfNeededFromMessage:notificationPayload]);
215+
OCMExpect([_testUtil.mockMessaging handleContextManagerMessage:notificationPayload]);
216+
OCMExpect([_testUtil.mockMessaging handleIncomingLinkIfNeededFromMessage:notificationPayload]);
230217
OCMExpect([_mockMessagingAnalytics logMessage:notificationPayload toAnalytics:[OCMArg any]]);
231218
XCTAssertEqualObjects(@(FIRMessagingMessageStatusNew),
232-
@([_messaging appDidReceiveMessage:notificationPayload].status));
233-
OCMVerifyAll(_mockMessaging);
219+
@([_testUtil.messaging appDidReceiveMessage:notificationPayload].status));
220+
OCMVerifyAll(_testUtil.mockMessaging);
234221

235-
OCMExpect([_mockMessaging handleContextManagerMessage:notificationPayload]);
236-
OCMExpect([_mockMessaging handleIncomingLinkIfNeededFromMessage:notificationPayload]);
222+
OCMExpect([_testUtil.mockMessaging handleContextManagerMessage:notificationPayload]);
223+
OCMExpect([_testUtil.mockMessaging handleIncomingLinkIfNeededFromMessage:notificationPayload]);
237224
OCMExpect([_mockMessagingAnalytics logMessage:notificationPayload toAnalytics:[OCMArg any]]);
238225

239226
XCTAssertEqualObjects(@(FIRMessagingMessageStatusNew),
240-
@([_messaging appDidReceiveMessage:notificationPayload].status));
241-
OCMVerifyAll(_mockMessaging);
227+
@([_testUtil.messaging appDidReceiveMessage:notificationPayload].status));
228+
OCMVerifyAll(_testUtil.mockMessaging);
242229
}
243230

244231
@end

Example/Messaging/Tests/FIRMessagingLinkHandlingTest.m

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ - (NSURL *)linkURLFromMessage:(NSDictionary *)message;
3535
@interface FIRMessagingLinkHandlingTest : XCTestCase
3636

3737
@property(nonatomic, readonly, strong) FIRMessaging *messaging;
38+
@property(nonatomic, strong) FIRMessagingTestUtilities * testUtil;
39+
3840

3941
@end
4042

@@ -44,11 +46,12 @@ - (void)setUp {
4446
[super setUp];
4547

4648
NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:kFIRMessagingTestsLinkHandlingSuiteName];
47-
_messaging = [FIRMessagingTestUtilities messagingForTestsWithUserDefaults:defaults];
49+
_testUtil = [[FIRMessagingTestUtilities alloc] initWithUserDefaults:defaults withRMQManager:NO];
50+
_messaging = _testUtil.messaging;
4851
}
4952

5053
- (void)tearDown {
51-
[self.messaging.messagingUserDefaults removePersistentDomainForName:kFIRMessagingTestsLinkHandlingSuiteName];
54+
[_testUtil cleanupAfterTest];
5255
_messaging = nil;
5356
[super tearDown];
5457
}
@@ -58,39 +61,39 @@ - (void)tearDown {
5861
- (void)testNonExistentLinkInMessage {
5962
NSMutableDictionary *notification =
6063
[FIRMessagingTestNotificationUtilities createBasicNotificationWithUniqueMessageID];
61-
NSURL *url = [self.messaging linkURLFromMessage:notification];
64+
NSURL *url = [_messaging linkURLFromMessage:notification];
6265
XCTAssertNil(url);
6366
}
6467

6568
- (void)testEmptyLinkInMessage {
6669
NSMutableDictionary *notification =
6770
[FIRMessagingTestNotificationUtilities createBasicNotificationWithUniqueMessageID];
6871
notification[kFIRMessagingMessageLinkKey] = @"";
69-
NSURL *url = [self.messaging linkURLFromMessage:notification];
72+
NSURL *url = [_messaging linkURLFromMessage:notification];
7073
XCTAssertNil(url);
7174
}
7275

7376
- (void)testNonStringLinkInMessage {
7477
NSMutableDictionary *notification =
7578
[FIRMessagingTestNotificationUtilities createBasicNotificationWithUniqueMessageID];
7679
notification[kFIRMessagingMessageLinkKey] = @(5);
77-
NSURL *url = [self.messaging linkURLFromMessage:notification];
80+
NSURL *url = [_messaging linkURLFromMessage:notification];
7881
XCTAssertNil(url);
7982
}
8083

8184
- (void)testInvalidURLStringLinkInMessage {
8285
NSMutableDictionary *notification =
8386
[FIRMessagingTestNotificationUtilities createBasicNotificationWithUniqueMessageID];
8487
notification[kFIRMessagingMessageLinkKey] = @"This is not a valid url string";
85-
NSURL *url = [self.messaging linkURLFromMessage:notification];
88+
NSURL *url = [_messaging linkURLFromMessage:notification];
8689
XCTAssertNil(url);
8790
}
8891

8992
- (void)testValidURLStringLinkInMessage {
9093
NSMutableDictionary *notification =
9194
[FIRMessagingTestNotificationUtilities createBasicNotificationWithUniqueMessageID];
9295
notification[kFIRMessagingMessageLinkKey] = @"https://www.google.com/";
93-
NSURL *url = [self.messaging linkURLFromMessage:notification];
96+
NSURL *url = [_messaging linkURLFromMessage:notification];
9497
XCTAssertTrue([url.absoluteString isEqualToString:@"https://www.google.com/"]);
9598
}
9699

0 commit comments

Comments
 (0)
0