Skip to content

Commit 275242b

Browse files
committed
Fix flaky PurchaseControllerTests.testDownloadAsync test.
1 parent 2e899eb commit 275242b

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Tests/Unit/PurchaseControllerTests.m

Lines changed: 7 additions & 4 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,22 @@ - (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+
[progressExpectation fulfill];
247250
}
248251
sessionToken:@"token"] continueWithExecutor:[BFExecutor mainThreadExecutor] withBlock:^id(BFTask *task) {
249252
XCTAssertFalse(task.faulted);
250-
XCTAssertEqual(lastProgress, 100);
251253

252254
NSData *contentsOfFile = [NSData dataWithContentsOfFile:task.result];
253255
XCTAssertEqualObjects(contentsOfFile, [self sampleData]);
@@ -256,8 +258,9 @@ - (void)testDownloadAssetAsync {
256258

257259
return nil;
258260
}];
259-
260261
[self waitForTestExpectations];
262+
263+
XCTAssertEqual(lastProgress, 100);
261264
}
262265

263266
- (void)testDownloadInvalidReceipt {

0 commit comments

Comments
 (0)