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

Add more sync points to await action results before sending done messages #984

Merged
merged 1 commit into from
Oct 17, 2018
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
28 changes: 20 additions & 8 deletions detox/ios/Detox/DetoxManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,26 @@ - (void)websocketDidConnect
if (![ReactNativeSupport isReactNativeApp])
{
_isReady = YES;
[self.webSocket sendAction:@"ready" withParams:@{} withMessageId:@-1000];
[self _safeSendAction:@"ready" params:@{} messageId:@-1000];
}
}

- (void)_safeSendAction:(NSString*)action params:(NSDictionary*)params messageId:(NSNumber*)messageId
{
[EarlGrey detox_safeExecuteSync:^{
[self.webSocket sendAction:action withParams:params withMessageId:messageId];
}];
}

- (void)websocketDidReceiveAction:(NSString *)type withParams:(NSDictionary *)params withMessageId:(NSNumber *)messageId
{
NSAssert(messageId != nil, @"Got action with a null messageId");

if([type isEqualToString:@"invoke"])
if([type isEqualToString:@"waitForIdle"])
{
[self _safeSendAction:@"waitForIdleDone" params:@{} messageId: messageId];
}
else if([type isEqualToString:@"invoke"])
{
[self.testRunner invoke:params withMessageId:messageId];
return;
Expand All @@ -139,7 +150,7 @@ - (void)websocketDidReceiveAction:(NSString *)type withParams:(NSDictionary *)pa
{
if(_isReady)
{
[self.webSocket sendAction:@"ready" withParams:@{} withMessageId:@-1000];
[self _safeSendAction:@"ready" params:@{} messageId:@-1000];
}
return;
}
Expand All @@ -156,7 +167,7 @@ - (void)websocketDidReceiveAction:(NSString *)type withParams:(NSDictionary *)pa
void (^block)(void);
//Send webSocket and messageId as params so the block is of global type, instead of being allocated on every message.
void (^sendDoneAction)(WebSocket* webSocket, NSNumber* messageId) = ^ (WebSocket* webSocket, NSNumber* messageId) {
[webSocket sendAction:@"deliverPayloadDone" withParams:@{} withMessageId: messageId];
[self _safeSendAction:@"deliverPayloadDone" params:@{} messageId: messageId];
};

if(params[@"url"])
Expand Down Expand Up @@ -221,7 +232,7 @@ - (void)websocketDidReceiveAction:(NSString *)type withParams:(NSDictionary *)pa
[EarlGrey detox_safeExecuteSync:^{
[self _sendShakeNotification];

[self.webSocket sendAction:@"shakeDeviceDone" withParams:@{} withMessageId: messageId];
[self _safeSendAction:@"shakeDeviceDone" params:@{} messageId: messageId];
}];
}
else if([type isEqualToString:@"reactNativeReload"])
Expand Down Expand Up @@ -260,19 +271,20 @@ - (void)testRunnerOnInvokeResult:(id)res withMessageId:(NSNumber *)messageId
{
res = [NSString stringWithFormat:@"(%@)", NSStringFromClass([res class])];
}
[self.webSocket sendAction:@"invokeResult" withParams:@{@"result": res} withMessageId:messageId];

[self _safeSendAction:@"invokeResult" params:@{@"result": res} messageId:messageId];
}

- (void)testRunnerOnTestFailed:(NSString *)details withMessageId:(NSNumber *) messageId
{
if (details == nil) details = @"";
[self.webSocket sendAction:@"testFailed" withParams:@{@"details": details} withMessageId:messageId];
[self _safeSendAction:@"testFailed" params:@{@"details": details} messageId:messageId];
}

- (void)testRunnerOnError:(NSString *)error withMessageId:(NSNumber *) messageId
{
if (error == nil) error = @"";
[self.webSocket sendAction:@"error" withParams:@{@"error": error} withMessageId:messageId];
[self _safeSendAction:@"error" params:@{@"error": error} messageId:messageId];
}

- (void)notifyOnCrashWithDetails:(NSDictionary*)details
Expand Down