3
3
4
4
using System ;
5
5
using System . IO ;
6
- using System . Threading ;
7
6
using System . Runtime . CompilerServices ;
8
- using Xunit ;
9
7
using System . Runtime . InteropServices ;
8
+ using System . Threading ;
9
+ using Xunit ;
10
10
11
11
public static class Utility
12
12
{
13
13
// These pinvokes are used only for tests and not by the src
14
14
[ DllImport ( "Kernel32.dll" , EntryPoint = "CreateSymbolicLinkW" , SetLastError = true ) ]
15
15
private static extern byte CreateSymbolicLink ( string linkName , string targetFileName , int flags ) ;
16
+
16
17
[ DllImport ( "libc" , SetLastError = true ) ]
17
18
private static extern int symlink ( string oldPath , string newPath ) ;
18
19
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 ;
23
20
private const int SYMBOLIC_LINK_FLAG_DIRECTORY = 0x1 ;
24
21
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
+
25
31
public static TemporaryTestFile CreateTestFile ( [ CallerMemberName ] string path = null )
26
32
{
27
33
if ( String . IsNullOrEmpty ( path ) )
@@ -97,15 +103,15 @@ public static AutoResetEvent WatchForEvents(FileSystemWatcher watcher, WatcherCh
97
103
return eventOccured ;
98
104
}
99
105
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 )
101
107
{
102
108
string message = String . Format ( "Didn't observe a {0} event within {1}ms" , eventName , timeout ) ;
103
109
Assert . True ( eventOccured . WaitOne ( timeout ) , message ) ;
104
110
}
105
111
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 )
107
113
{
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 ) ;
109
115
Assert . False ( eventOccured . WaitOne ( timeout ) , message ) ;
110
116
}
111
117
@@ -128,11 +134,11 @@ public static void TestNestedDirectoriesHelper(
128
134
129
135
using ( var firstDir = new TemporaryTestDirectory ( Path . Combine ( dir . Path , "dir1" ) ) )
130
136
{
131
- Utility . ExpectEvent ( createdOccured , "dir1 created" , WaitForCreationTimeoutInMs ) ;
137
+ Utility . ExpectEvent ( createdOccured , "dir1 created" ) ;
132
138
133
139
using ( var nestedDir = new TemporaryTestDirectory ( Path . Combine ( firstDir . Path , "nested" ) ) )
134
140
{
135
- Utility . ExpectEvent ( createdOccured , "nested created" , WaitForCreationTimeoutInMs ) ;
141
+ Utility . ExpectEvent ( createdOccured , "nested created" ) ;
136
142
137
143
action ( eventOccured , nestedDir ) ;
138
144
}
0 commit comments