mercredi 2 septembre 2015

My Test case never ends

I am trying to test an async request to the server. I send the request, get the response, but then the test hangs and does not end

this is my test :

-(void)testClearAppsCache{
    XCTestExpectation *expectation = [self expectationWithDescription:@"callServicesWithParameters"];
    [self.apiClient callServicesWithParameters:nil//@{@"version":@""}
                                       success:^(BridgeModel *bridge) {
                                           BOOL onMainThread = [NSThread isMainThread];
                                           XCTAssertFalse(onMainThread,@"should be on main thread");
                                           XCTAssertNotNil(bridge);
                                           [expectation fulfill];
                                           NSLog(@"done");
                                       }

                                       failure: ^(NSError * error) {
                                           [expectation fulfill];
                                           LogInfo(@"error gettings services:%@",error);
                                       }];

    [self waitForExpectationsWithTimeout:5.0 handler:^(NSError *error) {
        NSLog(@"waiting for expectation");
        if(error){
            NSLog(@"error:%@",error);
            XCTFail(@"error:%@",error);
        }else {
            XCTAssertNil(error,@"test finished");
        }
    }];

    NSLog(@"done testing");

}

This is the log that is printed after the test:

2015-09-03 00:16:00.758 MyApp[1960:35258312] I,-[AppDelegate application:didFinishLaunchingWithOptions:]:55 application:didFinishLaunchingWithOptions:
2015-09-03 00:16:00.851 MyApp[1960:35258312] Request http://ift.tt/1EC6DAl?
Test Suite 'Selected tests' started at 2015-09-02 21:16:01 +0000
Test Suite 'MyApp Tests.xctest' started at 2015-09-02 21:16:01 +0000
Test Suite 'ManagerTests' started at 2015-09-02 21:16:01 +0000

2015-09-03 00:16:01.151 MyApp[1960:35258312] I,-[apiClient sendRequest:]:515
sending GET request to path:http:...
2015-09-03 00:16:01.152 MyApp[1960:35258312] D,-[apiClient sendRequest:]:516

2015-09-03 00:16:01.152 MyApp[1960:35258312] D,-[apiClient asyncRequestDataForServerRequest:]:161 added '?'
2015-09-03 00:16:01.152 MyApp[1960:35258312] D,-[apiClient asyncRequestDataForServerRequest:]:165 path with params:http://ift.tt/1EC6DAl?
2015-09-03 00:16:01.152 MyApp[1960:35258312] D,-[apiClient startRequest:]:183 started connection
2015-09-03 00:16:01.902 MyApp[1960:35258364] D,-[apiClient connection:didReceiveResponse:]:249 Response recieved from url:http://ift.tt/1EC6DAl?
2015-09-03 00:16:01.902 MyApp[1960:35258348] D,-[apiClient connectionDidFinishLoading:]:267 Data recieved:
2015-09-03 00:16:01.904 MyApp[1960:35258348] D,-[apiClient connectionDidFinishLoading:]:268 statusCode:200
2015-09-03 00:16:03.940 MyApp[1960:35258348] D,-[apiClient connectionDidFinishLoading:]:277 onMainThread?0
2015-09-03 00:16:05.189 MyApp[1960:35258348] done

The request runs and succeeds, receives correct response and status code, the success block runs, however after the success block is finished, nothing happens, the test sort of hangs - how can i fix that ?

Aucun commentaire:

Enregistrer un commentaire