diff --git a/dio_test/lib/src/test/download_tests.dart b/dio_test/lib/src/test/download_tests.dart index f81e30a9c..660e8c9c9 100644 --- a/dio_test/lib/src/test/download_tests.dart +++ b/dio_test/lib/src/test/download_tests.dart @@ -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', );