Skip to content
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

ObjC tests: Questionable API usage errors #86

Merged
merged 2 commits into from
Nov 26, 2015

Conversation

ricardopereira
Copy link
Contributor

No description provided.

@ricardopereira
Copy link
Contributor Author

2015-11-25 08:42:23.973 xctest[37800:1214684] Questionable API usage: creating XCTestExpectation for test case -[ARTRealtimeChannelHistoryTest testHistoryFromAttach] which is not the currently running test case -[ARTRealtimeChannelHistoryTest testTimeBackwards]
2015-11-25 08:42:25.679 xctest[37800:1214684] Questionable API usage: called -[XCTestExpectation fulfill] for send_first_batch after the test case in which the expectation was created is no longer running. Created in test -[ARTRealtimeChannelHistoryTest testHistoryFromAttach], current test is -[ARTRealtimeChannelHistoryTest testTimeBackwards]
2015-11-25 08:42:25.680 xctest[37800:1214684] Questionable API usage: creating XCTestExpectation for test case -[ARTRealtimeChannelHistoryTest testHistoryFromAttach] which is not the currently running test case -[ARTRealtimeChannelHistoryTest testTimeBackwards]
2015-11-25 08:42:26.012 xctest[37800:1214684] Questionable API usage: called -[XCTestExpectation fulfill] for get_history_channel2 after the test case in which the expectation was created is no longer running. Created in test -[ARTRealtimeChannelHistoryTest testHistoryFromAttach], current test is -[ARTRealtimeChannelHistoryTest testTimeBackwards]

 - Changed `publishRealtimeMessages`. Use a callback instead of
`(XCTestExpectation *)expectation`.
 - Changed `publishRealtimeMessages `. Use a callback instead of
`(XCTestExpectation *)expectation`.
 - Changed `publishEnterMessages `. Use a callback instead of
`(XCTestExpectation *)expectation`.
 - Ignored `test250ClientsEnter` (in comment because I didn't find the
source of the problem: `failed: caught "NSRangeException", "***
-[NSArray subarrayWithRange:]: range {0, 2} extends beyond bounds [0 ..
0]"`)
 - Ignored `testSyncResumes` (in comment because I didn't find the
source of the problem: `failed: caught "NSRangeException", "***
-[NSArray subarrayWithRange:]: range {0, 2} extends beyond bounds [0 ..
0]"`)
 - Removed `testPublish_20_200`. We have `testPublish_10_1000` and
`testMultipleText_1000_10` already.
 - Removed `testHistoryUntilAttach` because it was incomplete
@ricardopereira
Copy link
Contributor Author

  • Changed publishRealtimeMessages. Use a callback instead of (XCTestExpectation *)expectation.
  • Changed publishRealtimeMessages. Use a callback instead of (XCTestExpectation *)expectation.
  • Changed publishEnterMessages. Use a callback instead of (XCTestExpectation *)expectation.
  • Ignored test250ClientsEnter (in comment because I didn't find the source of the problem: failed: caught "NSRangeException", "*** -[NSArray subarrayWithRange:]: range {0, 2} extends beyond bounds [0 .. 0]")
  • Ignored testSyncResumes (in comment because I didn't find the source of the problem: failed: caught "NSRangeException", "*** -[NSArray subarrayWithRange:]: range {0, 2} extends beyond bounds [0 .. 0]")
  • Removed testPublish_20_200. We have testPublish_10_1000 and testMultipleText_1000_10 already.
  • Removed testHistoryUntilAttach because it was incomplete

@ricardopereira
Copy link
Contributor Author

ObjC tests:
** TEST SUCCEEDED: 152 passed, 0 failed, 0 errored, 152 total ** (550821 ms)

Swift tests (without #85):
** TEST FAILED: 127 passed, 12 failed, 1 errored, 140 total ** (299369 ms)

@ricardopereira
Copy link
Contributor Author

Odd errors on Travis:

RestClient__logging__should_output_to_the_system_log_and_the_log_level_should_be_Warn

2015-11-25 14:25:41.550 xctest[1879:6136] WARN: This is a warning
/Users/travis/build/ably/ably-ios/ablySpec/RestClient.swift:92: failed - expected to contain <WARN: This is a warning>, got <Swift._FunctionGenerator<Swift.String>>

RestClient__channels__get__should_return_a_channel_with_the_provided_options

Invalid connection: com.apple.coresymbolicationd

@mattheworiordan
Copy link
Member

Not really sure what I am supposed to do with this? It would be a lot more useful to have a PR with a summary of what it fixes as this seems to be a work in progress branch of some sort?

@ricardopereira
Copy link
Contributor Author

@mattheworiordan The branch is ready to merge. Sorry about the mess but I had to change a lot of code. When a test uses a callback it is necessary to create a XCTestExpectation to ensure the test does not finish until the asynchronous call is done. You need to create the XCTestExpectation before the asynchronous code but some of them were created inside the callback and that was breaking the tests. For example, testHistoryFromAttach continues the work after the test has finished.

Old:

- (void)testHistoryFromAttach {
    ...

    [ARTTestUtil setupApp:[ARTTestUtil clientOptions] cb:^(ARTClientOptions *options) {
        XCTestExpectation *firstExpectation = [self expectationWithDescription:@"send_first_batch"];
        ARTRealtime * realtime =[[ARTRealtime alloc] initWithOptions:options];
        _realtime = realtime;

        for (int i=0; i < firstBatchTotal; i++) {
            ...
            [firstExpectation fulfill];
        }

        [self waitForExpectationsWithTimeout:[ARTTestUtil timeout] handler:nil];

        XCTestExpectation *secondExpecation = [self expectationWithDescription:@"get_history_channel2"];

        [channel2 history:query callback:^(ARTPaginatedResult *result, NSError *error) {        
            ... 
            [secondExpecation fulfill];     
        }];

        [self waitForExpectationsWithTimeout:[ARTTestUtil timeout] handler:nil];
    }
}

New:

- (void)testHistoryFromAttach {
    ...

    XCTestExpectation *expectation = [self expectationWithDescription:@"batch"];    
    [ARTTestUtil setupApp:[ARTTestUtil clientOptions] cb:^(ARTClientOptions *options) {
        ARTRealtime * realtime =[[ARTRealtime alloc] initWithOptions:options];
        _realtime = realtime;

        for (int i=0; i < firstBatchTotal; i++) {
            ...
        }

        [channel2 history:query callback:^(ARTPaginatedResult *result, NSError *error) {        
            ... 
            [expectation fulfill];      
        }];
    }
    [self waitForExpectationsWithTimeout:[ARTTestUtil timeout] handler:nil];
}

@mattheworiordan
Copy link
Member

Ok, well I will merge on the basis that this is a bunch of fixups as I've not reviewed the code in detail.

mattheworiordan added a commit that referenced this pull request Nov 26, 2015
ObjC tests: Questionable API usage errors
@mattheworiordan mattheworiordan merged commit 6cca442 into master Nov 26, 2015
@ricardopereira ricardopereira deleted the objc-tests-questionable-api branch January 5, 2016 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants