OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import 'dart:async'; | 5 import 'dart:async'; |
6 | 6 |
7 import 'package:http/http.dart' as http; | 7 import 'package:http/http.dart' as http; |
8 import 'package:http/testing.dart'; | 8 import 'package:http/testing.dart'; |
9 import 'package:http_throttle/http_throttle.dart'; | 9 import 'package:http_throttle/http_throttle.dart'; |
10 import 'package:unittest/unittest.dart'; | 10 import 'package:test/test.dart'; |
11 | 11 |
12 void main() { | 12 void main() { |
13 test("makes requests until the limit is hit", () { | 13 test("makes requests until the limit is hit", () { |
14 var pendingResponses = []; | 14 var pendingResponses = []; |
15 var client = new ThrottleClient(10, new MockClient((request) { | 15 var client = new ThrottleClient(10, new MockClient((request) { |
16 var completer = new Completer(); | 16 var completer = new Completer(); |
17 pendingResponses.add(completer); | 17 pendingResponses.add(completer); |
18 return completer.future.then((response) { | 18 return completer.future.then((response) { |
19 pendingResponses.remove(completer); | 19 pendingResponses.remove(completer); |
20 return response; | 20 return response; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 /// times. By default, this should pump the event queue enough times to allow | 60 /// times. By default, this should pump the event queue enough times to allow |
61 /// any code to run, as long as it's not waiting on some external event. | 61 /// any code to run, as long as it's not waiting on some external event. |
62 Future pumpEventQueue([int times = 20]) { | 62 Future pumpEventQueue([int times = 20]) { |
63 if (times == 0) return new Future.value(); | 63 if (times == 0) return new Future.value(); |
64 // We use a delayed future to allow microtask events to finish. The | 64 // We use a delayed future to allow microtask events to finish. The |
65 // Future.value or Future() constructors use scheduleMicrotask themselves and | 65 // Future.value or Future() constructors use scheduleMicrotask themselves and |
66 // would therefore not wait for microtask callbacks that are scheduled after | 66 // would therefore not wait for microtask callbacks that are scheduled after |
67 // invoking this method. | 67 // invoking this method. |
68 return new Future.delayed(Duration.ZERO, () => pumpEventQueue(times - 1)); | 68 return new Future.delayed(Duration.ZERO, () => pumpEventQueue(times - 1)); |
69 } | 69 } |
OLD | NEW |