-
Notifications
You must be signed in to change notification settings - Fork 23
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
21 changed files
with
599 additions
and
192 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
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System.Threading.Channels; | ||
using Sally7.RequestExecutor; | ||
|
||
namespace Sally7.Tests.RequestExecutor; | ||
|
||
public class JobPoolTests | ||
{ | ||
[Fact] | ||
public async Task RentJobIdAsync_Throws_If_Disposed_And_Depleted() | ||
{ | ||
// Arrange | ||
var sut = new JobPool(1); | ||
sut.Dispose(); | ||
_ = await sut.RentJobIdAsync(CancellationToken.None); // Empty the pool | ||
|
||
// Act | ||
// Assert | ||
await Should.ThrowAsync<ChannelClosedException>(() => sut.RentJobIdAsync(CancellationToken.None).AsTask()); | ||
} | ||
|
||
[Fact] | ||
public async Task ReturnJobId_Does_Not_Throw_If_Disposed() | ||
{ | ||
// Arrange | ||
var sut = new JobPool(1); | ||
var jobId = await sut.RentJobIdAsync(CancellationToken.None); | ||
sut.Dispose(); | ||
|
||
// Act | ||
// Assert | ||
sut.ReturnJobId(jobId); | ||
} | ||
|
||
[Fact] | ||
public async Task Dispose_Calls_Dispose_On_Requests() | ||
{ | ||
// Arrange | ||
var sut = new JobPool(1); | ||
var jobId = await sut.RentJobIdAsync(CancellationToken.None); | ||
var request = sut.GetRequest(jobId); | ||
|
||
// Act | ||
sut.Dispose(); | ||
|
||
// Assert | ||
Should.Throw<ObjectDisposedException>(() => request.GetResult()); | ||
} | ||
} |
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,35 @@ | ||
using FakeItEasy; | ||
using Sally7.RequestExecutor; | ||
|
||
namespace Sally7.Tests.RequestExecutor; | ||
|
||
public class RequestTests | ||
{ | ||
[Fact] | ||
public void Completes_On_Dispose() | ||
{ | ||
// Arrange | ||
var sut = new Request(); | ||
var callback = A.Fake<Action>(); | ||
sut.OnCompleted(callback); | ||
|
||
// Act | ||
sut.Dispose(); | ||
|
||
// Assert | ||
A.CallTo(() => callback.Invoke()).MustHaveHappenedOnceExactly(); | ||
} | ||
|
||
[Fact] | ||
public async Task Throws_When_Awaited_After_Dispose() | ||
{ | ||
// Arrange | ||
var sut = new Request(); | ||
|
||
// Act | ||
sut.Dispose(); | ||
|
||
// Assert | ||
await Should.ThrowAsync<ObjectDisposedException>(async () => await sut); | ||
} | ||
} |
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,19 @@ | ||
using System.Threading.Channels; | ||
using Sally7.RequestExecutor; | ||
|
||
namespace Sally7.Tests.RequestExecutor; | ||
|
||
public class SignalTests | ||
{ | ||
[Fact] | ||
public async Task WaitAsync_Throws_If_Disposed() | ||
{ | ||
// Arrange | ||
var sut = new Signal(); | ||
sut.Dispose(); | ||
|
||
// Act | ||
// Assert | ||
await Should.ThrowAsync<ChannelClosedException>(() => sut.WaitAsync(CancellationToken.None).AsTask()); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,106 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Xunit; | ||
|
||
namespace Sally7.Tests; | ||
|
||
internal static class TestValues | ||
{ | ||
public static IEnumerable<byte> ByteData => | ||
Enumerable.Range(byte.MinValue, byte.MaxValue).Select(x => (byte)x); | ||
|
||
public static IEnumerable<sbyte> SByteData => | ||
Enumerable.Range(sbyte.MinValue, sbyte.MaxValue).Select(x => (sbyte)x); | ||
|
||
|
||
public static IEnumerable<short> Int16Data => ShortValues; | ||
|
||
public static IEnumerable<ushort> UInt16Data => | ||
ShortValues.Select(x => (ushort)x); | ||
|
||
public static IEnumerable<int> Int32Data => UIntValues.Select(x => (int)x); | ||
|
||
public static IEnumerable<uint> UInt32Data => UIntValues; | ||
|
||
public static IEnumerable<float> SingleData | ||
{ | ||
get | ||
{ | ||
float[] values = | ||
[ | ||
0, | ||
1, | ||
0.1f, | ||
123.45f, | ||
float.MinValue, | ||
float.MaxValue, | ||
]; | ||
|
||
return values; | ||
} | ||
} | ||
|
||
public static IEnumerable<long> Int64Data => ULongValues.Select(x => (long) x); | ||
|
||
public static IEnumerable<ulong> UInt64Data => ULongValues; | ||
|
||
public static IEnumerable<double> DoubleData | ||
{ | ||
get | ||
{ | ||
double[] values = | ||
[ | ||
0, | ||
1, | ||
0.1, | ||
123.45, | ||
0.0000001, | ||
(double) ulong.MaxValue * 33, | ||
double.MinValue, | ||
double.MaxValue, | ||
]; | ||
|
||
return values; | ||
} | ||
} | ||
|
||
private static readonly short[] ShortValues = | ||
[ | ||
0, | ||
1, | ||
123, | ||
12345, | ||
-1, | ||
-123, | ||
-12345, | ||
1 << 8, | ||
1 | 2 << 8, | ||
short.MinValue, | ||
short.MaxValue | ||
]; | ||
|
||
private static readonly uint[] UIntValues = | ||
[ | ||
uint.MinValue, | ||
uint.MaxValue, | ||
1, | ||
123, | ||
12345, | ||
1 << 8, | ||
1 << 16, | ||
1 << 24, | ||
1 | 2 << 8, | ||
1 | 2 << 8 | 3 << 16, | ||
1 | 2 << 8 | 3 << 24, | ||
1 | 2 << 8 | 3 << 16 | 4 << 24, | ||
0xf, | ||
0xf << 8, | ||
0xf << 16, | ||
0xf << 24, | ||
]; | ||
|
||
private static readonly ulong[] ULongValues = UIntValues.Select(x => (ulong)x) | ||
.SelectMany(x => new[] { x, x << 8, x << 16, x << 24, x << 32 }) | ||
.Concat(UIntValues.SelectMany(_ => UIntValues, (a, b) => (ulong)a << 32 | b)) | ||
.Concat(UIntValues.SelectMany(_ => UIntValues, (a, b) => a | (ulong)b << 32)).Distinct().ToArray(); | ||
} |
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,22 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using Xunit.Sdk; | ||
|
||
namespace Sally7.Tests; | ||
|
||
internal sealed class TestValuesDataAttribute : DataAttribute | ||
{ | ||
public override IEnumerable<object[]> GetData(MethodInfo testMethod) | ||
{ | ||
var paramType = testMethod.GetParameters()[0].ParameterType; | ||
var dataProperty = typeof(TestValues).GetProperty($"{paramType.Name}Data") ?? | ||
throw new ArgumentException($"No data available for type {paramType}"); | ||
|
||
var data = dataProperty.GetValue(null) as IEnumerable ?? | ||
throw new NotSupportedException($"Data from {dataProperty} could not be converted to {nameof(IEnumerable)}."); | ||
|
||
foreach (var value in data) yield return [value]; | ||
} | ||
} |
Oops, something went wrong.