Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable parallel test execution #404

Merged
merged 23 commits into from
Jul 12, 2018

Conversation

MattKotsenas
Copy link
Contributor

Enable test execution by fixing two classes of file locking problems:

  1. Improper use of IDisposable in the library
  2. Locked file streams by the tests themselves

Solving these problems generally had one of two solutions:

  1. Using the NonDisposingStream in additional places so types that were "borrowing" a stream could still follow the Dispose pattern without upsetting code analysis
  2. Changing tests to not take exclusive locks on original files

Lastly, the IsLocked check in TestBase had to be removed because it isn't parallel-test-execution-aware. Some of that gap is closed by the expanded test coverage in ReaderTests, though more is certainly welcome. I chose to stop here to avoid making the PR unmanageable.

Move the `TestStream` and `ForwardOnlyStream` to Mocks/ to separate them
from the test classes.
- Remove the duplicate `GC.SuppressFinalization` call
(called in `System.IO.Stream)
- Improve the `ThrowOnDispose` error message
Update the sub-stream classes to all inherit from `NonDisposingStream`.
This allows them to correctly implement the `Dispose` pattern, and delegate
the actual disposal to `NonDisposingStream`.

In doing so, we need to remove some redundant overrides from
`NonDisposingStream`, otherwise `BufferedSubStream` would use the
overrides inherited from `NonDisposingStream` instead of the ones
inherited from `Stream` (i.e. delegate `ReadByte` to `Read`).
`ArchiveFactory.Open` has two overloads that take `string` or
`FileInfo` (string delegates to FileInfo). Both of these implementations
open a `Stream` with the default `ReaderOptions`, which leaves the
stream open, resulting in a leak.

The fix is to set `LeaveOpen` to `false` if no options were provided.
Note that if a user was provding options and `LeaveOpen` was set to
`true`, the code did and will still leak.
The `IEnumerable<string>` version of `ReaderTests` is unused, so delete
it to simplify the code.
Update `RarHeaderFactoryTests` and `GZipArchiveTests` to open the test
readers as `FileAccess.Read` and `FileShare.Read` to prevent issues with
multiple test from trying to open exclusive access to files.
Refactor `ListeningStream`:

- Override of `WriteByte` was redundant and removed
- Make `Dispose` delegate to base class
`AppendingStream` is unused, so rather than refactor it, just delete it.
Update `Volume` and `ForwardOnlyStream` to follow the project's
general pattern and best-practices for `Dispose`
Refactor the `TestStream` constructor so by default it defers to
the underlying Stream
Update the `ReaderTests` base class to validate that `Dispose` is
called appropriately in both the close and the leave open cases.
Delete `NonSeekableStream` used in Zip64 tests in favor
of `ForwardOnlyStream` used in Mocks.

Additionally, delete the `ForwardOnlyStream.ReadByte` implementation
as the implementation on the base Stream is sufficient.
- Refactor `RarReaderTests` to use `ReaderFactory`
- Update `ReaderTests.Read` to support Rar tests
Refactor `TestSharpCompressWithEmptyStream` so it asserts that the files
and bytes are the same.
Now that the sources of file locking are fixed, enable test parallelization
and the forced garbage collection workaround.

Lastly, remove the `IsLocked` check because it doesn't work in a
parallel test running world - the file may be locked due to another test
running.
@MattKotsenas
Copy link
Contributor Author

Fixes #58

@MattKotsenas
Copy link
Contributor Author

Fixes #237

@MattKotsenas MattKotsenas changed the title Enabled parallel test execution Enable parallel test execution Jul 12, 2018
Copy link
Owner

@adamhathcock adamhathcock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great clean up. I've needed someone to give this a fresh pair of eyes forever. Thank you!

@adamhathcock adamhathcock merged commit bd96279 into adamhathcock:master Jul 12, 2018
@MattKotsenas MattKotsenas deleted the bugfix/idisposable branch July 12, 2018 19:51
@MattKotsenas
Copy link
Contributor Author

Thank you for your quick response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants