| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 import "package:unittest/unittest.dart"; | 6 import "package:unittest/unittest.dart"; |
| 7 | 7 |
| 8 main() { | 8 main() { |
| 9 const ms5 = const Duration(milliseconds: 5); | 9 const ms5 = const Duration(milliseconds: 5); |
| 10 const twoSecs = const Duration(seconds: 2); | 10 const twoSecs = const Duration(seconds: 2); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 onError: expectAsync((e, s) { | 60 onError: expectAsync((e, s) { |
| 61 expect(ctr, 2); | 61 expect(ctr, 2); |
| 62 expect(e, new isInstanceOf<TimeoutException>()); | 62 expect(e, new isInstanceOf<TimeoutException>()); |
| 63 })); | 63 })); |
| 64 c..add(42)..add(42); // No close, timeout after two events. | 64 c..add(42)..add(42); // No close, timeout after two events. |
| 65 }); | 65 }); |
| 66 | 66 |
| 67 test("broadcast stream timeout", () { | 67 test("broadcast stream timeout", () { |
| 68 StreamController c = new StreamController.broadcast(); | 68 StreamController c = new StreamController.broadcast(); |
| 69 Stream tos = c.stream.timeout(ms5); | 69 Stream tos = c.stream.timeout(ms5); |
| 70 expect(tos.isBroadcast, false); | 70 expect(tos.isBroadcast, true); |
| 71 tos.handleError(expectAsync((e, s) { | 71 tos.handleError(expectAsync((e, s) { |
| 72 expect(e, new isInstanceOf<TimeoutException>()); | 72 expect(e, new isInstanceOf<TimeoutException>()); |
| 73 expect(s, null); | 73 expect(s, null); |
| 74 })).listen((v){ fail("Unexpected event"); }); | 74 })).listen((v){ fail("Unexpected event"); }); |
| 75 }); | 75 }); |
| 76 | 76 |
| 77 test("asBroadcast stream timeout", () { | 77 test("asBroadcast stream timeout", () { |
| 78 StreamController c = new StreamController.broadcast(); | 78 StreamController c = new StreamController.broadcast(); |
| 79 Stream tos = c.stream.asBroadcastStream().timeout(ms5); | 79 Stream tos = c.stream.asBroadcastStream().timeout(ms5); |
| 80 expect(tos.isBroadcast, false); | 80 expect(tos.isBroadcast, true); |
| 81 tos.handleError(expectAsync((e, s) { | 81 tos.handleError(expectAsync((e, s) { |
| 82 expect(e, new isInstanceOf<TimeoutException>()); | 82 expect(e, new isInstanceOf<TimeoutException>()); |
| 83 expect(s, null); | 83 expect(s, null); |
| 84 })).listen((v){ fail("Unexpected event"); }); | 84 })).listen((v){ fail("Unexpected event"); }); |
| 85 }); | 85 }); |
| 86 | 86 |
| 87 test("mapped stream timeout", () { | 87 test("mapped stream timeout", () { |
| 88 StreamController c = new StreamController(); | 88 StreamController c = new StreamController(); |
| 89 Stream tos = c.stream.map((x) => 2 * x).timeout(ms5); | 89 Stream tos = c.stream.map((x) => 2 * x).timeout(ms5); |
| 90 expect(tos.isBroadcast, false); | 90 expect(tos.isBroadcast, false); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 fail("Timeout not prevented by close"); | 173 fail("Timeout not prevented by close"); |
| 174 }); | 174 }); |
| 175 var subscription = tos.listen((_) {}, onDone: expectAsync((){})); | 175 var subscription = tos.listen((_) {}, onDone: expectAsync((){})); |
| 176 subscription.pause(); | 176 subscription.pause(); |
| 177 new Timer(twoSecs, () { | 177 new Timer(twoSecs, () { |
| 178 c.close(); | 178 c.close(); |
| 179 subscription.resume(); | 179 subscription.resume(); |
| 180 }); | 180 }); |
| 181 }); | 181 }); |
| 182 } | 182 } |
| OLD | NEW |