Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(210)

Side by Side Diff: test/with_close_guarantee_test.dart

Issue 2041983003: Add StreamChannel.withCloseGuarantee. (Closed) Base URL: git@github.com:dart-lang/stream_channel.git@master
Patch Set: Code review changes Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/stream_channel.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
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.
4
5 import 'dart:async';
6
7 import 'package:async/async.dart';
8 import 'package:stream_channel/stream_channel.dart';
9 import 'package:test/test.dart';
10
11 import 'utils.dart';
12
13 final _delayTransformer = new StreamTransformer.fromHandlers(
14 handleData: (data, sink) => new Future.microtask(() => sink.add(data)),
15 handleDone: (sink) => new Future.microtask(() => sink.close()));
16
17 final _delaySinkTransformer =
18 new StreamSinkTransformer.fromStreamTransformer(_delayTransformer);
19
20 void main() {
21 var controller;
22 var channel;
23 setUp(() {
24 controller = new StreamChannelController();
25
26 // Add a bunch of layers of asynchronous dispatch between the channel and
27 // the underlying controllers.
28 var stream = controller.foreign.stream;
29 var sink = controller.foreign.sink;
30 for (var i = 0; i < 10; i++) {
31 stream = stream.transform(_delayTransformer);
32 sink = _delaySinkTransformer.bind(sink);
33 }
34
35 channel = new StreamChannel.withCloseGuarantee(stream, sink);
36 });
37
38 test("closing the event sink causes the stream to close before it emits any "
39 "more events", () async {
40 controller.local.sink.add(1);
41 controller.local.sink.add(2);
42 controller.local.sink.add(3);
43
44 expect(channel.stream.listen(expectAsync((event) {
45 if (event == 2) channel.sink.close();
46 }, count: 2)).asFuture(), completes);
47
48 await pumpEventQueue();
49 });
50
51 test("closing the event sink before events are emitted causes the stream to "
52 "close immediately", () async {
53 channel.sink.close();
54 channel.stream.listen(
55 expectAsync((_) {}, count: 0),
56 onError: expectAsync((_, __) {}, count: 0),
57 onDone: expectAsync(() {}));
58
59 controller.local.sink.add(1);
60 controller.local.sink.add(2);
61 controller.local.sink.add(3);
62 controller.local.sink.close();
63
64 await pumpEventQueue();
65 });
66 }
OLDNEW
« no previous file with comments | « lib/stream_channel.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698