Skip to content

Commit

Permalink
✅ Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexV525 committed Apr 11, 2024
1 parent 8f5b880 commit 537832e
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions dio_test/lib/src/test/cancellation_tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,33 @@ void cancellationTests(
),
);
});

test(
'not closing sockets with requests that have same hosts',
() async {
final token = CancelToken();
final completer = Completer<Response?>();
// Complete the first request with the cancel token.
await dio.get('/get', cancelToken: token);
// Request the second without any cancel token, but with the same host.
dio.get('/drip?duration=3').then(
(res) {
completer.complete(res);
return res;
},
onError: (e) {
completer.complete(null);
return Response(requestOptions: (e as DioException).requestOptions);
},
);
// Simulate connection established.
await Future.delayed(const Duration(seconds: 1));
token.cancel();
final response = await completer.future;
// Response should be obtained without exceptions.
expect(response, isNotNull);
},
testOn: '!browser',
);
});
}

0 comments on commit 537832e

Please sign in to comment.