| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2012, 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 import 'dart:io'; |
| 7 |
| 8 import 'package:scheduled_test/scheduled_test.dart'; |
| 9 import 'package:watcher/watcher.dart'; |
| 10 |
| 11 import 'utils.dart'; |
| 12 |
| 13 main() { |
| 14 initConfig(); |
| 15 |
| 16 setUp(createSandbox); |
| 17 |
| 18 test('ready does not complete until after subscription', () { |
| 19 var watcher = createWatcher(waitForReady: false); |
| 20 |
| 21 var ready = false; |
| 22 watcher.ready.then((_) { |
| 23 ready = true; |
| 24 }); |
| 25 |
| 26 // Should not be ready yet. |
| 27 schedule(() { |
| 28 expect(ready, isFalse); |
| 29 }); |
| 30 |
| 31 // Subscribe to the events. |
| 32 schedule(() { |
| 33 var subscription = watcher.events.listen((event) {}); |
| 34 |
| 35 currentSchedule.onComplete.schedule(() { |
| 36 subscription.cancel(); |
| 37 }); |
| 38 }); |
| 39 |
| 40 // Should eventually be ready. |
| 41 schedule(() => watcher.ready); |
| 42 |
| 43 schedule(() { |
| 44 expect(ready, isTrue); |
| 45 }); |
| 46 }); |
| 47 |
| 48 test('ready completes immediately when already ready', () { |
| 49 var watcher = createWatcher(waitForReady: false); |
| 50 |
| 51 // Subscribe to the events. |
| 52 schedule(() { |
| 53 var subscription = watcher.events.listen((event) {}); |
| 54 |
| 55 currentSchedule.onComplete.schedule(() { |
| 56 subscription.cancel(); |
| 57 }); |
| 58 }); |
| 59 |
| 60 // Should eventually be ready. |
| 61 schedule(() => watcher.ready); |
| 62 |
| 63 // Now ready should be a future that immediately completes. |
| 64 var ready = false; |
| 65 schedule(() { |
| 66 watcher.ready.then((_) { |
| 67 ready = true; |
| 68 }); |
| 69 }); |
| 70 |
| 71 schedule(() { |
| 72 expect(ready, isTrue); |
| 73 }); |
| 74 }); |
| 75 |
| 76 test('ready returns a future that does not complete after unsubscribing', () { |
| 77 var watcher = createWatcher(waitForReady: false); |
| 78 |
| 79 // Subscribe to the events. |
| 80 var subscription; |
| 81 schedule(() { |
| 82 subscription = watcher.events.listen((event) {}); |
| 83 }); |
| 84 |
| 85 var ready = false; |
| 86 |
| 87 // Wait until ready. |
| 88 schedule(() => watcher.ready); |
| 89 |
| 90 // Now unsubscribe. |
| 91 schedule(() { |
| 92 subscription.cancel(); |
| 93 |
| 94 // Track when it's ready again. |
| 95 ready = false; |
| 96 watcher.ready.then((_) { |
| 97 ready = true; |
| 98 }); |
| 99 }); |
| 100 |
| 101 // Should be back to not ready. |
| 102 schedule(() { |
| 103 expect(ready, isFalse); |
| 104 }); |
| 105 }); |
| 106 } |
| OLD | NEW |