Repository: flutter
Issue: flutter_test adds a delayed item to stream after it's closed
Labels: a: tests,c: new feature,framework,c: proposal,P2,team-framework,triaged-framework

## Steps to Reproduce

1. Put this code somewhere a test will run it.
```dart
    final sc = StreamController<String>();
    final obs = Observable.just("test").delay(Duration(seconds: 1)).takeUntil(sc.stream).listen((s) => print(s));
    // final obs = Observable.just("test").takeUntil(sc.stream).listen((s) => print(s));  <---  This works
    sc.add("whatever");
```
2. Make sure the test pumps enough time to trigger the delayed action.
2. Run the test, observe an exception thrown (see logs).
3. Run on device/emulation, observe that it works.

## Logs

```
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following StateError was thrown running a test:
Bad state: Cannot add event after closing

When the exception was thrown, this was the stack:
#12     DelayStreamTransformer._buildTransformer.<anonymous closure>.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:rxdart/src/transformers/delay.dart:42:34)
#22     AutomatedTestWidgetsFlutterBinding.pump.<anonymous closure> (package:flutter_test/src/binding.dart:705:27)
#25     TestAsyncUtils.guard (package:flutter_test/src/test_async_utils.dart:69:41)
#26     AutomatedTestWidgetsFlutterBinding.pump (package:flutter_test/src/binding.dart:701:27)
#27     WidgetTester.pump.<anonymous closure> (package:flutter_test/src/widget_tester.dart:247:53)
#30     TestAsyncUtils.guard (package:flutter_test/src/test_async_utils.dart:69:41)
#31     WidgetTester.pump (package:flutter_test/src/widget_tester.dart:247:27)
#32     main.<anonymous closure> (file:///C:/Users/andrey/Documents/Code/hello/hello_world/test/widget_test.dart:30:18)
<asynchronous suspension>
#33     testWidgets.<anonymous closure>.<anonymous closure> (package:flutter_test/src/widget_tester.dart:72:23)
#34     TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:566:19)
<asynchronous suspension>
#37     TestWidgetsFlutterBinding._runTest (package:flutter_test/src/binding.dart:550:14)
#38     AutomatedTestWidgetsFlutterBinding.runTest.<anonymous closure> (package:flutter_test/src/binding.dart:893:24)
#44     AutomatedTestWidgetsFlutterBinding.runTest (package:flutter_test/src/binding.dart:890:15)
#45     testWidgets.<anonymous closure> (package:flutter_test/src/widget_tester.dart:71:22)
#46     Declarer.test.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:test_api/src/backend/declarer.dart:168:27)
<asynchronous suspension>
#47     Invoker.waitForOutstandingCallbacks.<anonymous closure> (package:test_api/src/backend/invoker.dart:249:15)
<asynchronous suspension>
#52     Invoker.waitForOutstandingCallbacks (package:test_api/src/backend/invoker.dart:246:5)
#53     Declarer.test.<anonymous closure>.<anonymous closure> (package:test_api/src/backend/declarer.dart:166:33)
#58     Declarer.test.<anonymous closure> (package:test_api/src/backend/declarer.dart:165:13)
<asynchronous suspension>
#59     Invoker._onRun.<anonymous closure>.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:test_api/src/backend/invoker.dart:399:25)
<asynchronous suspension>
#73     _Timer._runTimers (dart:isolate/runtime/libtimer_impl.dart:382:19)
#74     _Timer._handleMessage (dart:isolate/runtime/libtimer_impl.dart:416:5)
#75     _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171:12)
(elided 53 frames from class _FakeAsync, package dart:async, and package stack_trace)

The test description was:
Counter increments smoke test
════════════════════════════════════════════════════════════════════════════════════════════════════
Test failed. See exception logs above.
The test description was: Counter increments smoke test

✖ Counter increments smoke test
Exited (1)
```

flutter analyze
```
Analyzing hello_world...
No issues found! (ran in 2.0s)
```

flutter doctor -v
```
[√] Flutter (Channel beta, v0.11.3, on Microsoft Windows [Version 10.0.17134.407], locale en-AU)
    • Flutter version 0.11.3 at C:\flutter
    • Framework revision 72bf075e8d (4 weeks ago), 2018-11-09 20:36:17 -0800
    • Engine revision 5646e86a6f
    • Dart version 2.1.0 (build 2.1.0-dev.9.3 9c07fb64c4)

[√] Android toolchain - develop for Android devices (Android SDK 28.0.3)
    • Android SDK at C:\Users\andrey\AppData\Local\Android\sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
    • All Android licenses accepted.

[√] Android Studio (version 3.2)
    • Android Studio at C:\Program Files\Android\Android Studio
    X Flutter plugin not installed; this adds Flutter specific functionality.
    X Dart plugin not installed; this adds Dart specific functionality.
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)

[√] VS Code (version 1.29.1)
    • VS Code at C:\Users\andrey\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 2.21.0

[√] Connected device (1 available)
    • SM N910C • 4100e4f8f29ba2e5 • android-arm • Android 6.0.1 (API 23)

• No issues found!
```