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

fix(android): fix onprogress payload value for data other than HashMap #11168

Merged
merged 26 commits into from Oct 21, 2019

Conversation

ypbnv
Copy link
Contributor

@ypbnv ypbnv commented Aug 22, 2019

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.

request's length was not accounted for data of type different from HashMap, thus not reporting the
progress properly in the callback
@ypbnv ypbnv added this to the 8.3.0 milestone Aug 22, 2019
@ypbnv ypbnv requested a review from garymathews August 22, 2019 15:21
@build build requested a review from a team August 22, 2019 15:45
@build
Copy link
Contributor

build commented Aug 22, 2019

Messages
📖

💾 Here's the generated SDK zipfile.

📖

✅ All tests are passing
Nice one! All 4405 tests are passing.
(There are 479 skipped tests not included in that total)

📖 ✊ The commits in this PR match our conventions! Feel free to Rebase and Merge this PR when ready.

Generated by 🚫 dangerJS against b5ef204

Copy link
Contributor

@garymathews garymathews left a 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);
Copy link
Contributor

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...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@ssekhri
Copy link

ssekhri commented Sep 16, 2019

FR Passed.
Verified on:
Mac OS 10.14.6
Ti SDK: 8.3.0.v20190916012915
Appc CLI: 7.1.1
Node: 10.5.0
JDK: 10.0.2
Studio: 5.1.4.201909061933
Device: Nexus4 (v5.1.1), Pixel2 emulator (8.0.0)

@jquick-axway
Copy link
Contributor

@ypbnv, can you look into the unit test failure please? That's the only thing blocking this PR. Thanks!

@garymathews
Copy link
Contributor

Looks like this has broke callbackTestForPOSTMethod test

@ypbnv
Copy link
Contributor Author

ypbnv commented Oct 17, 2019

After some more research - callbackTestForPOSTMethod should serve the same purpose of the unit test added by this PR. It should check the progress callback for sending data through HTTPRequest.

It fails because the test is successful when the progress event callback returns 1. This happened before, because it was calculated using the removed totalLength variable. It contained the length only of the data in the passed dictionary. In the case of the unit test that was a buffer with 10*1024 which has a 512 factor (this is how we track progress - with chunks of 512 bytes), so the last 512 bytes triggered the event with a progress 1. I think this would not be a reliable test because any content size different from X times of 512 bytes will never return progress value of 1. I am not really sure if this is the case for iOS, though.

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.
@jquick-axway @garymathews @vijaysingh-axway

@jquick-axway
Copy link
Contributor

Yes, the progress should be 1.0 (aka: 100%) when the upload finishes successfully. That is a reasonable expectation. This problem needs to be solved.

@jquick-axway
Copy link
Contributor

jquick-axway commented Oct 17, 2019

@ypbnv, add the following code to the ProgressOutputStream class. This will solve the problem. I tested it out and it does the job.

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.

@ypbnv
Copy link
Contributor Author

ypbnv commented Oct 21, 2019

@jquick-axway Added the snippet and also moved the closing of PrintWriter to happen for request that do not need multipart too.

Copy link
Contributor

@jquick-axway jquick-axway left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CR: Pass

@sgtcoolguy sgtcoolguy merged commit a190a5d into tidev:master Oct 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants