Project: titanium
Issue TIMOB-20483: Android HTTPClient onsendstream progress is wrong
I've noticed that the progress callback of TiHTTPClient under Android reaches a value of 1 way before the upload is completed. This can be seen on slow link speeds. I believe this bug also exists on normal speeds but is less apparent there. This might be related to [https://jira.appcelerator.org/browse/TC-5837] I've tested this with Titanium SDK 5.1.2 & 5.2.0 on Android 4, 5 and 6 devices. For testing I limited my wireless link speed with dd-wrt to 64kbits. This is also reproducable with slow mobile EDGE speeds. The example code uses a 1 MB testfile from here: [http://cachefly.cachefly.net/speedtest/] {code:javascript}	var win = Ti.UI.createWindow();	var progress = Ti.UI.createProgressBar({	width:200,	min:0,	max:1,	value:0,	});	win.add(progress);	var timestamp = Date.now();	var file = Ti.Filesystem.getFile('1mb.test');	win.addEventListener('open', function() {	var xhr = Ti.Network.createHTTPClient({	onload: function() {	var time_passed = Math.floor((Date.now()-timestamp)/1000);	Ti.API.info(time_passed + ' SUCCESS');	},	onsendstream: function(e) {	var time_passed = Math.floor((Date.now()-timestamp)/1000);	Ti.API.info(time_passed + ' PROGRESS ' + e.progress);	progress.setValue(e.progress);	}	});	xhr.open('POST', 'http://www.example.org/post.php');	xhr.send({data: file})	});	win.open(); {code} *What should happen:* The link speed IS constant, so the progress log should be liniear. Assuming a BLANK response, the onload event should get called quickly after progress reached the value of 1. *What actually happens:* Progress goes up to value 1 very quickly (in 1-2 seconds). It's not possible to upload 1MB in ~1 second with the available bandwidth. The progress is not fired anymore after it reached the value of 1 although the upload is still in progress. After ~138 seconds the onload event fires correctly. The time of the onload event is consistent with the available bandwith. Router bandwith logs show also that a upload is in progress until the onload event is fired. {noformat} [INFO] : 0 PROGRESS 0.00048828125 [INFO] : 0 PROGRESS 0.0009765625 [INFO] : 0 PROGRESS 0.00146484375 [INFO] : 0 PROGRESS 0.001953125 [INFO] : 0 PROGRESS 0.00244140625 ... [INFO] : 1 PROGRESS 0.99853515625 [INFO] : 1 PROGRESS 0.9990234375 [INFO] : 1 PROGRESS 0.99951171875 [INFO] : 1 PROGRESS 1 [INFO] : 138 SUCCESS {noformat}
Story points: 2