| 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 | |
| 7 import 'package:scheduled_test/scheduled_test.dart'; | |
| 8 import 'package:watcher/watcher.dart'; | |
| 9 | |
| 10 import 'utils.dart'; | |
| 11 | |
| 12 main() { | |
| 13 initConfig(); | |
| 14 | |
| 15 setUp(createSandbox); | |
| 16 | |
| 17 test('does not notify for changes when there were no subscribers', () { | |
| 18 // Note that this test doesn't rely as heavily on the test functions in | |
| 19 // utils.dart because it needs to be very explicit about when the event | |
| 20 // stream is and is not subscribed. | |
| 21 var watcher = createWatcher(); | |
| 22 | |
| 23 // Subscribe to the events. | |
| 24 var completer = new Completer(); | |
| 25 var subscription = watcher.events.listen(wrapAsync((event) { | |
| 26 expect(event.type, equals(ChangeType.ADD)); | |
| 27 expect(event.path, endsWith("file.txt")); | |
| 28 completer.complete(); | |
| 29 })); | |
| 30 | |
| 31 writeFile("file.txt"); | |
| 32 | |
| 33 // Then wait until we get an event for it. | |
| 34 schedule(() => completer.future); | |
| 35 | |
| 36 // Unsubscribe. | |
| 37 schedule(() { | |
| 38 subscription.cancel(); | |
| 39 }); | |
| 40 | |
| 41 // Now write a file while we aren't listening. | |
| 42 writeFile("unwatched.txt"); | |
| 43 | |
| 44 // Then start listening again. | |
| 45 schedule(() { | |
| 46 completer = new Completer(); | |
| 47 subscription = watcher.events.listen(wrapAsync((event) { | |
| 48 // We should get an event for the third file, not the one added while | |
| 49 // we weren't subscribed. | |
| 50 expect(event.type, equals(ChangeType.ADD)); | |
| 51 expect(event.path, endsWith("added.txt")); | |
| 52 completer.complete(); | |
| 53 })); | |
| 54 }); | |
| 55 | |
| 56 // The watcher will have been cancelled and then resumed in the middle of | |
| 57 // its pause between polling loops. That means the second scan to skip | |
| 58 // what changed while we were unsubscribed won't happen until after that | |
| 59 // delay is done. Wait long enough for that to happen. | |
| 60 // | |
| 61 // We're doing * 4 here because that seems to give the slower bots enough | |
| 62 // time for this to complete. | |
| 63 schedule(() => new Future.delayed(watcher.pollingDelay * 4)); | |
| 64 | |
| 65 // And add a third file. | |
| 66 writeFile("added.txt"); | |
| 67 | |
| 68 // Wait until we get an event for the third file. | |
| 69 schedule(() => completer.future); | |
| 70 | |
| 71 schedule(() { | |
| 72 subscription.cancel(); | |
| 73 }); | |
| 74 }); | |
| 75 } | |
| OLD | NEW |