-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
fix NetworkingModule NoContentType test now that didCompleteNetworkRe… #414
fix NetworkingModule NoContentType test now that didCompleteNetworkRe… #414
Conversation
…sponse emits three args
Actually, if the |
Thanks @FLGMwt. Currently, the EventEmitter and the InvocationHandler are synchronous in test because the InvocationHandler doesn't actually push to the JavaScript thread. I think we left in the EventWaitHandle in case the base class ever changed to auto-switch to the JS thread for instance, but that actually does seem unlikely. We could probably delete them. |
if (name != "emit" || args.Length != 2 || ((string)args[0]) != "didCompleteNetworkResponse") | ||
{ | ||
return; | ||
} | ||
|
||
var array = args[1] as JArray; | ||
if (array == null || array.Count != 2) | ||
if (array == null || array.Count != 3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should fix the root issue here, and only send the canceled flag if the value is true. It will save the extra cycles from having to serialize a boolean.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean changing NetworkingModule.OnRequestError
to be something like this?
private void OnRequestError(int requestId, string message, bool timeout)
{
if (timeout)
{
EventEmitter.emit("didCompleteNetworkResponse", new JArray
{
requestId,
message,
true
});
}
else
{
EventEmitter.emit("didCompleteNetworkResponse", new JArray
{
requestId,
message
});
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be cleaner to just have:
private void OnRequestError(int requestId, string message)
{
...
}
private void OnRequestError(int requestId, string message, bool timeout)
{
...
}
Same number of lines, one less conditional check :-).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, how about
private void OnRequestError(int requestId, string message)
{
EventEmitter.emit("didCompleteNetworkResponse", new JArray
{
requestId,
message
});
}
private void OnRequestErrorDueToTimeout(int requestId, string message)
{
EventEmitter.emit("didCompleteNetworkResponse", new JArray
{
requestId,
message,
true
});
}
to save the bool check and the unnecessary bool arg? : ) Open to suggestions for naming OnRequestErrorDueToTimeout
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, or even just OnRequestTimeout ;-).
I'm going to leave this closed for now. I took your original suggestion and just updated the unit test. May make sense still to create a new PR for the "optimization". |
Summary: If we don't measure exactly, percentage values aren't exactly either. Fix for #414. Closes facebook/yoga#416 Closes facebook/yoga#414 Reviewed By: astreet Differential Revision: D4604729 Pulled By: emilsjolander fbshipit-source-id: 66880230073209cbe89668b838c2a82e7f9b34df
Motivation: testing conditions of the
NetworkingModule_Request_Content_String_NoContentType
test are no longer valid as of #382, sincedidCompleteNetworkResponse
now emits three arguments. Since the test failure caused a return before theEventWaitHandle
was triggered, the test hung indefinitely. After correcting the test conditions, the test passes.In addition to correcting the test condition, I reworked the use of the
waitHandle
to prevent the indefinite hang should the test fail in the future. I'm fairly certain we're safe to unconditionally trigger the handle as soon as we enter theMockInvocationHandler
and only rely on the testing conditions for thepassed
flag. I tested this by adding aTask.Delay(5000).Wait()
after thewaitHandle.Set()
as it is in this PR. I saw the invocation handler was allowed to execute to completion, with thepassed
flag being allowed to be set properly before continuation of the test.Unless I'm missing something, I thing this could be an issue with many of the tests in the project where we're only triggering the wait handle for the happy path. For example, in
NetworkingModule_Response_Content
, if I change"didReceiveNetworkData"
to"definitelyNotDidReceiveNetworkData"
(reflecting a potential name change dispatched event), I see the same indefinite hang.If I'm not missing something, I can create an issue to investigate this throughout the tests. At a minimum, I think I have enough context to look into #288