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

Side by Side Diff: tests/corelib/stream_controller_test.dart

Issue 11308154: Stream isolates. (Closed) Base URL: https://dart.googlecode.com/svn/experimental/lib_v2/dart
Patch Set: Fixes and test. Created 8 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 // Test the basic ControllerStream. 5 // Test the basic ControllerStream.
6 import 'dart:async'; 6 import 'dart:async';
7 7
8 class Event { 8 class Event {
9 void replay(StreamSink sink); 9 void replay(StreamSink sink);
10 } 10 }
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 Expect.listEquals(expectedEvents.events, actualEvents.events); 248 Expect.listEquals(expectedEvents.events, actualEvents.events);
249 expectedEvents..write(44)..write(45)..close(); 249 expectedEvents..write(44)..write(45)..close();
250 sub.onDone(() { 250 sub.onDone(() {
251 // This depends on the captured events in actualEvents being filled 251 // This depends on the captured events in actualEvents being filled
252 // before sub.onDone is called. That's slightly hacky. We need a 252 // before sub.onDone is called. That's slightly hacky. We need a
253 // way to write async tests (this file is really depending on 253 // way to write async tests (this file is really depending on
254 // synchronous event propagation). 254 // synchronous event propagation).
255 Expect.listEquals(expectedEvents.events, actualEvents.events); 255 Expect.listEquals(expectedEvents.events, actualEvents.events);
256 }); 256 });
257 signal.complete(); 257 signal.complete();
258
259 // Test subscription changes while firing.
260 c = new StreamController();
261 var sink = c.sink;
262 var stream = c.stream;
263 var counter = 0;
264 var subscription = stream.subscribe();
265 subscription.onData((data) {
266 counter += data;
267 subscription.unsubscribe();
268 stream.subscribe(onData: (data) {
269 counter += 10 * data;
270 });
271 var subscription2 = stream.subscribe();
272 subscription2.onData((data) {
273 counter += 100 * data;
274 if (data == 4) subscription2.unsubscribe();
275 });
276 });
277 sink.write(1); // seen by stream 1
278 sink.write(2); // seen by stream 10 and 100
279 sink.write(3); // -"-
280 sink.write(4); // -"-
281 sink.write(5); // seen by stream 10
282 Expect.equals(1 + 20 + 200 + 30 + 300 + 40 + 400 + 50, counter);
258 } 283 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698