This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
230 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
//------------------------------------------------------------ | ||
|
||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: InternalsVisibleTo("System.IO.Pipelines.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010015c01ae1f50e8cc09ba9eac9147cf8fd9fce2cfe9f8dce4f7301c4132ca9fb50ce8cbf1df4dc18dd4d210e4345c744ecb3365ed327efdbc52603faa5e21daa11234c8c4a73e51f03bf192544581ebe107adee3a34928e39d04e524a9ce729d5090bfd7dad9d10c722c0def9ccc08ff0a03790e48bcd1f9b6c476063e1966a1c4")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,102 +1,102 @@ | ||
//// Licensed to the .NET Foundation under one or more agreements. | ||
//// The .NET Foundation licenses this file to you under the MIT license. | ||
//// See the LICENSE file in the project root for more information. | ||
|
||
//using Xunit; | ||
|
||
//namespace System.IO.Pipelines.Tests | ||
//{ | ||
// public class PipeLengthTests : IDisposable | ||
// { | ||
// public PipeLengthTests() | ||
// { | ||
// _pool = new TestMemoryPool(); | ||
// _pipe = new Pipe(new PipeOptions(_pool)); | ||
// } | ||
|
||
// public void Dispose() | ||
// { | ||
// _pipe.Writer.Complete(); | ||
// _pipe.Reader.Complete(); | ||
// _pool?.Dispose(); | ||
// } | ||
|
||
// private readonly TestMemoryPool _pool; | ||
|
||
// private readonly Pipe _pipe; | ||
|
||
// [Fact] | ||
// public void ByteByByteTest() | ||
// { | ||
// for (var i = 1; i <= 1024 * 1024; i++) | ||
// { | ||
// _pipe.Writer.GetMemory(100); | ||
// _pipe.Writer.Advance(1); | ||
// _pipe.Writer.Commit(); | ||
|
||
// Assert.Equal(i, _pipe.Length); | ||
// } | ||
|
||
// _pipe.Writer.FlushAsync(); | ||
|
||
// for (int i = 1024 * 1024 - 1; i >= 0; i--) | ||
// { | ||
// ReadResult result = _pipe.Reader.ReadAsync().GetResult(); | ||
// SequencePosition consumed = result.Buffer.Slice(1).Start; | ||
|
||
// Assert.Equal(i + 1, result.Buffer.Length); | ||
|
||
// _pipe.Reader.AdvanceTo(consumed, consumed); | ||
|
||
// Assert.Equal(i, _pipe.Length); | ||
// } | ||
// } | ||
|
||
// [Fact] | ||
// public void LengthCorrectAfterAlloc0AdvanceCommit() | ||
// { | ||
// _pipe.Writer.GetMemory(0); | ||
// _pipe.Writer.WriteEmpty(10); | ||
// _pipe.Writer.Commit(); | ||
|
||
// Assert.Equal(10, _pipe.Length); | ||
// } | ||
|
||
// [Fact] | ||
// public void LengthCorrectAfterAllocAdvanceCommit() | ||
// { | ||
// PipeWriter writableBuffer = _pipe.Writer.WriteEmpty(10); | ||
// writableBuffer.Commit(); | ||
|
||
// Assert.Equal(10, _pipe.Length); | ||
// } | ||
|
||
// [Fact] | ||
// public void LengthDecreasedAfterReadAdvanceConsume() | ||
// { | ||
// _pipe.Writer.GetMemory(100); | ||
// _pipe.Writer.Advance(10); | ||
// _pipe.Writer.Commit(); | ||
// _pipe.Writer.FlushAsync(); | ||
|
||
// ReadResult result = _pipe.Reader.ReadAsync().GetResult(); | ||
// SequencePosition consumed = result.Buffer.Slice(5).Start; | ||
// _pipe.Reader.AdvanceTo(consumed, consumed); | ||
|
||
// Assert.Equal(5, _pipe.Length); | ||
// } | ||
|
||
// [Fact] | ||
// public void LengthNotChangeAfterReadAdvanceExamine() | ||
// { | ||
// PipeWriter writableBuffer = _pipe.Writer.WriteEmpty(10); | ||
// writableBuffer.Commit(); | ||
// writableBuffer.FlushAsync(); | ||
|
||
// ReadResult result = _pipe.Reader.ReadAsync().GetResult(); | ||
// _pipe.Reader.AdvanceTo(result.Buffer.Start, result.Buffer.End); | ||
|
||
// Assert.Equal(10, _pipe.Length); | ||
// } | ||
// } | ||
//} | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using Xunit; | ||
|
||
namespace System.IO.Pipelines.Tests | ||
{ | ||
public class PipeLengthTests : IDisposable | ||
{ | ||
public PipeLengthTests() | ||
{ | ||
_pool = new TestMemoryPool(); | ||
_pipe = new Pipe(new PipeOptions(_pool)); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_pipe.Writer.Complete(); | ||
_pipe.Reader.Complete(); | ||
_pool?.Dispose(); | ||
} | ||
|
||
private readonly TestMemoryPool _pool; | ||
|
||
private readonly Pipe _pipe; | ||
|
||
[Fact] | ||
public void ByteByByteTest() | ||
{ | ||
for (var i = 1; i <= 1024 * 1024; i++) | ||
{ | ||
_pipe.Writer.GetMemory(100); | ||
_pipe.Writer.Advance(1); | ||
_pipe.Writer.Commit(); | ||
|
||
Assert.Equal(i, _pipe.Length); | ||
} | ||
|
||
_pipe.Writer.FlushAsync(); | ||
|
||
for (int i = 1024 * 1024 - 1; i >= 0; i--) | ||
{ | ||
ReadResult result = _pipe.Reader.ReadAsync().GetResult(); | ||
SequencePosition consumed = result.Buffer.Slice(1).Start; | ||
|
||
Assert.Equal(i + 1, result.Buffer.Length); | ||
|
||
_pipe.Reader.AdvanceTo(consumed, consumed); | ||
|
||
Assert.Equal(i, _pipe.Length); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void LengthCorrectAfterAlloc0AdvanceCommit() | ||
{ | ||
_pipe.Writer.GetMemory(0); | ||
_pipe.Writer.WriteEmpty(10); | ||
_pipe.Writer.Commit(); | ||
|
||
Assert.Equal(10, _pipe.Length); | ||
} | ||
|
||
[Fact] | ||
public void LengthCorrectAfterAllocAdvanceCommit() | ||
{ | ||
PipeWriter writableBuffer = _pipe.Writer.WriteEmpty(10); | ||
writableBuffer.Commit(); | ||
|
||
Assert.Equal(10, _pipe.Length); | ||
} | ||
|
||
[Fact] | ||
public void LengthDecreasedAfterReadAdvanceConsume() | ||
{ | ||
_pipe.Writer.GetMemory(100); | ||
_pipe.Writer.Advance(10); | ||
_pipe.Writer.Commit(); | ||
_pipe.Writer.FlushAsync(); | ||
|
||
ReadResult result = _pipe.Reader.ReadAsync().GetResult(); | ||
SequencePosition consumed = result.Buffer.Slice(5).Start; | ||
_pipe.Reader.AdvanceTo(consumed, consumed); | ||
|
||
Assert.Equal(5, _pipe.Length); | ||
} | ||
|
||
[Fact] | ||
public void LengthNotChangeAfterReadAdvanceExamine() | ||
{ | ||
PipeWriter writableBuffer = _pipe.Writer.WriteEmpty(10); | ||
writableBuffer.Commit(); | ||
writableBuffer.FlushAsync(); | ||
|
||
ReadResult result = _pipe.Reader.ReadAsync().GetResult(); | ||
_pipe.Reader.AdvanceTo(result.Buffer.Start, result.Buffer.End); | ||
|
||
Assert.Equal(10, _pipe.Length); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.