21
21
#import " Crashlytics/Crashlytics/Private/FIRCLSOnDemandModel_Private.h"
22
22
#import " Crashlytics/UnitTests/Mocks/FIRAppFake.h"
23
23
#import " Crashlytics/UnitTests/Mocks/FIRCLSMockExistingReportManager.h"
24
+ #import " Crashlytics/UnitTests/Mocks/FIRCLSMockFileManager.h"
24
25
#import " Crashlytics/UnitTests/Mocks/FIRCLSMockOnDemandModel.h"
25
26
#import " Crashlytics/UnitTests/Mocks/FIRCLSMockReportUploader.h"
26
27
#import " Crashlytics/UnitTests/Mocks/FIRCLSMockSettings.h"
27
- #import " Crashlytics/UnitTests/Mocks/FIRCLSTempMockFileManager.h"
28
28
#import " Crashlytics/UnitTests/Mocks/FIRMockGDTCoreTransport.h"
29
29
#import " Crashlytics/UnitTests/Mocks/FIRMockInstallations.h"
30
30
@@ -40,7 +40,7 @@ @interface FIRCLSOnDemandModelTests : XCTestCase
40
40
@property (nonatomic , strong ) FIRCLSExistingReportManager *existingReportManager;
41
41
@property (nonatomic , strong ) FIRCLSManagerData *managerData;
42
42
@property (nonatomic , strong ) FIRCLSDataCollectionArbiter *dataArbiter;
43
- @property (nonatomic , strong ) FIRCLSTempMockFileManager *fileManager;
43
+ @property (nonatomic , strong ) FIRCLSMockFileManager *fileManager;
44
44
@property (nonatomic , strong ) FIRCLSMockReportUploader *mockReportUploader;
45
45
@property (nonatomic , strong ) FIRCLSMockSettings *mockSettings;
46
46
@@ -57,12 +57,13 @@ - (void)setUp {
57
57
id fakeApp = [[FIRAppFake alloc ] init ];
58
58
self.dataArbiter = [[FIRCLSDataCollectionArbiter alloc ] initWithApp: fakeApp withAppInfo: @{}];
59
59
60
- self.fileManager = [[FIRCLSTempMockFileManager alloc ] init ];
60
+ self.fileManager = [[FIRCLSMockFileManager alloc ] init ];
61
61
62
62
FIRCLSApplicationIdentifierModel *appIDModel = [[FIRCLSApplicationIdentifierModel alloc ] init ];
63
63
_mockSettings = [[FIRCLSMockSettings alloc ] initWithFileManager: self .fileManager
64
64
appIDModel: appIDModel];
65
65
_onDemandModel = [[FIRCLSMockOnDemandModel alloc ] initWithFIRCLSSettings: _mockSettings
66
+ fileManager: _fileManager
66
67
sleepBlock: ^(int delay){
67
68
}];
68
69
@@ -94,6 +95,7 @@ - (void)setUp {
94
95
FIRCLSInternalReport *report =
95
96
[[FIRCLSInternalReport alloc ] initWithPath: reportPath
96
97
executionIdentifier: @" TEST_EXECUTION_IDENTIFIER" ];
98
+
97
99
FIRCLSContextInitialize (report, self.mockSettings , self.fileManager );
98
100
}
99
101
@@ -133,14 +135,14 @@ - (void)testIncrementsQueueWhenEventRecorded {
133
135
134
136
- (void )testCompliesWithDataCollectionOff {
135
137
FIRExceptionModel *exceptionModel = [self getTestExceptionModel ];
136
- XCTestExpectation *testComplete =
138
+ XCTestExpectation *sleepComplete =
137
139
[[XCTestExpectation alloc ] initWithDescription: @" complete test" ];
138
140
139
141
// Put an expectation in the sleep block so we can test the state of the queue.
140
142
__weak FIRCLSOnDemandModelTests *weakSelf = self;
141
143
[self setSleepBlock: ^(int delay) {
142
144
XCTAssertEqual (delay, 60 / self.mockSettings .onDemandUploadRate );
143
- [weakSelf waitForExpectations: @[ testComplete ] timeout: 1.0 ];
145
+ [weakSelf waitForExpectations: @[ sleepComplete ] timeout: 1.0 ];
144
146
}];
145
147
146
148
BOOL success = [self .onDemandModel recordOnDemandExceptionIfQuota: exceptionModel
@@ -149,14 +151,18 @@ - (void)testCompliesWithDataCollectionOff {
149
151
150
152
// Should record but not submit a report.
151
153
XCTAssertTrue (success);
154
+
152
155
// We still count this as a recorded event if it was recorded but not submitted.
153
156
XCTAssertEqual ([self .onDemandModel recordedOnDemandExceptionCount ], 1 );
154
- XCTAssertEqual ([self contentsOfActivePath ].count , 2 );
155
157
XCTAssertEqual (self.onDemandModel .getQueuedOperationsCount , 1 );
156
- XCTAssertEqual ([self .onDemandModel.storedActiveReportPaths count ], 1 );
157
158
158
159
// Fulfill the expectation so the sleep block completes.
159
- [testComplete fulfill ];
160
+ [sleepComplete fulfill ];
161
+ [self .managerData.onDemandModel.operationQueue waitUntilAllOperationsAreFinished ];
162
+
163
+ XCTAssertEqual (self.onDemandModel .getQueuedOperationsCount , 0 );
164
+ XCTAssertEqual ([self contentsOfActivePath ].count , 1 );
165
+ XCTAssertEqual ([self .onDemandModel.storedActiveReportPaths count ], 1 );
160
166
}
161
167
162
168
- (void )testQuotaWithDataCollectionOff {
@@ -179,7 +185,7 @@ - (void)testQuotaWithDataCollectionOff {
179
185
180
186
XCTAssertEqual ([self .managerData.onDemandModel recordedOnDemandExceptionCount ],
181
187
FIRCLSMaxUnsentReports);
182
- XCTAssertEqual ([self contentsOfActivePath ].count , FIRCLSMaxUnsentReports + 1 );
188
+ XCTAssertEqual ([self contentsOfActivePath ].count , FIRCLSMaxUnsentReports);
183
189
XCTAssertEqual ([self .managerData.onDemandModel.storedActiveReportPaths count ],
184
190
FIRCLSMaxUnsentReports);
185
191
@@ -188,7 +194,8 @@ - (void)testQuotaWithDataCollectionOff {
188
194
asUrgent: YES ];
189
195
XCTAssertEqual ([self .managerData.onDemandModel recordedOnDemandExceptionCount ],
190
196
FIRCLSMaxUnsentReports);
191
- XCTAssertEqual ([self contentsOfActivePath ].count , 1 );
197
+ [self .existingReportManager.operationQueue waitUntilAllOperationsAreFinished ];
198
+ XCTAssertEqual ([self contentsOfActivePath ].count , 0 );
192
199
XCTAssertEqual ([self .managerData.onDemandModel.storedActiveReportPaths count ], 0 );
193
200
}
194
201
@@ -234,8 +241,7 @@ - (void)testDroppedEventCountResets {
234
241
235
242
#pragma mark - Helpers
236
243
- (NSArray *)contentsOfActivePath {
237
- return [[NSFileManager defaultManager ] contentsOfDirectoryAtPath: self .fileManager.activePath
238
- error: nil ];
244
+ return [self .fileManager activePathContents ];
239
245
}
240
246
241
247
- (FIRExceptionModel *)getTestExceptionModel {
0 commit comments