From 0b87be52ab8d15ca264518f700a2d4857a955226 Mon Sep 17 00:00:00 2001 From: Danny Tuppeny Date: Mon, 17 Jan 2022 18:24:23 +0000 Subject: [PATCH 1/8] Add/enable Windows tests --- test/directory_watcher/shared.dart | 3 ++- test/directory_watcher/windows_test.dart | 4 +--- test/no_subscription/windows_test.dart | 17 +++++++++++++++++ test/ready/windows_test.dart | 17 +++++++++++++++++ 4 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 test/no_subscription/windows_test.dart create mode 100644 test/ready/windows_test.dart diff --git a/test/directory_watcher/shared.dart b/test/directory_watcher/shared.dart index ebce488..87300a0 100644 --- a/test/directory_watcher/shared.dart +++ b/test/directory_watcher/shared.dart @@ -276,7 +276,8 @@ void sharedTests() { isAddEvent('new') ]); }, onPlatform: { - 'mac-os': Skip('https://github.com/dart-lang/watcher/issues/21') + 'mac-os': Skip('https://github.com/dart-lang/watcher/issues/21'), + 'windows': Skip('https://github.com/dart-lang/watcher/issues/21') }); test('emits events for many nested files added at once', () async { diff --git a/test/directory_watcher/windows_test.dart b/test/directory_watcher/windows_test.dart index 6ea412f..3ddb47e 100644 --- a/test/directory_watcher/windows_test.dart +++ b/test/directory_watcher/windows_test.dart @@ -14,11 +14,9 @@ import '../utils.dart'; void main() { watcherFactory = (dir) => WindowsDirectoryWatcher(dir); - // TODO(grouma) - renable when https://github.com/dart-lang/sdk/issues/31760 - // is resolved. group('Shared Tests:', () { sharedTests(); - }, skip: 'SDK issue see - https://github.com/dart-lang/sdk/issues/31760'); + }); test('DirectoryWatcher creates a WindowsDirectoryWatcher on Windows', () { expect(DirectoryWatcher('.'), TypeMatcher()); diff --git a/test/no_subscription/windows_test.dart b/test/no_subscription/windows_test.dart new file mode 100644 index 0000000..eb381d0 --- /dev/null +++ b/test/no_subscription/windows_test.dart @@ -0,0 +1,17 @@ +// Copyright (c) 2022, 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. + +@TestOn('windows') + +import 'package:test/test.dart'; +import 'package:watcher/src/directory_watcher/windows.dart'; + +import 'shared.dart'; +import '../utils.dart'; + +void main() { + watcherFactory = (dir) => WindowsDirectoryWatcher(dir); + + sharedTests(); +} diff --git a/test/ready/windows_test.dart b/test/ready/windows_test.dart new file mode 100644 index 0000000..eb381d0 --- /dev/null +++ b/test/ready/windows_test.dart @@ -0,0 +1,17 @@ +// Copyright (c) 2022, 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. + +@TestOn('windows') + +import 'package:test/test.dart'; +import 'package:watcher/src/directory_watcher/windows.dart'; + +import 'shared.dart'; +import '../utils.dart'; + +void main() { + watcherFactory = (dir) => WindowsDirectoryWatcher(dir); + + sharedTests(); +} From ed55adbe5c9e8f7a937166686db433a5138972ca Mon Sep 17 00:00:00 2001 From: Danny Tuppeny Date: Tue, 18 Jan 2022 18:16:23 +0000 Subject: [PATCH 2/8] Ensure watcher subs are cancelled --- test/ready/shared.dart | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/ready/shared.dart b/test/ready/shared.dart index 6578c52..d9bb5ae 100644 --- a/test/ready/shared.dart +++ b/test/ready/shared.dart @@ -21,19 +21,21 @@ void sharedTests() { expect(ready, isFalse); // Subscribe to the events. - watcher.events.listen((event) {}); + var subscription = watcher.events.listen((event) {}); await watcher.ready; // Should eventually be ready. expect(watcher.isReady, isTrue); + + await subscription.cancel(); }); test('ready completes immediately when already ready', () async { var watcher = createWatcher(); // Subscribe to the events. - watcher.events.listen((event) {}); + var subscription = watcher.events.listen((event) {}); // Allow watcher to become ready await watcher.ready; @@ -43,6 +45,8 @@ void sharedTests() { watcher.ready.timeout(Duration(milliseconds: 0), onTimeout: () => throw 'Does not complete immedately'), completes); + + await subscription.cancel(); }); test('ready returns a future that does not complete after unsubscribing', From 3419ac57868dd539cc074c9e0610f5308fad1e97 Mon Sep 17 00:00:00 2001 From: Danny Tuppeny Date: Wed, 19 Jan 2022 10:05:22 +0000 Subject: [PATCH 3/8] Try adding a delay during teardown on Windows to see if it helps with deletion errors --- test/utils.dart | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/utils.dart b/test/utils.dart index 8d8981c..e37d04d 100644 --- a/test/utils.dart +++ b/test/utils.dart @@ -42,6 +42,10 @@ Watcher createWatcher({String? path}) { path = p.join(d.sandbox, path); } + if (Platform.isWindows) { + addTearDown(() => Future.delayed(const Duration(milliseconds: 500))); + } + return _watcherFactory(path); } From b1bbfe35d36fc2b325de6b5afb22f17659a42471 Mon Sep 17 00:00:00 2001 From: Danny Tuppeny Date: Wed, 19 Jan 2022 10:12:51 +0000 Subject: [PATCH 4/8] Try forcing cancellation of subscription --- test/utils.dart | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/utils.dart b/test/utils.dart index e37d04d..6137237 100644 --- a/test/utils.dart +++ b/test/utils.dart @@ -43,7 +43,10 @@ Watcher createWatcher({String? path}) { } if (Platform.isWindows) { - addTearDown(() => Future.delayed(const Duration(milliseconds: 500))); + addTearDown(() async { + await Future.delayed(const Duration(milliseconds: 500)); + await _watcherEvents.cancel(immediate: true)?.catchError((e) {}); + }); } return _watcherFactory(path); From c3319322e436b7bc46dbd98d56758f8981179e57 Mon Sep 17 00:00:00 2001 From: Danny Tuppeny Date: Wed, 19 Jan 2022 10:17:02 +0000 Subject: [PATCH 5/8] Test only cancelling once --- test/utils.dart | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/utils.dart b/test/utils.dart index 6137237..88338d0 100644 --- a/test/utils.dart +++ b/test/utils.dart @@ -45,7 +45,8 @@ Watcher createWatcher({String? path}) { if (Platform.isWindows) { addTearDown(() async { await Future.delayed(const Duration(milliseconds: 500)); - await _watcherEvents.cancel(immediate: true)?.catchError((e) {}); + await pumpEventQueue(); + await _watcherEvents.cancel(immediate: true); }); } @@ -87,8 +88,8 @@ Future startWatcher({String? path}) async { /// indefinitely because they might in the future and because the watcher is /// normally only closed after the test completes. void startClosingEventStream() async { - await pumpEventQueue(); - await _watcherEvents.cancel(immediate: true); + // await pumpEventQueue(); + // await _watcherEvents.cancel(immediate: true); } /// A list of [StreamMatcher]s that have been collected using From 42ceb65a3461c3e1914c23a88698fe83b4070102 Mon Sep 17 00:00:00 2001 From: Danny Tuppeny Date: Wed, 19 Jan 2022 10:25:04 +0000 Subject: [PATCH 6/8] Allow tests to close watcher, but ensure they always close via teardown --- test/utils.dart | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/test/utils.dart b/test/utils.dart index 88338d0..a34f572 100644 --- a/test/utils.dart +++ b/test/utils.dart @@ -42,20 +42,18 @@ Watcher createWatcher({String? path}) { path = p.join(d.sandbox, path); } - if (Platform.isWindows) { - addTearDown(() async { - await Future.delayed(const Duration(milliseconds: 500)); - await pumpEventQueue(); - await _watcherEvents.cancel(immediate: true); - }); - } - return _watcherFactory(path); } /// The stream of events from the watcher started with [startWatcher]. late StreamQueue _watcherEvents; +/// Whether the event stream has been closed. +/// +/// If this is not done by a test (by calling [startClosingEventStream]) it will +/// be done automatically via [addTearDown] in [startWatcher]. +var _hasClosedStream = true; + /// Creates a new [Watcher] that watches a temporary file or directory and /// starts monitoring it for events. /// @@ -78,6 +76,9 @@ Future startWatcher({String? path}) async { _watcherEvents = StreamQueue(watcher.events); // Forces a subscription to the underlying stream. unawaited(_watcherEvents.hasNext); + + addTearDown(startClosingEventStream); + await watcher.ready; } @@ -88,8 +89,10 @@ Future startWatcher({String? path}) async { /// indefinitely because they might in the future and because the watcher is /// normally only closed after the test completes. void startClosingEventStream() async { - // await pumpEventQueue(); - // await _watcherEvents.cancel(immediate: true); + if (_hasClosedStream) return; + _hasClosedStream = true; + await pumpEventQueue(); + await _watcherEvents.cancel(immediate: true); } /// A list of [StreamMatcher]s that have been collected using From b303a454c17e9c037aa6aade75b65d693b19a88b Mon Sep 17 00:00:00 2001 From: Danny Tuppeny Date: Wed, 19 Jan 2022 10:25:47 +0000 Subject: [PATCH 7/8] Ensure _hasClosedStream is reset when a new watcher is set up --- test/utils.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/test/utils.dart b/test/utils.dart index a34f572..23adcbc 100644 --- a/test/utils.dart +++ b/test/utils.dart @@ -77,6 +77,7 @@ Future startWatcher({String? path}) async { // Forces a subscription to the underlying stream. unawaited(_watcherEvents.hasNext); + _hasClosedStream = false; addTearDown(startClosingEventStream); await watcher.ready; From 4c40b99a9f305179af51e2a89439db8f2c75d0a2 Mon Sep 17 00:00:00 2001 From: Danny Tuppeny Date: Wed, 19 Jan 2022 15:50:01 +0000 Subject: [PATCH 8/8] Skip failing test on Windows See #125. --- test/directory_watcher/shared.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/directory_watcher/shared.dart b/test/directory_watcher/shared.dart index 87300a0..07fbf9c 100644 --- a/test/directory_watcher/shared.dart +++ b/test/directory_watcher/shared.dart @@ -134,6 +134,8 @@ void sharedTests() { renameFile('from.txt', 'to.txt'); await inAnyOrder([isRemoveEvent('from.txt'), isModifyEvent('to.txt')]); + }, onPlatform: { + 'windows': Skip('https://github.com/dart-lang/watcher/issues/125') }); });