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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6ae715b
Move the TestStream and ForwardOnlyStream to Mocks folder
MattKotsenas Jul 10, 2018
084c5e2
Rename StreamTests.cs --> LzmaStreamTests.cs
MattKotsenas Jul 10, 2018
a35c66e
Move RewindableStreamTest.cs to the Streams/ folder
MattKotsenas Jul 10, 2018
c2bf540
Close verification streams in TestBase.CompareArchivesByPath
MattKotsenas Jul 11, 2018
6c2e5e1
Cleanup NonDisposingStream for reuse
MattKotsenas Jul 11, 2018
cab1ce3
Update sub-streams to uniformly inherit from NonDisposingStream
MattKotsenas Jul 11, 2018
1652471
Fix Stream leak in ArchiveFactory
MattKotsenas Jul 11, 2018
4cd80e9
Simplify GZip bad compression test
MattKotsenas Jul 11, 2018
c6cf0d4
Simplify ReaderTests
MattKotsenas Jul 11, 2018
0473ec1
Open test archives as read
MattKotsenas Jul 11, 2018
ee4ae66
Refactor ListeningStream
MattKotsenas Jul 11, 2018
6d1d62f
Delete AppendingStream
MattKotsenas Jul 11, 2018
6c25322
Follow best-practices for Dispose in Volume and ForwardOnlyStream
MattKotsenas Jul 11, 2018
98558c5
Refactor TestStream constructor
MattKotsenas Jul 11, 2018
44dc36a
Update ReaderTests base class to validate Dispose
MattKotsenas Jul 11, 2018
7d20ba5
Simplify RarHeaderTests
MattKotsenas Jul 11, 2018
933ffe7
Remove unused code from ArchiveTests
MattKotsenas Jul 11, 2018
3c2f4eb
Combine ForwardOnlyStream and NonSeekableStream
MattKotsenas Jul 11, 2018
87a1440
Decouple UseReader from VerifyFiles
MattKotsenas Jul 11, 2018
e9a6fed
FIXUP decouple UseReader from VerifyFiles
MattKotsenas Jul 11, 2018
138038b
Move RarReaderTests over to user ReaderFactory
MattKotsenas Jul 12, 2018
93c0b91
Refactor TestSharpCompressWithEmptyStream
MattKotsenas Jul 12, 2018
f7ad595
Enable test parallelization and remove garbage collection workaround
MattKotsenas Jul 12, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/SharpCompress/Archives/ArchiveFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public static IWritableArchive Create(ArchiveType type)
public static IArchive Open(string filePath, ReaderOptions options = null)
{
filePath.CheckNotNullOrEmpty("filePath");
return Open(new FileInfo(filePath), options ?? new ReaderOptions());
return Open(new FileInfo(filePath), options);
}

/// <summary>
Expand All @@ -103,36 +103,31 @@ public static IArchive Open(string filePath, ReaderOptions options = null)
public static IArchive Open(FileInfo fileInfo, ReaderOptions options = null)
{
fileInfo.CheckNotNull("fileInfo");
options = options ?? new ReaderOptions();
options = options ?? new ReaderOptions { LeaveStreamOpen = false };
using (var stream = fileInfo.OpenRead())
{
if (ZipArchive.IsZipFile(stream, null))
{
stream.Dispose();
return ZipArchive.Open(fileInfo, options);
}
stream.Seek(0, SeekOrigin.Begin);
if (SevenZipArchive.IsSevenZipFile(stream))
{
stream.Dispose();
return SevenZipArchive.Open(fileInfo, options);
}
stream.Seek(0, SeekOrigin.Begin);
if (GZipArchive.IsGZipFile(stream))
{
stream.Dispose();
return GZipArchive.Open(fileInfo, options);
}
stream.Seek(0, SeekOrigin.Begin);
if (RarArchive.IsRarFile(stream, options))
{
stream.Dispose();
return RarArchive.Open(fileInfo, options);
}
stream.Seek(0, SeekOrigin.Begin);
if (TarArchive.IsTarFile(stream))
{
stream.Dispose();
return TarArchive.Open(fileInfo, options);
}
throw new InvalidOperationException("Cannot determine compressed stream type. Supported Archive Formats: Zip, GZip, Tar, Rar, 7Zip");
Expand Down
11 changes: 5 additions & 6 deletions src/SharpCompress/Common/Tar/TarReadOnlySubStream.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
using System;
using SharpCompress.IO;
using System;
using System.IO;

namespace SharpCompress.Common.Tar
{
internal class TarReadOnlySubStream : Stream
internal class TarReadOnlySubStream : NonDisposingStream
{
private bool _isDisposed;
private long _amountRead;

public TarReadOnlySubStream(Stream stream, long bytesToRead)
public TarReadOnlySubStream(Stream stream, long bytesToRead) : base(stream, throwOnDispose: false)
{
Stream = stream;
BytesLeftToRead = bytesToRead;
}

Expand All @@ -36,12 +36,11 @@ protected override void Dispose(bool disposing)
var buffer = new byte[skipBytes];
Stream.ReadFully(buffer);
}
base.Dispose(disposing);
}

private long BytesLeftToRead { get; set; }

public Stream Stream { get; }

public override bool CanRead => true;

public override bool CanSeek => false;
Expand Down
16 changes: 10 additions & 6 deletions src/SharpCompress/Common/Volume.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;
using SharpCompress.IO;
using SharpCompress.Readers;

Expand Down Expand Up @@ -33,15 +34,18 @@ internal Volume(Stream stream, ReaderOptions readerOptions)
/// </summary>
public virtual bool IsMultiVolume => true;

private bool _disposed;

public void Dispose()
protected virtual void Dispose(bool disposing)
{
if (!_disposed)
if (disposing)
{
_actualStream.Dispose();
_disposed = true;
}
}

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
}
}
74 changes: 0 additions & 74 deletions src/SharpCompress/IO/AppendingStream.cs

