Skip to content

Commit 04eddbc

Browse files
committed
Fix flaky PurchaseControllerTests.testDownloadAsync test.
1 parent 2e899eb commit 04eddbc

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

Tests/Unit/PurchaseControllerTests.m

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#import "PFTestSKProductsRequest.h"
3030
#import "PFUnitTestCase.h"
3131
#import "Parse_Private.h"
32+
#import "BFTask+Private.h"
3233

3334
@interface PurchaseControllerTests : PFUnitTestCase
3435
@end
@@ -233,21 +234,24 @@ - (void)testDownloadAssetAsync {
233234

234235
NSString *tempDirectory = [NSTemporaryDirectory() stringByAppendingPathComponent:[[NSUUID UUID] UUIDString]];
235236

236-
OCMStub([[commandRunner ignoringNonObjectArgs] runCommandAsync:OCMOCK_ANY withOptions:0]).andReturn(mockedTask);
237+
OCMStub([[commandRunner ignoringNonObjectArgs] runCommandAsync:[OCMArg isNotNil] withOptions:0]).andReturn(mockedTask);
237238
OCMStub([fileManager parseDataItemPathForPathComponent:@"product"]).andReturn(tempDirectory);
238239

239240
XCTestExpectation *expectation = [self currentSelectorTestExpectation];
241+
XCTestExpectation *progressExpectation = [self expectationWithDescription:@"progress"];
240242

241243
__block int lastProgress = -1;
242244
[[purchaseController downloadAssetAsyncForTransaction:transaction
243245
withProgressBlock:^(int percentDone) {
244246
XCTAssertGreaterThan(percentDone, lastProgress);
245-
246247
lastProgress = percentDone;
248+
249+
if (lastProgress == 100) {
250+
[progressExpectation fulfill];
251+
}
247252
}
248-
sessionToken:@"token"] continueWithExecutor:[BFExecutor mainThreadExecutor] withBlock:^id(BFTask *task) {
253+
sessionToken:@"token"] continueWithBlock:^id(BFTask *task) {
249254
XCTAssertFalse(task.faulted);
250-
XCTAssertEqual(lastProgress, 100);
251255

252256
NSData *contentsOfFile = [NSData dataWithContentsOfFile:task.result];
253257
XCTAssertEqualObjects(contentsOfFile, [self sampleData]);
@@ -256,7 +260,6 @@ - (void)testDownloadAssetAsync {
256260

257261
return nil;
258262
}];
259-
260263
[self waitForTestExpectations];
261264
}
262265

0 commit comments

Comments
 (0)