From 90db10146a539a4d3c0719d08d0d83ca7d246ebb Mon Sep 17 00:00:00 2001 From: sgrekhov Date: Mon, 21 Oct 2024 12:44:24 +0300 Subject: [PATCH 1/7] #2933. Add MultiStreamController tests. Part 4. --- .../isPaused_A01_t01.dart | 47 +++++++++++++++++ .../isPaused_A01_t02.dart | 47 +++++++++++++++++ .../isPaused_A01_t03.dart | 50 +++++++++++++++++++ .../onCancel_A01_t01.dart | 34 +++++++++++++ .../onCancel_A01_t02.dart | 34 +++++++++++++ .../onCancel_A01_t03.dart | 39 +++++++++++++++ .../onCancel_A02_t01.dart | 38 ++++++++++++++ .../onListen_A01_t01.dart | 42 ++++++++++++++++ .../onListen_A01_t02.dart | 39 +++++++++++++++ .../onListen_A02_t01.dart | 34 +++++++++++++ .../onPause_A01_t01.dart | 39 +++++++++++++++ .../onPause_A01_t02.dart | 46 +++++++++++++++++ .../onPause_A02_t01.dart | 40 +++++++++++++++ .../onResume_A01_t01.dart | 45 +++++++++++++++++ .../MultiStreamController/sink_A01_t01.dart | 34 +++++++++++++ .../MultiStreamController/stream_A01_t01.dart | 39 +++++++++++++++ 16 files changed, 647 insertions(+) create mode 100644 LibTest/async/MultiStreamController/isPaused_A01_t01.dart create mode 100644 LibTest/async/MultiStreamController/isPaused_A01_t02.dart create mode 100644 LibTest/async/MultiStreamController/isPaused_A01_t03.dart create mode 100644 LibTest/async/MultiStreamController/onCancel_A01_t01.dart create mode 100644 LibTest/async/MultiStreamController/onCancel_A01_t02.dart create mode 100644 LibTest/async/MultiStreamController/onCancel_A01_t03.dart create mode 100644 LibTest/async/MultiStreamController/onCancel_A02_t01.dart create mode 100644 LibTest/async/MultiStreamController/onListen_A01_t01.dart create mode 100644 LibTest/async/MultiStreamController/onListen_A01_t02.dart create mode 100644 LibTest/async/MultiStreamController/onListen_A02_t01.dart create mode 100644 LibTest/async/MultiStreamController/onPause_A01_t01.dart create mode 100644 LibTest/async/MultiStreamController/onPause_A01_t02.dart create mode 100644 LibTest/async/MultiStreamController/onPause_A02_t01.dart create mode 100644 LibTest/async/MultiStreamController/onResume_A01_t01.dart create mode 100644 LibTest/async/MultiStreamController/sink_A01_t01.dart create mode 100644 LibTest/async/MultiStreamController/stream_A01_t01.dart diff --git a/LibTest/async/MultiStreamController/isPaused_A01_t01.dart b/LibTest/async/MultiStreamController/isPaused_A01_t01.dart new file mode 100644 index 0000000000..95fec1b4fc --- /dev/null +++ b/LibTest/async/MultiStreamController/isPaused_A01_t01.dart @@ -0,0 +1,47 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion bool get isPaused +/// Whether the subscription would need to buffer events. +/// +/// This is the case if the controller's stream has a listener and it is paused, +/// or if it has not received a listener yet. In that case, the controller is +/// considered paused as well. +/// +/// A broadcast stream controller is never considered paused. It always forwards +/// its events to all uncanceled subscriptions, if any, and let the +/// subscriptions handle their own pausing and buffering. +/// +/// @description Checks that this getter returns `true` if the stream is paused +/// and `false` otherwise. +/// @author sgrekhov22@gmail.com + +import "dart:async"; +import "../../../Utils/expect.dart"; + +main() { + asyncStart(); + var controllers = >[]; + var stream = Stream.multi((controller) { + Expect.isFalse(controller.isPaused); + controller.add(1); + controller.add(2); + controller.add(3); + }); + listen(stream); + listen(stream); + Future.delayed(Duration(milliseconds: 200), () { + controllers.forEach((c) { + Expect.isTrue(c.isPaused); + }); + asyncEnd(); + }); +} + +void listen(Stream stream) { + late StreamSubscription ss; + ss = stream.listen((v) { + ss.pause(); + }); +} diff --git a/LibTest/async/MultiStreamController/isPaused_A01_t02.dart b/LibTest/async/MultiStreamController/isPaused_A01_t02.dart new file mode 100644 index 0000000000..f41eddb4af --- /dev/null +++ b/LibTest/async/MultiStreamController/isPaused_A01_t02.dart @@ -0,0 +1,47 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion bool get isPaused +/// Whether the subscription would need to buffer events. +/// +/// This is the case if the controller's stream has a listener and it is paused, +/// or if it has not received a listener yet. In that case, the controller is +/// considered paused as well. +/// +/// A broadcast stream controller is never considered paused. It always forwards +/// its events to all uncanceled subscriptions, if any, and let the +/// subscriptions handle their own pausing and buffering. +/// +/// @description Checks that this getter returns `true` if the stream is paused +/// and `false` otherwise. Test `isBroadcast: true` case. +/// @author sgrekhov22@gmail.com + +import "dart:async"; +import "../../../Utils/expect.dart"; + +main() { + asyncStart(); + var controllers = >[]; + var stream = Stream.multi((controller) { + Expect.isFalse(controller.isPaused); + controller.add(1); + controller.add(2); + controller.add(3); + }); + listen(stream); + listen(stream); + Future.delayed(Duration(milliseconds: 200), () { + controllers.forEach((c) { + Expect.isTrue(c.isPaused); + }); + asyncEnd(); + }); +} + +void listen(Stream stream) { + late StreamSubscription ss; + ss = stream.listen((v) { + ss.pause(); + }); +} diff --git a/LibTest/async/MultiStreamController/isPaused_A01_t03.dart b/LibTest/async/MultiStreamController/isPaused_A01_t03.dart new file mode 100644 index 0000000000..56e75e620a --- /dev/null +++ b/LibTest/async/MultiStreamController/isPaused_A01_t03.dart @@ -0,0 +1,50 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion bool get isPaused +/// Whether the subscription would need to buffer events. +/// +/// This is the case if the controller's stream has a listener and it is paused, +/// or if it has not received a listener yet. In that case, the controller is +/// considered paused as well. +/// +/// A broadcast stream controller is never considered paused. It always forwards +/// its events to all uncanceled subscriptions, if any, and let the +/// subscriptions handle their own pausing and buffering. +/// +/// @description Checks that this getter returns `true` if the stream is paused +/// and `false` otherwise. +/// @author sgrekhov22@gmail.com +/// @issue 56915 + +import "dart:async"; +import "../../../Utils/expect.dart"; + +var theController; + +main() { + asyncStart(); + var stream = Stream.multi((controller) { + theController = controller; + Expect.isFalse(controller.isPaused); + controller.add(1); + controller.add(2); + controller.add(3); + controller.close(); + }); + listen(stream); +} + +void listen(Stream stream) { + late StreamSubscription ss; + ss = stream.listen((v) { + if (v == 1) { + ss.pause(Future.delayed(Duration(milliseconds: 100))); + } else { + // Looks strange, but it is expected. + // See https://github.com/dart-lang/sdk/issues/56915 for more details. + Expect.isTrue(theController.isPaused); + } + }, onDone: asyncEnd); +} diff --git a/LibTest/async/MultiStreamController/onCancel_A01_t01.dart b/LibTest/async/MultiStreamController/onCancel_A01_t01.dart new file mode 100644 index 0000000000..5b9808f2e9 --- /dev/null +++ b/LibTest/async/MultiStreamController/onCancel_A01_t01.dart @@ -0,0 +1,34 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion FutureOr Function()? onCancel +/// The callback which is called when the stream is canceled. +/// +/// May be set to `null`, in which case no callback will happen. +/// +/// @description Checks that this callback is called when the stream is canceled +/// @author sgrekhov22@gmail.com + +import "dart:async"; +import "../../../Utils/expect.dart"; + +main() { + asyncStart(2); + var stream = Stream.multi((controller) { + Expect.isNull(controller.onCancel); + controller.onCancel = asyncEnd; + controller.add(1); + controller.add(2); + controller.add(3); + }); + listen(stream); + listen(stream); +} + +void listen(Stream stream) { + late StreamSubscription ss; + ss = stream.listen((v) { + ss.cancel(); + }); +} diff --git a/LibTest/async/MultiStreamController/onCancel_A01_t02.dart b/LibTest/async/MultiStreamController/onCancel_A01_t02.dart new file mode 100644 index 0000000000..5aa5809260 --- /dev/null +++ b/LibTest/async/MultiStreamController/onCancel_A01_t02.dart @@ -0,0 +1,34 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion FutureOr Function()? onCancel +/// The callback which is called when the stream is canceled. +/// +/// May be set to `null`, in which case no callback will happen. +/// +/// @description Checks that this callback is called on "done" event. +/// @author sgrekhov22@gmail.com + +import "dart:async"; +import "../../../Utils/expect.dart"; + +main() { + asyncStart(2); + var stream = Stream.multi((controller) { + controller.onCancel = asyncEnd; + controller.add(1); + controller.add(2); + controller.add(3); + controller.close(); + }); + listen(stream); + listen(stream); +} + +void listen(Stream stream) { + int i = 0; + stream.listen((v) { + Expect.equals(++i, v); + }); +} diff --git a/LibTest/async/MultiStreamController/onCancel_A01_t03.dart b/LibTest/async/MultiStreamController/onCancel_A01_t03.dart new file mode 100644 index 0000000000..8b05a45224 --- /dev/null +++ b/LibTest/async/MultiStreamController/onCancel_A01_t03.dart @@ -0,0 +1,39 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion FutureOr Function()? onCancel +/// The callback which is called when the stream is canceled. +/// +/// May be set to `null`, in which case no callback will happen. +/// +/// @description Checks that this callback is not called when the stream is +/// paused. +/// @author sgrekhov22@gmail.com + +import "dart:async"; +import "../../../Utils/expect.dart"; + +main() { + asyncStart(); + var stream = Stream.multi((controller) { + controller.onCancel = () { + Expect.fail("Unexpected onCancel"); + }; + controller.add(1); + controller.add(2); + controller.add(3); + }); + listen(stream); + listen(stream); + Future.delayed(Duration(milliseconds: 200), asyncEnd); +} + +void listen(Stream stream) { + late StreamSubscription ss; + ss = stream.listen((v) { + if (v == 1) { + ss.pause(); + } + }); +} diff --git a/LibTest/async/MultiStreamController/onCancel_A02_t01.dart b/LibTest/async/MultiStreamController/onCancel_A02_t01.dart new file mode 100644 index 0000000000..3dd3af4eb3 --- /dev/null +++ b/LibTest/async/MultiStreamController/onCancel_A02_t01.dart @@ -0,0 +1,38 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion FutureOr Function()? onCancel +/// The callback which is called when the stream is canceled. +/// +/// May be set to `null`, in which case no callback will happen. +/// +/// @description Checks that if this callback is set to `null`, then no callback +/// happens. +/// @author sgrekhov22@gmail.com + +import "dart:async"; +import "../../../Utils/expect.dart"; + +main() { + asyncStart(2); + var stream = Stream.multi((controller) { + controller.onCancel = () { + Expect.fail("Unexpected onCancel"); + }; + controller.onCancel = null; + controller.add(1); + controller.add(2); + controller.add(3); + }); + listen(stream); + listen(stream); +} + +void listen(Stream stream) { + late StreamSubscription ss; + ss = stream.listen((v) { + ss.cancel(); + asyncEnd(); + }); +} diff --git a/LibTest/async/MultiStreamController/onListen_A01_t01.dart b/LibTest/async/MultiStreamController/onListen_A01_t01.dart new file mode 100644 index 0000000000..da3d3d4051 --- /dev/null +++ b/LibTest/async/MultiStreamController/onListen_A01_t01.dart @@ -0,0 +1,42 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion void Function()? onListen +/// +/// The callback which is called when the stream is listened to. +/// +/// May be set to null, in which case no callback will happen. +/// +/// @description Checks that setting the `onListen` on the +/// [MultiStreamController] has no effect, the one subscription that the +/// controller applies to has already started listening. +/// @author sgrekhov22@gmail.com + +import "dart:async"; +import "../../../Utils/expect.dart"; + +main() { + asyncStart(2); + var stream = Stream.multi((controller) { + controller.onListen = () { + Expect.fail("Unexpected onListen"); + }; + controller.add(1); + controller.add(2); + controller.add(3); + controller.close(); + }); + listen(stream); + listen(stream); +} + +void listen(Stream stream) { + int i = 0; + stream.listen((v) { + Expect.equals(++i, v); + }, onDone: () { + Expect.equals(3, i); + asyncEnd(); + }); +} diff --git a/LibTest/async/MultiStreamController/onListen_A01_t02.dart b/LibTest/async/MultiStreamController/onListen_A01_t02.dart new file mode 100644 index 0000000000..11295933fa --- /dev/null +++ b/LibTest/async/MultiStreamController/onListen_A01_t02.dart @@ -0,0 +1,39 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion void Function()? onListen +/// +/// The callback which is called when the stream is listened to. +/// +/// May be set to null, in which case no callback will happen. +/// +/// @description Checks that when [MultiStreamController] is listened `onListen` +/// callback is set. +/// @author sgrekhov22@gmail.com + +import "dart:async"; +import "../../../Utils/expect.dart"; + +main() { + asyncStart(2); + var stream = Stream.multi((controller) { + Expect.isNotNull(controller.onListen); + controller.add(1); + controller.add(2); + controller.add(3); + controller.close(); + }); + listen(stream); + listen(stream); +} + +void listen(Stream stream) { + int i = 0; + stream.listen((v) { + Expect.equals(++i, v); + }, onDone: () { + Expect.equals(3, i); + asyncEnd(); + }); +} diff --git a/LibTest/async/MultiStreamController/onListen_A02_t01.dart b/LibTest/async/MultiStreamController/onListen_A02_t01.dart new file mode 100644 index 0000000000..43f18a10e6 --- /dev/null +++ b/LibTest/async/MultiStreamController/onListen_A02_t01.dart @@ -0,0 +1,34 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion void Function()? onListen +/// +/// The callback which is called when the stream is listened to. +/// +/// May be set to null, in which case no callback will happen. +/// +/// @description Checks that setting `onListen` to `null` has no effect in case +/// of [MultiStreamController]. +/// @author sgrekhov22@gmail.com + +import "dart:async"; +import "../../../Utils/expect.dart"; + +main() { + asyncStart(2); + var stream = Stream.multi((controller) { + controller.onListen = null; + controller.add(1); + controller.add(2); + controller.add(3); + controller.close(); + }); + listen(stream); + listen(stream); +} + +void listen(Stream stream) { + stream.listen((v) { + }, onDone: asyncEnd); +} diff --git a/LibTest/async/MultiStreamController/onPause_A01_t01.dart b/LibTest/async/MultiStreamController/onPause_A01_t01.dart new file mode 100644 index 0000000000..e76adc44e2 --- /dev/null +++ b/LibTest/async/MultiStreamController/onPause_A01_t01.dart @@ -0,0 +1,39 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion void Function()? onPause +/// The callback which is called when the stream is paused. +/// +/// May be set to `null`, in which case no callback will happen. +/// +/// Pause related callbacks are not supported on broadcast stream controllers. +/// +/// @description Checks that this callback is called when the stream is paused. +/// @author sgrekhov22@gmail.com + +import "dart:async"; +import "../../../Utils/expect.dart"; + +main() { + asyncStart(2); + var stream = Stream.multi((controller) { + Expect.isNull(controller.onPause); + controller.onPause = () { + asyncEnd(); + }; + controller.add(1); + controller.add(2); + controller.add(3); + controller.close(); + }); + listen(stream); + listen(stream); +} + +void listen(Stream stream) { + late StreamSubscription ss; + ss = stream.listen((v) { + ss.pause(); + }); +} diff --git a/LibTest/async/MultiStreamController/onPause_A01_t02.dart b/LibTest/async/MultiStreamController/onPause_A01_t02.dart new file mode 100644 index 0000000000..3c3d69f97f --- /dev/null +++ b/LibTest/async/MultiStreamController/onPause_A01_t02.dart @@ -0,0 +1,46 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion void Function()? onPause +/// The callback which is called when the stream is paused. +/// +/// May be set to `null`, in which case no callback will happen. +/// +/// Pause related callbacks are not supported on broadcast stream controllers. +/// +/// @description Checks that this callback is called when the stream is paused. +/// @author sgrekhov22@gmail.com + +import "dart:async"; +import "../../../Utils/expect.dart"; + +main() { + asyncStart(2); + var stream = Stream.multi((controller) { + controller.onPause = () { + Expect.fail("Unexpected onPause"); + }; + controller.onPause = null; + controller.add(1); + controller.add(2); + controller.add(3); + controller.close(); + }); + listen(stream); + listen(stream); +} + +void listen(Stream stream) { + late StreamSubscription ss; + int i = 0; + ss = stream.listen((v) { + Expect.equals(++i, v); + if (i == 1) { + ss.pause(); + Future.delayed(Duration(milliseconds: 100), () { + ss.resume(); + }); + } + }, onDone: asyncEnd); +} diff --git a/LibTest/async/MultiStreamController/onPause_A02_t01.dart b/LibTest/async/MultiStreamController/onPause_A02_t01.dart new file mode 100644 index 0000000000..c29936f55c --- /dev/null +++ b/LibTest/async/MultiStreamController/onPause_A02_t01.dart @@ -0,0 +1,40 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion void Function()? onPause +/// The callback which is called when the stream is paused. +/// +/// May be set to `null`, in which case no callback will happen. +/// +/// Pause related callbacks are not supported on broadcast stream controllers. +/// +/// @description Checks that this callback is called when the stream is paused. +/// Test `isBroadcast: true` case. +/// @author sgrekhov22@gmail.com + +import "dart:async"; +import "../../../Utils/expect.dart"; + +main() { + asyncStart(2); + var stream = Stream.multi((controller) { + Expect.isNull(controller.onPause); + controller.onPause = () { + asyncEnd(); + }; + controller.add(1); + controller.add(2); + controller.add(3); + controller.close(); + }, isBroadcast: true); + listen(stream); + listen(stream); +} + +void listen(Stream stream) { + late StreamSubscription ss; + ss = stream.listen((v) { + ss.pause(); + }); +} diff --git a/LibTest/async/MultiStreamController/onResume_A01_t01.dart b/LibTest/async/MultiStreamController/onResume_A01_t01.dart new file mode 100644 index 0000000000..81decd4b14 --- /dev/null +++ b/LibTest/async/MultiStreamController/onResume_A01_t01.dart @@ -0,0 +1,45 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion void Function()? onResume +/// The callback which is called when the stream is resumed. +/// +/// May be set to `null`, in which case no callback will happen. +/// +/// Pause related callbacks are not supported on broadcast stream controllers. +/// +/// @description Checks that this callback is called when the stream is resumed. +/// @author sgrekhov22@gmail.com +/// @issue 56927 + +import "dart:async"; +import "../../../Utils/expect.dart"; + +main() { + asyncStart(2); + var stream = Stream.multi((controller) { + Expect.isNull(controller.onResume); + controller.onResume = asyncEnd; + controller.add(1); + controller.add(2); + controller.add(3); + controller.close(); + }); + listen(stream); + listen(stream); +} + +void listen(Stream stream) { + late StreamSubscription ss; + int i = 0; + ss = stream.listen((v) { + Expect.equals(++i, v); + if (i == 1) { + ss.pause(); + Future.delayed(Duration(milliseconds: 100), () { + ss.resume(); + }); + } + }); +} diff --git a/LibTest/async/MultiStreamController/sink_A01_t01.dart b/LibTest/async/MultiStreamController/sink_A01_t01.dart new file mode 100644 index 0000000000..a83ef25fa1 --- /dev/null +++ b/LibTest/async/MultiStreamController/sink_A01_t01.dart @@ -0,0 +1,34 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion StreamSink get sink +/// Returns a view of this object that only exposes the StreamSink interface. +/// +/// @description Checks that this getter returns a view of this object that +/// exposes the StreamSink interface. +/// @author sgrekhov22@gmail.com + +import "dart:async"; +import "../../../Utils/expect.dart"; + +main() { + asyncStart(2); + late Stream stream; + stream = Stream.multi((controller) { + Expect.isNotNull(controller.sink); + controller.sink.add(1); + controller.sink.add(2); + controller.sink.add(3); + controller.sink.close(); + }); + listen(stream); + listen(stream); +} + +void listen(Stream stream) { + int i = 0; + stream.listen((v) { + Expect.equals(++i, v); + }, onDone: asyncEnd); +} diff --git a/LibTest/async/MultiStreamController/stream_A01_t01.dart b/LibTest/async/MultiStreamController/stream_A01_t01.dart new file mode 100644 index 0000000000..ed5e963538 --- /dev/null +++ b/LibTest/async/MultiStreamController/stream_A01_t01.dart @@ -0,0 +1,39 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion Stream get stream +/// The stream that this controller is controlling. +/// +/// @description Checks that the [MultiStreamController] does not support +/// reading its [StreamController.stream]. +/// @author sgrekhov22@gmail.com + +import "dart:async"; +import "../../../Utils/expect.dart"; + +main() { + asyncStart(2); + late Stream stream; + stream = Stream.multi((controller) { + Expect.throws(() { + controller.stream; + }); + controller.add(1); + controller.add(2); + controller.add(3); + Expect.throws(() { + controller.stream; + }); + controller.close(); + }); + listen(stream); + listen(stream); +} + +void listen(Stream stream) { + int i = 0; + stream.listen((v) { + Expect.equals(++i, v); + }, onDone: asyncEnd); +} From af17cef4704e019ecdc9bcf0fd7a4519bf4e6c12 Mon Sep 17 00:00:00 2001 From: sgrekhov Date: Mon, 21 Oct 2024 13:06:12 +0300 Subject: [PATCH 2/7] Update `onResume` tests --- .../onResume_A01_t01.dart | 7 +-- .../onResume_A01_t02.dart | 48 ++++++++++++++++++ .../onResume_A02_t01.dart | 49 +++++++++++++++++++ 3 files changed, 101 insertions(+), 3 deletions(-) create mode 100644 LibTest/async/MultiStreamController/onResume_A01_t02.dart create mode 100644 LibTest/async/MultiStreamController/onResume_A02_t01.dart diff --git a/LibTest/async/MultiStreamController/onResume_A01_t01.dart b/LibTest/async/MultiStreamController/onResume_A01_t01.dart index 81decd4b14..1bf90881c9 100644 --- a/LibTest/async/MultiStreamController/onResume_A01_t01.dart +++ b/LibTest/async/MultiStreamController/onResume_A01_t01.dart @@ -11,7 +11,6 @@ /// /// @description Checks that this callback is called when the stream is resumed. /// @author sgrekhov22@gmail.com -/// @issue 56927 import "dart:async"; import "../../../Utils/expect.dart"; @@ -20,11 +19,13 @@ main() { asyncStart(2); var stream = Stream.multi((controller) { Expect.isNull(controller.onResume); - controller.onResume = asyncEnd; + controller.onResume = () { + controller.close(); + asyncEnd(); + }; controller.add(1); controller.add(2); controller.add(3); - controller.close(); }); listen(stream); listen(stream); diff --git a/LibTest/async/MultiStreamController/onResume_A01_t02.dart b/LibTest/async/MultiStreamController/onResume_A01_t02.dart new file mode 100644 index 0000000000..9ba41e5508 --- /dev/null +++ b/LibTest/async/MultiStreamController/onResume_A01_t02.dart @@ -0,0 +1,48 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion void Function()? onResume +/// The callback which is called when the stream is resumed. +/// +/// May be set to `null`, in which case no callback will happen. +/// +/// Pause related callbacks are not supported on broadcast stream controllers. +/// +/// @description Checks that if this callback is is not called after "done" +/// event. +/// @author sgrekhov22@gmail.com + +import "dart:async"; +import "../../../Utils/expect.dart"; + +main() { + asyncStart(2); + var stream = Stream.multi((controller) { + Expect.isNull(controller.onResume); + controller.onResume = () { + // See https://github.com/dart-lang/sdk/issues/56927 for an explanation. + Expect.fail("Unexpected onResume"); + }; + controller.add(1); + controller.add(2); + controller.add(3); + controller.close(); + }); + listen(stream); + listen(stream); +} + +void listen(Stream stream) { + late StreamSubscription ss; + int i = 0; + ss = stream.listen((v) { + Expect.equals(++i, v); + if (i == 1) { + ss.pause(); + Future.delayed(Duration(milliseconds: 100), () { + ss.resume(); + }); + } + }, onDone: asyncEnd); +} diff --git a/LibTest/async/MultiStreamController/onResume_A02_t01.dart b/LibTest/async/MultiStreamController/onResume_A02_t01.dart new file mode 100644 index 0000000000..1d0c3cb27f --- /dev/null +++ b/LibTest/async/MultiStreamController/onResume_A02_t01.dart @@ -0,0 +1,49 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion void Function()? onResume +/// The callback which is called when the stream is resumed. +/// +/// May be set to `null`, in which case no callback will happen. +/// +/// Pause related callbacks are not supported on broadcast stream controllers. +/// +/// @description Checks that if this callback is set to `null`, then no callback +/// happens. +/// @author sgrekhov22@gmail.com +/// @issue 56927 + +import "dart:async"; +import "../../../Utils/expect.dart"; + +main() { + asyncStart(2); + var stream = Stream.multi((controller) { + Expect.isNull(controller.onResume); + controller.onResume = () { + Expect.fail("Unexpected onResume"); + }; + controller.onResume = null; + controller.add(1); + controller.add(2); + controller.add(3); + }); + listen(stream); + listen(stream); +} + +void listen(Stream stream) { + late StreamSubscription ss; + int i = 0; + ss = stream.listen((v) { + Expect.equals(++i, v); + if (i == 1) { + ss.pause(); + Future.delayed(Duration(milliseconds: 100), () { + ss.resume(); + asyncEnd(); + }); + } + }); +} From e385410f4a8b4f5f1ae9cd87556d7fbe7f0f6d8a Mon Sep 17 00:00:00 2001 From: sgrekhov Date: Mon, 21 Oct 2024 19:30:15 +0300 Subject: [PATCH 3/7] Implement review recommendations --- LibTest/async/MultiStreamController/isPaused_A01_t01.dart | 1 + LibTest/async/MultiStreamController/isPaused_A01_t02.dart | 3 ++- LibTest/async/MultiStreamController/onPause_A01_t02.dart | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/LibTest/async/MultiStreamController/isPaused_A01_t01.dart b/LibTest/async/MultiStreamController/isPaused_A01_t01.dart index 95fec1b4fc..882016ea11 100644 --- a/LibTest/async/MultiStreamController/isPaused_A01_t01.dart +++ b/LibTest/async/MultiStreamController/isPaused_A01_t01.dart @@ -24,6 +24,7 @@ main() { asyncStart(); var controllers = >[]; var stream = Stream.multi((controller) { + controllers.add(controller); Expect.isFalse(controller.isPaused); controller.add(1); controller.add(2); diff --git a/LibTest/async/MultiStreamController/isPaused_A01_t02.dart b/LibTest/async/MultiStreamController/isPaused_A01_t02.dart index f41eddb4af..622e33bee5 100644 --- a/LibTest/async/MultiStreamController/isPaused_A01_t02.dart +++ b/LibTest/async/MultiStreamController/isPaused_A01_t02.dart @@ -24,11 +24,12 @@ main() { asyncStart(); var controllers = >[]; var stream = Stream.multi((controller) { + controllers.add(controller); Expect.isFalse(controller.isPaused); controller.add(1); controller.add(2); controller.add(3); - }); + }, isBroadcast: true); listen(stream); listen(stream); Future.delayed(Duration(milliseconds: 200), () { diff --git a/LibTest/async/MultiStreamController/onPause_A01_t02.dart b/LibTest/async/MultiStreamController/onPause_A01_t02.dart index 3c3d69f97f..5378816e80 100644 --- a/LibTest/async/MultiStreamController/onPause_A01_t02.dart +++ b/LibTest/async/MultiStreamController/onPause_A01_t02.dart @@ -9,7 +9,8 @@ /// /// Pause related callbacks are not supported on broadcast stream controllers. /// -/// @description Checks that this callback is called when the stream is paused. +/// @description Checks that if this property is set to `null` then no callback +/// happens. /// @author sgrekhov22@gmail.com import "dart:async"; From dbca77ac21246f16496d7bed7a1396fb3203ff4d Mon Sep 17 00:00:00 2001 From: sgrekhov Date: Tue, 22 Oct 2024 12:33:52 +0300 Subject: [PATCH 4/7] Remove setting onSomeEvent tests to null --- .../onCancel_A02_t01.dart | 38 -------------- .../onResume_A02_t01.dart | 49 ------------------- 2 files changed, 87 deletions(-) delete mode 100644 LibTest/async/MultiStreamController/onCancel_A02_t01.dart delete mode 100644 LibTest/async/MultiStreamController/onResume_A02_t01.dart diff --git a/LibTest/async/MultiStreamController/onCancel_A02_t01.dart b/LibTest/async/MultiStreamController/onCancel_A02_t01.dart deleted file mode 100644 index 3dd3af4eb3..0000000000 --- a/LibTest/async/MultiStreamController/onCancel_A02_t01.dart +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -/// @assertion FutureOr Function()? onCancel -/// The callback which is called when the stream is canceled. -/// -/// May be set to `null`, in which case no callback will happen. -/// -/// @description Checks that if this callback is set to `null`, then no callback -/// happens. -/// @author sgrekhov22@gmail.com - -import "dart:async"; -import "../../../Utils/expect.dart"; - -main() { - asyncStart(2); - var stream = Stream.multi((controller) { - controller.onCancel = () { - Expect.fail("Unexpected onCancel"); - }; - controller.onCancel = null; - controller.add(1); - controller.add(2); - controller.add(3); - }); - listen(stream); - listen(stream); -} - -void listen(Stream stream) { - late StreamSubscription ss; - ss = stream.listen((v) { - ss.cancel(); - asyncEnd(); - }); -} diff --git a/LibTest/async/MultiStreamController/onResume_A02_t01.dart b/LibTest/async/MultiStreamController/onResume_A02_t01.dart deleted file mode 100644 index 1d0c3cb27f..0000000000 --- a/LibTest/async/MultiStreamController/onResume_A02_t01.dart +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -/// @assertion void Function()? onResume -/// The callback which is called when the stream is resumed. -/// -/// May be set to `null`, in which case no callback will happen. -/// -/// Pause related callbacks are not supported on broadcast stream controllers. -/// -/// @description Checks that if this callback is set to `null`, then no callback -/// happens. -/// @author sgrekhov22@gmail.com -/// @issue 56927 - -import "dart:async"; -import "../../../Utils/expect.dart"; - -main() { - asyncStart(2); - var stream = Stream.multi((controller) { - Expect.isNull(controller.onResume); - controller.onResume = () { - Expect.fail("Unexpected onResume"); - }; - controller.onResume = null; - controller.add(1); - controller.add(2); - controller.add(3); - }); - listen(stream); - listen(stream); -} - -void listen(Stream stream) { - late StreamSubscription ss; - int i = 0; - ss = stream.listen((v) { - Expect.equals(++i, v); - if (i == 1) { - ss.pause(); - Future.delayed(Duration(milliseconds: 100), () { - ss.resume(); - asyncEnd(); - }); - } - }); -} From e471b9ff352df30dfcf83b131eb4745bd24abde0 Mon Sep 17 00:00:00 2001 From: sgrekhov Date: Tue, 22 Oct 2024 15:18:18 +0300 Subject: [PATCH 5/7] Implement review recommendations --- LibTest/async/MultiStreamController/onResume_A01_t01.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/LibTest/async/MultiStreamController/onResume_A01_t01.dart b/LibTest/async/MultiStreamController/onResume_A01_t01.dart index 1bf90881c9..f2179f3c9b 100644 --- a/LibTest/async/MultiStreamController/onResume_A01_t01.dart +++ b/LibTest/async/MultiStreamController/onResume_A01_t01.dart @@ -20,7 +20,6 @@ main() { var stream = Stream.multi((controller) { Expect.isNull(controller.onResume); controller.onResume = () { - controller.close(); asyncEnd(); }; controller.add(1); From 4346b80e8cdcdf0d6b7544e7f703078cbf746dbd Mon Sep 17 00:00:00 2001 From: sgrekhov Date: Wed, 23 Oct 2024 15:36:00 +0300 Subject: [PATCH 6/7] Readd setting `onSomeEvent` tests --- .../onCancel_A02_t01.dart | 35 +++++++++++++++ .../onResume_A02_t01.dart | 45 +++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 LibTest/async/MultiStreamController/onCancel_A02_t01.dart create mode 100644 LibTest/async/MultiStreamController/onResume_A02_t01.dart diff --git a/LibTest/async/MultiStreamController/onCancel_A02_t01.dart b/LibTest/async/MultiStreamController/onCancel_A02_t01.dart new file mode 100644 index 0000000000..b1de7fce2b --- /dev/null +++ b/LibTest/async/MultiStreamController/onCancel_A02_t01.dart @@ -0,0 +1,35 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion FutureOr Function()? onCancel +/// The callback which is called when the stream is canceled. +/// +/// May be set to `null`, in which case no callback will happen. +/// +/// @description Checks that if this callback is set to `null`, then no callback +/// happens. +/// @author sgrekhov22@gmail.com + +import "dart:async"; +import "../../../Utils/expect.dart"; + +main() { + asyncStart(2); + var stream = Stream.multi((controller) { + controller.onCancel = null; + controller.add(1); + controller.add(2); + controller.add(3); + }); + listen(stream); + listen(stream); +} + +void listen(Stream stream) { + late StreamSubscription ss; + ss = stream.listen((v) { + ss.cancel(); + asyncEnd(); + }); +} diff --git a/LibTest/async/MultiStreamController/onResume_A02_t01.dart b/LibTest/async/MultiStreamController/onResume_A02_t01.dart new file mode 100644 index 0000000000..89ff286a02 --- /dev/null +++ b/LibTest/async/MultiStreamController/onResume_A02_t01.dart @@ -0,0 +1,45 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion void Function()? onResume +/// The callback which is called when the stream is resumed. +/// +/// May be set to `null`, in which case no callback will happen. +/// +/// Pause related callbacks are not supported on broadcast stream controllers. +/// +/// @description Checks that if this callback is set to `null`, then no callback +/// happens. +/// @author sgrekhov22@gmail.com + +import "dart:async"; +import "../../../Utils/expect.dart"; + +main() { + asyncStart(2); + var stream = Stream.multi((controller) { + Expect.isNull(controller.onResume); + controller.onResume = null; + controller.add(1); + controller.add(2); + controller.add(3); + }); + listen(stream); + listen(stream); +} + +void listen(Stream stream) { + late StreamSubscription ss; + int i = 0; + ss = stream.listen((v) { + Expect.equals(++i, v); + if (i == 1) { + ss.pause(); + Future.delayed(Duration(milliseconds: 100), () { + ss.resume(); + asyncEnd(); + }); + } + }); +} From 7584935f5653c00646319e1f58c9e15b23cbc784 Mon Sep 17 00:00:00 2001 From: sgrekhov Date: Fri, 25 Oct 2024 10:25:47 +0300 Subject: [PATCH 7/7] Implement review recommendations --- LibTest/async/MultiStreamController/onListen_A02_t01.dart | 3 +-- LibTest/async/MultiStreamController/onPause_A01_t02.dart | 3 --- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/LibTest/async/MultiStreamController/onListen_A02_t01.dart b/LibTest/async/MultiStreamController/onListen_A02_t01.dart index 43f18a10e6..970bf3d900 100644 --- a/LibTest/async/MultiStreamController/onListen_A02_t01.dart +++ b/LibTest/async/MultiStreamController/onListen_A02_t01.dart @@ -29,6 +29,5 @@ main() { } void listen(Stream stream) { - stream.listen((v) { - }, onDone: asyncEnd); + stream.listen(null, onDone: asyncEnd); } diff --git a/LibTest/async/MultiStreamController/onPause_A01_t02.dart b/LibTest/async/MultiStreamController/onPause_A01_t02.dart index 5378816e80..fcddb18aed 100644 --- a/LibTest/async/MultiStreamController/onPause_A01_t02.dart +++ b/LibTest/async/MultiStreamController/onPause_A01_t02.dart @@ -19,9 +19,6 @@ import "../../../Utils/expect.dart"; main() { asyncStart(2); var stream = Stream.multi((controller) { - controller.onPause = () { - Expect.fail("Unexpected onPause"); - }; controller.onPause = null; controller.add(1); controller.add(2);