When we're waiting for an event that we know will arrive, we can wait for a fairly long time, because if it doesn't arrive we're going to fail the tests anyway. This changes makes all of the ExpectEvent calls use a long timeout, much longer than most were previously using. In the process I removed all of the custom values being passed, as they were all the same or shorter than the new default. This should help to minimize avoid false positive flakiness.
Commit migrated from https://github.com/dotnet/corefx/commit/81e84b7910244f2f72ba760c100b16c01a38877c
My previous change to rename FSW test classes led to FSW tests getting parallelized. It turns out that some of the tests are not robust against this due to using file names that can end up conflicting with other tests. Additionally, it appears that the waiting / timeouts used by the tests is very susceptible to failure when run in parallel due to reliance on the shared thread pool, causing more failures in CI.
Commit migrated from https://github.com/dotnet/corefx/commit/83decea6937e1296be20202ff2f8ace51339e958
The FSW tests still take ~10 seconds on my machine, most of which is spent waiting for events to not fire. This change just separates the tests out so that they're not all on the same class, letting xunit parallelize them. They now take ~3.5 seconds on my machine.
Commit migrated from https://github.com/dotnet/corefx/commit/2fbabe417accb662a6ed63a40506dea0268cf8e2
One of the FSW tests is passing a 30 second timeout to an ExpectNoEvent, which means the test when correctly functioning will take at least 30 seconds. I've removed the custom timeout to give the test the normal timeout period of half a second.
Commit migrated from https://github.com/dotnet/corefx/commit/d4d0d561a3978f43ccb2271e8dc417d6d3ffefc2
At least on Windows 10, writing to a file can cause directories in its parent directory structure to also be noted as modified, such that events will be raised for those directories. This is causing the FileSystemWatcher_Changed_PreSeededNestedStructure test to consistently fail. I've updated the test to instead look for and modify file attributes, instead.
Commit migrated from https://github.com/dotnet/corefx/commit/784403a8cb1afa56136cdc4abd79a5425653c7d8
- Every iteration of calling ReadDirectoryChangesW was allocating a bunch of state (an FSWAsyncResult, a delegate, a new overlapped, etc). Fixed to allocate that state once and store it for the duration of the watching operation.
- Every iteration of calling ReadDirectoryChangesW was pinning/unpinning the buffer. Fixed to use a PreAllocatedOverlapped so that this happens just once for the whole operation.
- Centralized all of the cleanup code of the thread pool binding, and removed the thread pool binding field from the watcher as it's no longer necessary and it risks regressing to the code where we accidentally used the wrong one
- Removed confusing and duplicative flags around whether the implementation is currently running
- Removed duplicate interop code and moved the rest to the Common\src\Interop folder to follow the convention for the rest of the repo
- Made more robust the case where a failure occurs after creating the directory handle and before starting monitoring
- Removed unnecessary locking
- Reorganized some code to make the implementation easier to read, and added comments
Commit migrated from https://github.com/dotnet/corefx/commit/b6c478ccc9729e22ac7b9bf2248b644b51883db2
If a FileSystemWatcher is stopped and restarted while processing events, it can end up trying to free an allocated NativeOverlapped on the ThreadPoolBoundHandle associated with the new session even if it was created with the old one. This commit changes the code to store the appropriate binding and directory handle in locals and in the async state object so that the same binding can be used to free as was used to allocate.
Commit migrated from https://github.com/dotnet/corefx/commit/0f672042510d1902f7071189860c1960bd99ef43
inotify handles renames via a pair of MOVED_FROM and MOVED_TO events that are potentially delivered separately and that for some moves may not have a MOVED_TO at all (such as if moving a file out of the watched path). This means that if we get a MOVED_FROM and we haven't yet received any further events, we have a choice:
- Do we wait until we get another event to make a decision about how to process the MOVED_FROM, seeing if the next event is a MOVED_TO (in which case the MOVED_FROM is treated as part of the rename) or if it's something else (in which case the MOVED_FROM is treated as a deletion).
- Do we assume we won't get an associated MOVED_TO, and immediately treat the MOVED_FROM as a deletion.
We originally implemented the former, as it doesn't suffer from the race condition the latter suffers from, which might treat some MOVED_FROM/MOVED_TO pairs as a rename and others as a creation/deletion, based on timing. But it suffers from another problem, that if you just get a MOVED_FROM and no other event arrives (or arrives for a while) the event associated with the MOVED_FROM could be delayed (indefinitely if another event never arrives). dotnet/corefx#2587 switched from the former to the latter, under the assumption that it's the least bad of the two options.
As discussed at https://github.com/dotnet/corefx/pull/2655#issuecomment-128484923, a compromise can be to wait a few milliseconds for the MOVED_TO to arrive, as that's been shown to handle a vast majority of the cases where a MOVED_TO is on its way. This commit simply adds that timeout to our call to poll. As long as this code was being modified, the commit also adds a try/finally around the handle manipulation, just in case an exception happens to emerge.
Commit migrated from https://github.com/dotnet/corefx/commit/919d7af3f1277691c482bc0b7e35a510fe5fa370
On Linux, depending on the timing of events, we can sometimes generate
delete+create instead of rename. As such, we can't perform renames and
test that no create or delete is raised when we're running on Linux.
The issue had so far only arisen on the negative create test and not the
negative delete test, which turned out to be because the negative delete
test was using the wrong event name.
Commit migrated from https://github.com/dotnet/corefx/commit/56c279db8707bf9246109b1ff232925e0312b7f8
* Defer conversions until necessary
* Rename Errno -> RawErrno
* Return null for ERANGE for strerror
* Add conversion helper for Error -> ErrorInfo
* Fix typos
* Remove unnecessary _POSIX_C_SOURCE define
* Fix names and sizes of managed FileStatus members
* Don't double-initialize ErrorInfo out param
* Zero out BirthTime when not available
* Put back newline at EOL
* Restore size of UnixFileSystemObject
* Use ignored local name for ignored error info
* Rename Interop.System to Interop.Sys to avoid
collision with System namespace
Commit migrated from https://github.com/dotnet/corefx/commit/e82401bd3feea682832215d1e97dbb4bb73e211a
* Provide explicit constants for interpreting file mode
* Use extern "C" one function at a time
* Rename FileStats to FileStatus to match POSIX language
* Rename FileStatus to be more 1:1 with struct stat
* Put parameters on their own lines in header
Commit migrated from https://github.com/dotnet/corefx/commit/bf0290c0a45f9ea1edafaf1aa12f4ff576107303
Changed the way the UnixFileSystem does File moving; it was previously implemented using the rename syscall but now uses a combination of link and unlink. The side effect of this change is that the FileSystemWatcher will now treat File.Move as a deletion.
- Resolvesdotnet/corefx#2460
- Removed all tests from FileSystemWatcher that made calls to File.Move and consolidated them into a new file: FileSystemWatcher.MoveFile.cs. This new file separates tests into Windows and Unix categories and uses Theories to supply the input WatcherChangeType and whether a move should trigger an event for the given type. If we later decide to change the Unix behavior of MoveFile, changing the FileSystemWatcher tests will be a simple matter of flipping the boolean values for the affected tests.
- Fixed some comments in UnixFileSystem to be more specific to FileSystemWatcher
- Changed variable names for FSW Move tests to be more descriptive
- Modified FSW MoveFile and Utitlity helper classes to use guids so that they may be run concurrently.
Commit migrated from https://github.com/dotnet/corefx/commit/cae7c5116d46c0d98e6f0fb3526fa2a15945501a
This change modifies the build to consume the stable version where available.
This disables building the dowlevel packages since we shipped them once as stable and we're done.
From here on out, we'll only build the latest version (except for a servicing event, which would
be handled by syncing to a hash).
I can't rev the package versions in the normal way yet (by modifying the assembly version of the contents)
because that turned out to be too big of a problem to tackle in this change. Instead I added a
parameter to the task that calculates package versions to do the rev for anything that was
stable, but only when building the package itself, not when calculating the dependencies.
This has the downside of not permitting a dependency on a incremented pre-release version if we've
shipped a stable version, but that is a small point in time problem until I can rev the assembly
versions.
[tfs-changeset: 1508664]
Commit migrated from https://github.com/dotnet/corefx/commit/ee1ec2891c7c65b46fa9dfb078636be503bb2a60
Several projects are no longer loading correctly in VS for me. It's happening for projects and only for projects that contain a <ProjectTypeGuids/> node in the .csproj, related to portable libraries. These entries are unnecessary, and I'm simply deleting them, after which the projects load in VS successfully.
Commit migrated from https://github.com/dotnet/corefx/commit/6896000d173190ad945fac32834c2d30815d8a29
In my code review of @sokket's new FileSystemWatcher tests (dotnet/corefx#2347), I'd encouraged him to clean up some of the AutoResetEvents that were being created, in the name of good hygiene. But this introduces a sporadic failure in the tests due to a race condition.
The way that FileSystemWatcher is designed, stopping events on the instance doesn't actually prevent any in-progress operations from being processed, nor does stopping block until all in-process events have completed. As such, if after stopping processing we dispose of an event that's going to be set by one of the callbacks, it's possible such a set could occur from an in-flight operation after we've already disposed of the event, leading to an ObjectDisposedException that crashes the tests.
I contemplated adding synchronization to FSW itself to avoid these kinds of race conditions, e.g. by ensuring that the call to set "Enabled = false;" won't return until all in-progress operations have completed, but that could cause deadlocks not currently possible. As such, I simply stopped explicitly disposing of the events created in the tests, leaving the cleanup to finalization (as is already done for most other events in the tests).
Commit migrated from https://github.com/dotnet/corefx/commit/43bfad63384aee6eb7e20c064054c5e1cd00fbf0
Previously, System.IO.Path was implemented in mscorlib (with calls into Win32 on Windows / the Win32 PAL layer in libcoreclr on Unix) and type-forwarded from System.Runtime.Extensions. With dotnet/corefx#2234, we switched the Windows build to using System.IO.Path from System.Runtime.Extensions and Path.cs from corefx, but the Unix version was left still using the mscorlib implementation. One of the reasons for switching to the Path.cs in corefx, however, was to better enable a bunch of fixes to the behavior of the Unix implementation.
This change implements Path.cs in corefx for Unix and switches the Unix builds (Linux, OS X, and FreeBSD) over to using the implementation in corefx rather than type-forwarding to mscorlib.
Primary changes:
- Defined MaxPath / MaxComponent length in the Unix build in terms of pathconf
- Implemented the Unix build's NormalizePath to properly handle normalizing unnecessary "/", ".", and ".."s in the path.
- Implemented the Unix build's GetTempPath in terms of the TMPDIR environment variable (same logic that's in the Win32 PAL layer's implementation).
- Implemented the Unix build's GetTempFileName in terms of mkstemps.
- Implemented the Unix build's GetRandomFileName in terms of OpenSSL's RAND_pseudo_bytes, same as is done in System.Security.Cryptography.RandomNumberGenerator (which we can't reference due to layering).
- Centralized the wrapping of getcwd, which is now used from both System.Runtime.Extensions and System.IO.FileSystem. The previous usage of it always created a temporary array of size MaxPath, which can now be quite big, so the wrapper first tries to use stack space, and then graduates to retrying with larger and larger buffer sizes.
- Centralized the MaxPath and MaxName logic, which is now used by three libraries: System.Diagnostics.Process, System.IO.FileSystem, and now System.Runtime.Extensions.
- Centralized the throwing of PathTooLongException, as it now requires arguments for how long are the maximum path and component names.
- Cleaned up a few other minor things in the shared Path.cs (e.g. naming Boolean arguments) that were confusing me as I was working through the code.
- Added FreeBSD to the .sln and .csproj files, as otherwise the FreeBSD build for this library would be broken (previously it inherited the mscorlib implementation as did the other Unix OSes).
- Added a bunch of tests, some general across both Windows and Unix, but others specifically focused on Unix, which is more lenient than is Windows in the paths it allows.
Commit migrated from https://github.com/dotnet/corefx/commit/c4bc3bbfae8a9bf50defcfb8d6e13905f1209240
Nuget V3 has a graph walking optimization that chooses "nearest" reference.
The point of this is to avoid downloading the same package at multiple versions
and avoid rewalking graphs that will be superseded by a newer package.
As such it is a violation if a package references an older version of a package
than it pulls in transitively (a > b1 > c2, a > c1).
Nuget is in the process of adding warnings when this happens so we need to
clean up our dependencies to avoid those warnings out of the box.
[tfs-changeset: 1497671]
Commit migrated from https://github.com/dotnet/corefx/commit/ecb59b71b972c60ded7262791e3268a43bdcdf24
I tried to be clever in the calculation, but really we don't need to be very accurate so long as we can force the error. This is still not fool-proof as it seems a stressed system may drop/coalesce some of these events (perhaps because they are touching the same file & time) but it is close enough.
[tfs-changeset: 1493258]
Commit migrated from https://github.com/dotnet/corefx/commit/0c99692763e17c63f941fe7f52776ad27ae73232
Most test projects don't need unsafe code, but many were forced to allow unsafe blocks due to Interop.PlatformDetection.cs using pointers, and others were allowing it for no apparent reason. I've modified Interop.PlatformDetection.cs to not use unsafe code, and updated the relevant test projects accordingly. (Eventually we'll switch it over to using the new RuntimeInformation assembly, anyway.)
Commit migrated from https://github.com/dotnet/corefx/commit/3ae04f6ec948331c85c5f8441cd6d9eda868603f
Turns out my previous run of the OSX tests wasn't actually running all tests, due to my having an outdated xunit.netcore.extensions.dll and xunit silently not running some tests as a result.
@sokket is investigating. In the meantime, I'm disabling the rest of these on OSX.
Commit migrated from https://github.com/dotnet/corefx/commit/536cfc9118f029c3f91ab9739834b92b3728c8a6
Some of the project.json files were referencing xunit.netcore.extensions with ""1.0.0-prerelease" rather than "1.0.0-prerelease-*". As a result, I was unable to use more recent additions, like PlatformID.AnyUnix. This change just updates them to use the -* versions, and changes the few remaining places that were using PlatformID.Linux | PlatformID.OSX to instead use PlatformID.AnyUnix. The project.lock.json files were automatically updated by my building locally.
Commit migrated from https://github.com/dotnet/corefx/commit/f28722e261368de16adc2600fa1f1d3c0993ee8d
This change adds the lock files to repo to ensure we build against a stable set of dependencies. To explicitly update dependencies use build.cmd /T:RestorePackages /P:LockDependencies=true and this will pick up the latest depenedencies.
Existing projects adding new dependencies will automatically update the lock file incrementally.
New projects should make sure to check their lock file in with locked set to true.
[tfs-changeset: 1474296]
Commit migrated from https://github.com/dotnet/corefx/commit/d2fbc005707933db1cebca035d6cd6073af6cae4
Switch usage to new ThreadPoolBoundHandle API. This is relatively
straightforward, since this code didn't really do anything "tricky" like
re-use NativeOverlapped pointers.
Also, Enable overlapped operations in FileStream on N, now that they use
the supported API.
[tfs-changeset: 1474072]
Commit migrated from https://github.com/dotnet/corefx/commit/87270686b2e8d78953d1787422671faaf25eccb9
Latest packages are now on dotnet-core myget feed.
This should address a many of the warnings in the build. I will follow up with another change to address the rest.
This change brings in the latest build tools with updates to consume "latest" packages (* versions).
I've updated every project in the repo to use * versioning for dependencies.
The new packages can be used to resolve runtime assets as well (like clrcompression.dll) so I have removed the custom code in System.IO.Compression to copy this dll. Instead the test project references the actual System.IO.Compression package and sets the correct runtime IDs to pull out the resources. The System.IO.Compression.dll from the package is not used since the project reference takes precedence.
I had to workaround an issue in System.Xml.XmlSerializer with the current packages: System.Runtime.WindowsRuntime 4.0.0 has a depedendency on "windows" package which doesn't exist. This was caused by our auto-generation task not filtering the winrt reference in the reference assembly's surface area. I've fixed this in a separate change and we can remove the workaround once we have a new set of packages. https://github.com/dotnet/corefx/issues/1761
I also had to add a dependency to System.Security.Cryptography.Hashing.Algorithms\tests due to an issue with DNX. It's not honoring the dependency group with no targetFramework when another dependency group exists in the nuspec. This is inconsistent with nuget v2 and should be fixed in DNX. https://github.com/aspnet/dnx/issues/1881
[tfs-changeset: 1471885]
Commit migrated from https://github.com/dotnet/corefx/commit/08c0d8628ef621fbd44d7aaa85b3239616a6b108