Skip to content

Commit

Permalink
Add append download test
Browse files Browse the repository at this point in the history
  • Loading branch information
shehabmohamed0 committed Sep 1, 2024
1 parent fe609eb commit 7d721d9
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions dio_test/lib/src/test/download_tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,54 @@ void downloadTests(
completes,
);
});
test('append bytes previous download', () async {
final cancelToken = CancelToken();
final path = p.join(tmp.path, 'download_3.txt');
final requestedBytes = 1024 * 1024 * 10;
var recievedBytes1 = 0;
await expectLater(
dio.download(
'/bytes/$requestedBytes',
path,
cancelToken: cancelToken,
onReceiveProgress: (c, t) {
if (c > 5000) {
recievedBytes1 = c;
cancelToken.cancel();
}
},
deleteOnError: false,
),
throwsDioException(
DioExceptionType.cancel,
stackTraceContains: 'test/download_tests.dart',
),
);

final cancelToken2 = CancelToken();
var recievedBytes2 = 0;
expectLater(
dio.download(
'/bytes/$requestedBytes',
path,
cancelToken: cancelToken,
onReceiveProgress: (c, t) {
recievedBytes2 = c;
if (c > 5000) {
cancelToken2.cancel();
}
},
deleteOnError: false,
fileMode: DioFileMode.append,
),
throwsDioException(
DioExceptionType.cancel,
stackTraceContains: 'test/download_tests.dart',
),
);
await Future.delayed(const Duration(milliseconds: 100), () {});
expect(File(path).lengthSync(), recievedBytes1 + recievedBytes2);
});
},
testOn: 'vm',
);
Expand Down

0 comments on commit 7d721d9

Please sign in to comment.