Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 0038741

Browse files
committed
Merge pull request #2742 from stephentoub/change_fsw_timeouts
Change timeouts on FSW tests
2 parents 4abf509 + 81e84b7 commit 0038741

File tree

4 files changed

+27
-21
lines changed

4 files changed

+27
-21
lines changed

src/System.IO.FileSystem.Watcher/tests/FileSystemWatcher.Created.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public static void FileSystemWatcher_Created_FileCreatedInNestedDirectory()
125125
{
126126
using (var nestedFile = new TemporaryTestFile(Path.Combine(ttd.Path, "nestedFile")))
127127
{
128-
Utility.ExpectEvent(are, "nested file created", 1000 * 30);
128+
Utility.ExpectEvent(are, "nested file created");
129129
}
130130
});
131131
}

src/System.IO.FileSystem.Watcher/tests/FileSystemWatcher.Deleted.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,17 @@ public static void FileSystemWatcher_Deleted_NestedDirectories()
102102
using (var firstDir = new TemporaryTestDirectory(Path.Combine(dir.Path, "dir1")))
103103
{
104104
// Wait for the created event
105-
Utility.ExpectEvent(createOccured, "create", 1000 * 30);
105+
Utility.ExpectEvent(createOccured, "create");
106106

107107
using (var secondDir = new TemporaryTestDirectory(Path.Combine(firstDir.Path, "dir2")))
108108
{
109109
// Wait for the created event
110-
Utility.ExpectEvent(createOccured, "create", 1000 * 30);
110+
Utility.ExpectEvent(createOccured, "create");
111111

112112
using (var nestedDir = new TemporaryTestDirectory(Path.Combine(secondDir.Path, "nested")))
113113
{
114114
// Wait for the created event
115-
Utility.ExpectEvent(createOccured, "create", 1000 * 30);
115+
Utility.ExpectEvent(createOccured, "create");
116116
}
117117

118118
Utility.ExpectEvent(eventOccured, "deleted");
@@ -142,12 +142,12 @@ public static void FileSystemWatcher_Deleted_FileDeletedInNestedDirectory()
142142
using (var firstDir = new TemporaryTestDirectory(Path.Combine(dir.Path, "dir1")))
143143
{
144144
// Wait for the created event
145-
Utility.ExpectEvent(createOccured, "create", 1000 * 30);
145+
Utility.ExpectEvent(createOccured, "create");
146146

147147
using (var secondDir = new TemporaryTestDirectory(Path.Combine(dir.Path, "dir2")))
148148
{
149149
// Wait for the created event
150-
Utility.ExpectEvent(createOccured, "create", 1000 * 30);
150+
Utility.ExpectEvent(createOccured, "create");
151151

152152
using (var nestedDir = new TemporaryTestFile(Path.Combine(secondDir.Path, "nestedFile"))) { }
153153

src/System.IO.FileSystem.Watcher/tests/FileSystemWatcher.Renamed.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public static void FileSystemWatcher_Renamed_FileInNestedDirectory()
7575
{
7676
using (var nestedFile = new TemporaryTestFile(Path.Combine(ttd.Path, "nestedFile")))
7777
{
78-
Utility.ExpectEvent(are, "file created", Utility.WaitForCreationTimeoutInMs);
78+
Utility.ExpectEvent(are, "file created");
7979
nestedFile.Move(nestedFile.Path + "_2");
8080
Utility.ExpectEvent(are, "renamed");
8181
}
@@ -103,11 +103,11 @@ public static void FileSystemWatcher_Moved_NestedDirectoryRoot()
103103

104104
using (var dir1 = new TemporaryTestDirectory(Path.Combine(dir.Path, "dir1")))
105105
{
106-
Utility.ExpectEvent(createdOccured, "dir1 created", Utility.WaitForCreationTimeoutInMs);
106+
Utility.ExpectEvent(createdOccured, "dir1 created");
107107

108108
using (var dir2 = new TemporaryTestDirectory(Path.Combine(dir1.Path, "dir2")))
109109
{
110-
Utility.ExpectEvent(createdOccured, "dir2 created", Utility.WaitForCreationTimeoutInMs);
110+
Utility.ExpectEvent(createdOccured, "dir2 created");
111111

112112
using (var file = Utility.CreateTestFile(Path.Combine(dir2.Path, "test file"))) { };
113113

@@ -146,7 +146,7 @@ public static void FileSystemWatcher_Moved_NestedDirectoryRootWithoutSubdirector
146146

147147
using (var dir1 = new TemporaryTestDirectory(Path.Combine(dir.Path, "dir1")))
148148
{
149-
Utility.ExpectEvent(createdOccured, "dir1 created", Utility.WaitForCreationTimeoutInMs);
149+
Utility.ExpectEvent(createdOccured, "dir1 created");
150150

151151
using (var dir2 = new TemporaryTestDirectory(Path.Combine(dir1.Path, "dir2")))
152152
{

src/System.IO.FileSystem.Watcher/tests/Utility/Utility.cs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,31 @@
33

44
using System;
55
using System.IO;
6-
using System.Threading;
76
using System.Runtime.CompilerServices;
8-
using Xunit;
97
using System.Runtime.InteropServices;
8+
using System.Threading;
9+
using Xunit;
1010

1111
public static class Utility
1212
{
1313
// These pinvokes are used only for tests and not by the src
1414
[DllImport("Kernel32.dll", EntryPoint = "CreateSymbolicLinkW", SetLastError = true)]
1515
private static extern byte CreateSymbolicLink(string linkName, string targetFileName, int flags);
16+
1617
[DllImport("libc", SetLastError = true)]
1718
private static extern int symlink(string oldPath, string newPath);
1819

19-
// events are reported asynchronously by the OS, so allow an amount of time for
20-
// them to arrive before testing an assertion.
21-
public const int Timeout = 500;
22-
public const int WaitForCreationTimeoutInMs = 1000 * 30;
2320
private const int SYMBOLIC_LINK_FLAG_DIRECTORY = 0x1;
2421

22+
// Events are reported asynchronously by the OS, so allow an amount of time for
23+
// them to arrive before testing an assertion. If we expect an event to occur,
24+
// we can wait for it for a relatively long time, as if it doesn't arrive, we're
25+
// going to fail the test. If we don't expect an event to occur, then we need
26+
// to keep the timeout short, as in a successful run we'll end up waiting for
27+
// the entire timeout specified.
28+
public const int WaitForExpectedEventTimeout = 30000;
29+
public const int WaitForUnexpectedEventTimeout = 500;
30+
2531
public static TemporaryTestFile CreateTestFile([CallerMemberName] string path = null)
2632
{
2733
if (String.IsNullOrEmpty(path))
@@ -97,15 +103,15 @@ public static AutoResetEvent WatchForEvents(FileSystemWatcher watcher, WatcherCh
97103
return eventOccured;
98104
}
99105

100-
public static void ExpectEvent(WaitHandle eventOccured, string eventName, int timeout = Utility.Timeout)
106+
public static void ExpectEvent(WaitHandle eventOccured, string eventName, int timeout = WaitForExpectedEventTimeout)
101107
{
102108
string message = String.Format("Didn't observe a {0} event within {1}ms", eventName, timeout);
103109
Assert.True(eventOccured.WaitOne(timeout), message);
104110
}
105111

106-
public static void ExpectNoEvent(WaitHandle eventOccured, string eventName, int timeout = Utility.Timeout)
112+
public static void ExpectNoEvent(WaitHandle eventOccured, string eventName, int timeout = WaitForUnexpectedEventTimeout)
107113
{
108-
string message = String.Format("Should not observe a {0} event", eventName);
114+
string message = String.Format("Should not observe a {0} event within {1}ms", eventName, timeout);
109115
Assert.False(eventOccured.WaitOne(timeout), message);
110116
}
111117

@@ -128,11 +134,11 @@ public static void TestNestedDirectoriesHelper(
128134

129135
using (var firstDir = new TemporaryTestDirectory(Path.Combine(dir.Path, "dir1")))
130136
{
131-
Utility.ExpectEvent(createdOccured, "dir1 created", WaitForCreationTimeoutInMs);
137+
Utility.ExpectEvent(createdOccured, "dir1 created");
132138

133139
using (var nestedDir = new TemporaryTestDirectory(Path.Combine(firstDir.Path, "nested")))
134140
{
135-
Utility.ExpectEvent(createdOccured, "nested created", WaitForCreationTimeoutInMs);
141+
Utility.ExpectEvent(createdOccured, "nested created");
136142

137143
action(eventOccured, nestedDir);
138144
}

0 commit comments

Comments
 (0)