-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathmultipart_retry_tests.dart
62 lines (56 loc) · 1.63 KB
/
multipart_retry_tests.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
@TestOn('vm')
import 'package:dio/dio.dart';
import 'package:dio_smart_retry/dio_smart_retry.dart';
import 'package:dio_smart_retry/src/retry_not_supported_exception.dart';
import 'package:test/test.dart';
void main() {
test('Retry for MultipartFile throws RetryNotSupportedException', () async {
final dio = Dio();
dynamic exception;
dio.interceptors.add(
RetryInterceptor(
dio: dio,
logPrint: print,
),
);
final formData =
FormData.fromMap({'file': MultipartFile.fromFileSync('README.md')});
try {
await dio.post<dynamic>(
'https://multipart.free.beeceptor.com/post500',
data: formData,
);
} on DioError catch (error) {
exception = error.error;
}
expect(exception is RetryNotSupportedException, true);
});
test('Retry for MultipartFileRecreatable is retrying', () async {
final dio = Dio();
const retries = 2;
final evaluator = DefaultRetryEvaluator(defaultRetryableStatuses);
dio.interceptors.add(
RetryInterceptor(
dio: dio,
logPrint: print,
retries: retries,
retryDelays: const [Duration(seconds: 1), Duration(seconds: 1)],
retryEvaluator: evaluator.evaluate,
),
);
final formData = FormData.fromMap({
'file': MultipartFileRecreatable.fromFileSync('README.md'),
});
try {
await dio.post<dynamic>(
'https://multipart.free.beeceptor.com/post500',
data: formData,
);
} on DioError catch (error) {
if (error.type != DioErrorType.response) {
rethrow;
}
}
expect(evaluator.currentAttempt, retries);
});
}