Skip to content

Fix flaky PurchaseControllerTests.testDownloadAsync test. #174

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

Merged
merged 1 commit into from
Sep 4, 2015
Merged
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
13 changes: 8 additions & 5 deletions Tests/Unit/PurchaseControllerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#import "PFTestSKProductsRequest.h"
#import "PFUnitTestCase.h"
#import "Parse_Private.h"
#import "BFTask+Private.h"

@interface PurchaseControllerTests : PFUnitTestCase
@end
Expand Down Expand Up @@ -233,21 +234,24 @@ - (void)testDownloadAssetAsync {

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

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

XCTestExpectation *expectation = [self currentSelectorTestExpectation];
XCTestExpectation *progressExpectation = [self expectationWithDescription:@"progress"];

__block int lastProgress = -1;
[[purchaseController downloadAssetAsyncForTransaction:transaction
withProgressBlock:^(int percentDone) {
XCTAssertGreaterThan(percentDone, lastProgress);

lastProgress = percentDone;

if (lastProgress == 100) {
[progressExpectation fulfill];
}
}
sessionToken:@"token"] continueWithExecutor:[BFExecutor mainThreadExecutor] withBlock:^id(BFTask *task) {
sessionToken:@"token"] continueWithBlock:^id(BFTask *task) {
XCTAssertFalse(task.faulted);
XCTAssertEqual(lastProgress, 100);

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

return nil;
}];

[self waitForTestExpectations];
}

Expand Down