Created
February 26, 2021 08:08
-
-
Save j0nscalet/72c080a0ab8e2a1a2c6c3c267fd07a94 to your computer and use it in GitHub Desktop.
Comparing elapsed time reading and streaming file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test('send and track upload progress', () async { | |
var file = File('test/fixtures/lisanto.jpg'); | |
var length = await file.length(); | |
var bytesRead = 0; | |
var watch = Stopwatch(); | |
watch.start(); | |
file.openRead().listen((chunks) { | |
bytesRead += chunks.length; | |
if (bytesRead == length) { | |
watch.stop(); | |
print("Reading file... ${watch.elapsedMilliseconds / 1000}"); | |
} | |
}); | |
var events = <Map<String, dynamic>>[]; | |
client.uploadProgressStream.listen((event) { | |
events.add(event); | |
}); | |
await client.send(multipartRequest); | |
print("Streaming file...${events.last['elapsedTime']}"); | |
expect(events.length, greaterThan(0)); | |
expect( | |
events.every((e) => | |
e.containsKey('status') && | |
e.containsKey('url') && | |
e.containsKey('progress') && | |
e.containsKey('bytesUploaded') && | |
e.containsKey('totalBytes') && | |
e.containsKey('elapsedTime') && | |
e.containsKey('averageSpeed')), | |
equals(true)); | |
expect(events.first['status'], equals('uploading')); | |
expect(events.last['status'], equals("uploaded")); | |
expect(events.last['progress'], equals(100.0)); | |
}, timeout: Timeout(Duration(minutes: 10))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment