Skip to content
This repository has been archived by the owner on Oct 4, 2023. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
Creating v5 of DevFast
  • Loading branch information
samaysar committed Sep 23, 2020
2 parents c75304c + a4a7924 commit ba3ca4d
Show file tree
Hide file tree
Showing 44 changed files with 1,578 additions and 441 deletions.
Binary file added Dot.Net.DevFast/spon_logo/jetbrains.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
<TargetFrameworks Condition="'$(LibraryFrameworks)'!=''">$(LibraryFrameworks)</TargetFrameworks>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp2.0'">
<DefineConstants>NETCOREAPP2_0;NETCORE</DefineConstants>
<UseNETCoreGenerator>true</UseNETCoreGenerator>
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<DefineConstants>NETCOREAPP3_1;NETCORE;NETHASHCRYPTO;NETASYNCDISPOSE</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<DefineConstants>NETCOREAPP3_1;NETCORE</DefineConstants>
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp2.0'">
<DefineConstants>NETCOREAPP2_0;NETCORE</DefineConstants>
<UseNETCoreGenerator>true</UseNETCoreGenerator>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'net461'">
<DefineConstants>NET461</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'net472'">
<DefineConstants>NET472</DefineConstants>
<DefineConstants>NET472;NETHASHCRYPTO</DefineConstants>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' != 'netcoreapp2.0'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ public void CreateDecompressionStream_Works_As_Expected(bool isgzip)
public void CreateKeyAndIv_Works_As_Expected()
{
var keyIv = TestValues.FixedCryptoPass.CreateKeyAndIv(TestValues.FixedCryptoSalt
#if NET472
#if NETHASHCRYPTO
, HashAlgorithmName.SHA1
#endif
);
Expand All @@ -369,7 +369,7 @@ public void CreateKeyAndIv_Works_As_Expected()
//proof of concept if future version changes values of default params
//lets say by mistake 10000 is changed to 1K
keyIv = TestValues.FixedCryptoPass.CreateKeyAndIv(TestValues.FixedCryptoSalt
#if NET472
#if NETHASHCRYPTO
, HashAlgorithmName.SHA1
#endif
, 32, 16, 1000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ await Pipe<object, object>.Execute(CancellationToken.None, ConcurrentBuffer.MinS
IdentityAwaitableAdapter<object>.Default, producers, consumers).ConfigureAwait(false);
foreach (var consumer in consumers)
{
#if !NETASYNCDISPOSE
consumer.Received(1).Dispose();
#else
await consumer.Received(1).DisposeAsync();
#endif
await consumer.Received(0)
.ConsumeAsync(Arg.Any<object>(), Arg.Any<CancellationToken>())
.ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ public async Task Post_Dispose_Or_TearDown_Call_Accept_Throws_DisposedError()
consumers[0] = Substitute.For<IConsumer<object>>();
var instance = new Pipeline<object, object>(consumers, IdentityAwaitableAdapter<object>.Default,
CancellationToken.None, 1);
#if NETASYNCDISPOSE
await using (instance.ConfigureAwait(false))
#else
using (instance)
#endif
{
}

Expand All @@ -32,31 +36,37 @@ public async Task Post_Dispose_Or_TearDown_Call_Accept_Throws_DisposedError()
}

[Test]
public void TryAdd_Returns_False_On_Timeout_When_Unable_To_Add_Item()
public async Task TryAdd_Returns_False_On_Timeout_When_Unable_To_Add_Item()
{
using (var handle = new ManualResetEventSlim(false))
{
using (var consumerhandle = new ManualResetEventSlim(false))
using (var consumerHandle = new ManualResetEventSlim(false))
{
var consumers = new IConsumer<object>[1];
consumers[0] = Substitute.For<IConsumer<object>>();
consumers[0].ConsumeAsync(Arg.Any<object>(), Arg.Any<CancellationToken>())
.Returns(x =>
{
consumerhandle.Set();
consumerHandle.Set();
handle.Wait();
return Task.CompletedTask;
});

using (var instance = new Pipeline<object, object>(consumers,
IdentityAwaitableAdapter<object>.Default, CancellationToken.None, 1))
var instance = new Pipeline<object, object>(consumers, IdentityAwaitableAdapter<object>.Default,
CancellationToken.None, 1);
#if NETASYNCDISPOSE
await using (instance.ConfigureAwait(false))
#else
using (instance)
#endif
{
instance.Add(new object(), CancellationToken.None); //this one will reach consumer
consumerhandle.Wait();
consumerHandle.Wait();
instance.Add(new object(), CancellationToken.None); //this one will stay in buffer
Assert.False(instance.TryAdd(new object(), 0, CancellationToken.None)); //this one we wont be able to add
handle.Set();
}

await Task.CompletedTask;
}
}
}
Expand All @@ -72,14 +82,23 @@ public async Task TearDown_Returns_Normally_When_No_Data_Is_Produced_N_Consumers
consumers[i] = Substitute.For<IConsumer<object>>();
}

using (var instance = new Pipeline<object, object>(consumers, IdentityAwaitableAdapter<object>.Default,
CancellationToken.None, 1))
var instance = new Pipeline<object, object>(consumers, IdentityAwaitableAdapter<object>.Default,
CancellationToken.None, 1);
#if NETASYNCDISPOSE
await using (instance.ConfigureAwait(false))
#else
using (instance)
#endif
{
await instance.TearDown().ConfigureAwait(false);
foreach (var consumer in consumers)
{
await consumer.Received(1).InitAsync().ConfigureAwait(false);
#if !NETASYNCDISPOSE
consumer.Received(1).Dispose();
#else
await consumer.Received(1).DisposeAsync();
#endif
await consumer.Received(0).ConsumeAsync(Arg.Any<object>(), Arg.Any<CancellationToken>())
.ConfigureAwait(false);
}
Expand All @@ -91,34 +110,46 @@ await consumer.Received(0).ConsumeAsync(Arg.Any<object>(), Arg.Any<CancellationT
[TestCase(2)]
public void When_Token_Is_Canceled_The_Consumers_Are_Disposed_Pipeline_Remains_Alive_But_Accept_Throws_OpCancelErr(int cc)
{
Assert.True(Assert.ThrowsAsync<AggregateException>(async () =>
Assert.ThrowsAsync<OperationCanceledException>(async () =>
{
var countdownHandle = new CountdownEvent(cc);
var consumers = new IConsumer<object>[cc];
for (var i = 0; i < cc; i++)
{
consumers[i] = Substitute.For<IConsumer<object>>();
#if !NETASYNCDISPOSE
consumers[i].When(x => x.Dispose()).Do(x => countdownHandle.Signal());
#else
consumers[i].DisposeAsync().Returns(x =>
{
countdownHandle.Signal();
return default;
});
#endif
}

var cts = new CancellationTokenSource();
var instance = new Pipeline<object, object>(consumers, IdentityAwaitableAdapter<object>.Default,
cts.Token, 1);
cts.Cancel();
//we wait before checking received calls...! it means our dispose counts are correct!
countdownHandle.Wait(CancellationToken.None);
foreach (var consumer in consumers)
{
await consumer.Received(1).InitAsync().ConfigureAwait(false);
await consumer.Received(0).ConsumeAsync(Arg.Any<object>(), Arg.Any<CancellationToken>())
.ConfigureAwait(false);
}
Assert.Throws<OperationCanceledException>(() => instance.Add(new object(), CancellationToken.None));

#if NETASYNCDISPOSE
await using (instance.ConfigureAwait(false))
#else
using (instance)
#endif
{
cts.Cancel();
//we wait before checking received calls...! it means our dispose counts are correct!
countdownHandle.Wait(CancellationToken.None);
foreach (var consumer in consumers)
{
await consumer.Received(1).InitAsync().ConfigureAwait(false);
await consumer.Received(0).ConsumeAsync(Arg.Any<object>(), Arg.Any<CancellationToken>())
.ConfigureAwait(false);
}

Assert.Throws<OperationCanceledException>(() => instance.Add(new object(), CancellationToken.None));
}
}).InnerExceptions[0] is TaskCanceledException);
});
//task cancel error is thrown due to TearDown call!
}

Expand All @@ -129,8 +160,13 @@ public async Task Objects_Are_Properly_Passed_To_Consumers_With_Adapter()
var consumers = new IConsumer<List<object>>[1];
consumers[0] = Substitute.For<IConsumer<List<object>>>();

using (var instance = new Pipeline<object, List<object>>(consumers,
new IdentityAwaitableListAdapter<object>(2, 0), CancellationToken.None, 1))
var instance = new Pipeline<object, List<object>>(consumers,
new IdentityAwaitableListAdapter<object>(2, 0), CancellationToken.None, 1);
#if NETASYNCDISPOSE
await using (instance.ConfigureAwait(false))
#else
using (instance)
#endif
{
Assert.True(instance.UnconsumedCount == 0);
instance.Add(new object(), CancellationToken.None);
Expand All @@ -144,7 +180,11 @@ public async Task Objects_Are_Properly_Passed_To_Consumers_With_Adapter()
await consumer.Received(1).InitAsync().ConfigureAwait(false);
await consumer.Received(1).ConsumeAsync(Arg.Any<List<object>>(), Arg.Any<CancellationToken>())
.ConfigureAwait(false);
#if !NETASYNCDISPOSE
consumer.Received(1).Dispose();
#else
await consumer.Received(1).DisposeAsync();
#endif
}
}
}
Expand Down
Loading

0 comments on commit ba3ca4d

Please sign in to comment.