This file was deleted.

15 changes: 2 additions & 13 deletions src/SharpCompress/IO/BufferedSubStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,22 @@

namespace SharpCompress.IO
{
internal class BufferedSubStream : Stream
internal class BufferedSubStream : NonDisposingStream
{
private long position;
private int cacheOffset;
private int cacheLength;
private readonly byte[] cache;

public BufferedSubStream(Stream stream, long origin, long bytesToRead)
public BufferedSubStream(Stream stream, long origin, long bytesToRead) : base(stream, throwOnDispose: false)
{
Stream = stream;
position = origin;
BytesLeftToRead = bytesToRead;
cache = new byte[32 << 10];
}

protected override void Dispose(bool disposing)
{
if (disposing)
{
//Stream.Dispose();
}
}

private long BytesLeftToRead { get; set; }

public Stream Stream { get; }

public override bool CanRead => true;

public override bool CanSeek => false;
Expand Down
13 changes: 5 additions & 8 deletions src/SharpCompress/IO/CountingWritableSubStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@

namespace SharpCompress.IO
{
internal class CountingWritableSubStream : Stream
internal class CountingWritableSubStream : NonDisposingStream
{
private readonly Stream writableStream;

internal CountingWritableSubStream(Stream stream)
internal CountingWritableSubStream(Stream stream) : base(stream, throwOnDispose: false)
{
writableStream = stream;
}

public ulong Count { get; private set; }
Expand All @@ -22,7 +19,7 @@ internal CountingWritableSubStream(Stream stream)

public override void Flush()
{
writableStream.Flush();
Stream.Flush();
}

public override long Length => throw new NotSupportedException();
Expand All @@ -46,13 +43,13 @@ public override void SetLength(long value)

public override void Write(byte[] buffer, int offset, int count)
{
writableStream.Write(buffer, offset, count);
Stream.Write(buffer, offset, count);
Count += (uint)count;
}

public override void WriteByte(byte value)
{
writableStream.WriteByte(value);
Stream.WriteByte(value);
++Count;
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/SharpCompress/IO/ListeningStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ protected override void Dispose(bool disposing)
{
Stream.Dispose();
}
base.Dispose(disposing);
}

public Stream Stream { get; }
Expand Down Expand Up @@ -74,10 +75,5 @@ public override void Write(byte[] buffer, int offset, int count)
{
Stream.Write(buffer, offset, count);
}

public override void WriteByte(byte value)
{
Stream.WriteByte(value);
}
}
}
13 changes: 1 addition & 12 deletions src/SharpCompress/IO/NonDisposingStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ public NonDisposingStream(Stream stream, bool throwOnDispose = false)

protected override void Dispose(bool disposing)
{
GC.SuppressFinalize(this);
if (ThrowOnDispose)
{
throw new InvalidOperationException();
throw new InvalidOperationException($"Attempt to dispose of a {nameof(NonDisposingStream)} when {nameof(ThrowOnDispose)} is {ThrowOnDispose}");
}
}

Expand All @@ -44,11 +43,6 @@ public override int Read(byte[] buffer, int offset, int count)
return Stream.Read(buffer, offset, count);
}

public override int ReadByte()
{
return Stream.ReadByte();
}

public override long Seek(long offset, SeekOrigin origin)
{
return Stream.Seek(offset, origin);
Expand All @@ -63,10 +57,5 @@ public override void Write(byte[] buffer, int offset, int count)
{
Stream.Write(buffer, offset, count);
}

public override void WriteByte(byte value)
{
Stream.WriteByte(value);
}
}
}
2 changes: 1 addition & 1 deletion src/SharpCompress/IO/ReadOnlySubStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public ReadOnlySubStream(Stream stream, long bytesToRead)
}

public ReadOnlySubStream(Stream stream, long? origin, long bytesToRead)
: base(stream, false)
: base(stream, throwOnDispose: false)
{
if (origin != null)
{
Expand Down
Loading