Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

Data Not Available After Operation Completes Successfully #453

Open
kglee79 opened this issue Mar 12, 2015 · 0 comments
Open

Data Not Available After Operation Completes Successfully #453

kglee79 opened this issue Mar 12, 2015 · 0 comments

Comments

@kglee79
Copy link

kglee79 commented Mar 12, 2015

During testing I've found that it is possible that the operation state may be set to finished then back to executing due to the connection start occurring in a dispatch_async block and the operation state being updated to executing outside the block afterwards. Even though the operation completed successfully, the response data will not be made available since the responseData function checks for whether or not the state of the operation is finished. If it isn't, it will return nil.

Every so often during unit testing the operation will be executed, finish, and set the operation state to finished before control returns back to the dispatching function which then sets the state back to executing. I moved setting the state inside the dispatch_async function before the call to [self.connection start] to ensure it does not finish before being set to execute, however this seems a little off and am wondering if there is a better way to do this. I should also add that I am testing against a mock web server (Nocilla) so responses are much faster than they would be in a real world scenario, so it is highly unlikely this would happen in production and might only be an issue during testing.

In MKNetworkOperation:

    dispatch_async(dispatch_get_main_queue(), ^{
      self.connection = [[NSURLConnection alloc] initWithRequest:self.request
                                                        delegate:self
                                                startImmediately:NO];

      [self.connection scheduleInRunLoop:[NSRunLoop currentRunLoop]
                                 forMode:NSRunLoopCommonModes];

      [self.connection start];
    });

    self.state = MKNetworkOperationStateExecuting;
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant