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(android): fix onprogress payload value for data other than HashMap #11168
Conversation
request's length was not accounted for data of type different from HashMap, thus not reporting the progress properly in the callback
|
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.
CR: PASS
@@ -1279,7 +1274,7 @@ public void run() | |||
public void progress(int progress) | |||
{ | |||
KrollDict data = new KrollDict(); | |||
double currentProgress = ((double) progress / totalLength); | |||
double currentProgress = ((double) progress / contentLength); |
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.
@ypbnv, we should check if content length is zero. I can see this potentially happening with an HTTP "PUT" without a body.
public void progress(int progress)
{
if (contentLength <= 0) {
return;
}
// The rest of the code goes here...
}
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.
Done.
FR Passed. |
@ypbnv, can you look into the unit test failure please? That's the only thing blocking this PR. Thanks! |
Looks like this has broke |
After some more research - It fails because the test is successful when the progress event callback returns 1. This happened before, because it was calculated using the removed Apparently on iOS you can get the same progress value multiple times, so this is why the latest unit test fails there. It is expecting to get gradually increasing values from the event between 0 and 1. I am not really sure if this is a good way to report progress though. This ends up with the question - should we expect the progress event to always end up with 1? It makes sense that a 100% is part of the progress change, but for now it is not always happening in Android. One way would be to adjust the native code to always end up with 1 or we should change the unit test to not expect 1 for a successful run. I suppose it is a matter of parity with iOS. |
…into TIMOB-27293
Yes, the progress should be |
@ypbnv, add the following code to the private class ProgressOutputStream extends FilterOutputStream
{
// Existing code is here...
@Override
public void close() throws IOException
{
super.close();
if (!aborted && (transferred > 0)) {
lastTransferred = transferred;
listener.progress(transferred);
}
}
} Ideally, the progress handling should be redesigned, but I can live with this. |
remove redundant test file and ensure progress triggers 1 as a callback every time
@jquick-axway Added the snippet and also moved the closing of PrintWriter to happen for request that do not need multipart too. |
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.
CR: Pass
JIRA: https://jira.appcelerator.org/browse/TIMOB-27293
Description:
Request's length was not accounted for data of type different from HashMap, thus not reporting the
progress properly in the callback. Also there was a duplication in calculating a request's data size, so I removed the redundant variable. I believe all the cases are covered from the code that is left.
Working on a dedicated unit test for this.
Edit: Added the unit test.
Test case:
The JIRA ticket has a good code sample for testing.