Skip to content

Commit

Permalink
Synchronize sending message in CBLMockConnection (#2694)
Browse files Browse the repository at this point in the history
* Synchronize sending message in CBLMockConnection

* The message could be sent out-of-order and that causes the tests to failed intermittenly due to the error such as “CouchbaseLite Network ERROR: {BLIPIO#5489} Caught exception handling incoming BLIP message: BLIP protocol error: Bad incoming REQ #2 (too high)”.
* Synchronizing the sending message to prevent message out-of-order.

CBL-1092

* Add comment
  • Loading branch information
pasin authored Jun 26, 2020
1 parent 7f036a1 commit cf0e423
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions Objective-C/Tests/Util/CBLMockConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,21 @@ - (void) open: (id<CBLReplicatorConnection>)connection completion: (void (^)(BOO
}

- (void) send: (CBLMessage*)message completion: (void (^)(BOOL success, CBLMessagingError* _Nullable))completion {
NSLog(@"%@: Sending message ...", self);
CBLMessagingError* error;
if(self.isClient && [self.errorLogic shouldCloseAtLocation: kCBLMockConnectionSend]) {
error = [self.errorLogic createError];
NSLog(@"%@: Send message failed with error : %@", self, error);
[self connectionBroken: error];
} else {
[self performWrite: [message toData]];
NSLog(@"%@: Send message completed", self);
// Synchronize to prevent message getting sent out-of-order:
@synchronized (self) {
NSLog(@"%@: Sending message ...", self);
CBLMessagingError* error;
if(self.isClient && [self.errorLogic shouldCloseAtLocation: kCBLMockConnectionSend]) {
error = [self.errorLogic createError];
NSLog(@"%@: Send message failed with error : %@", self, error);
[self connectionBroken: error];
} else {
[self performWrite: [message toData]];
NSLog(@"%@: Send message completed", self);
}
NSLog(@"%@: Complete send message with error: %@", self, error);
completion(!error, error);
}
NSLog(@"%@: Complete send message with error: %@", self, error);
completion(!error, error);
}

- (void) close: (NSError*)error completion: (void (^)(void))completion {
Expand Down

0 comments on commit cf0e423

Please sign in to comment.