Skip to content

Commit

Permalink
separate sequential collections with delays
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerje committed Dec 14, 2024
1 parent cac43a8 commit 766fd40
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 29 deletions.
9 changes: 7 additions & 2 deletions src/Tests/Unit/ServiceWireTests/SequentialCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@

namespace ServiceWireTests
{
[CollectionDefinition("Sequential Collection", DisableParallelization = true)]
public class SequentialCollection
[CollectionDefinition("Sequential Collection Tcp", DisableParallelization = true)]
public class SequentialCollectionTcp
{
}

[CollectionDefinition("Sequential Collection TcpZk", DisableParallelization = true)]
public class SequentialCollectionTcpZk
{
}
}
22 changes: 19 additions & 3 deletions src/Tests/Unit/ServiceWireTests/TcpTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace ServiceWireTests
{
[Collection("Sequential Collection")]
[Collection("Sequential Collection Tcp")]
public class TcpTests : IDisposable
{
private INetTester _tester;
Expand All @@ -29,37 +29,42 @@ public TcpTests()
_tcphost = new TcpHost(CreateEndPoint());
_tcphost.AddService<INetTester>(_tester);
_tcphost.Open();

Task.Delay(500);
_clientProxy = new TcpClient<INetTester>(CreateEndPoint());
}

[Fact]
public void SimpleTest()
{
Task.Delay(500);
var rnd = new Random();

var a = rnd.Next(0, 100);
var b = rnd.Next(0, 100);

var result = _clientProxy.Proxy.Min(a, b);
Assert.Equal(Math.Min(a, b), result);
Task.Delay(500);
}

[Fact]
public async Task CalculateAsyncTest()
{
var rnd = new Random();
await Task.Delay(500);
var rnd = new Random();

var a = rnd.Next(0, 100);
var b = rnd.Next(0, 100);

var result = await _clientProxy.Proxy.CalculateAsync(a, b);
Assert.Equal(a + b, result);
await Task.Delay(500);
}

[Fact]
public void SimpleParallelTest()
{
Task.Delay(500);
var rnd = new Random();

Parallel.For(0, 4, (index, state) =>
Expand All @@ -74,12 +79,15 @@ public void SimpleParallelTest()
state.Break();
Assert.Equal(Math.Min(a, b), result);
}
Task.Delay(500);
});
Task.Delay(500);
}

[Fact]
public void ResponseTest()
{
Task.Delay(500);
const int count = 50;
const int start = 0;

Expand All @@ -91,11 +99,13 @@ public void ResponseTest()
Assert.True(result.TryGetValue(i, out temp));
Assert.Equal(i, temp);
}
Task.Delay(500);
}

[Fact]
public void ResponseParallelTest()
{
Task.Delay(500);
Parallel.For(0, 4, (index, state) =>
{
const int count = 50;
Expand All @@ -116,25 +126,31 @@ public void ResponseParallelTest()
Assert.True(false);
}
}
Task.Delay(500);
});
Task.Delay(500);
}

[Fact]
public void ResponseWithOutParameterTest()
{
Task.Delay(500);
int quantity = 0;
var result = _clientProxy.Proxy.Get(Guid.NewGuid(), "SomeLabel", 45.65, out quantity);
Assert.Equal(44, quantity);
Assert.NotEqual(default(TestResponse), result);
Assert.Equal("MyLabel", result.Label);
Task.Delay(500);
}

[Fact]
public void GetStringsTest()
{
Task.Delay(500);
var result = _clientProxy.Proxy.GetStrings();
Assert.Equal(4, result.Length);
Assert.Null(result[2]);
Task.Delay(500);
}


Expand Down
60 changes: 36 additions & 24 deletions src/Tests/Unit/ServiceWireTests/TcpZkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public ZkPasswordHash GetPasswordHashSet(string username)
}
}

[Collection("Sequential Collection")]
[Collection("Sequential Collection TcpZk")]
public class TcpZkTests : IDisposable
{
private INetTester _tester;
Expand Down Expand Up @@ -52,56 +52,64 @@ public TcpZkTests()
_tcphost = new TcpHost(CreateEndPoint(), zkRepository: _repo);
_tcphost.AddService<INetTester>(_tester);
_tcphost.Open();

Task.Delay(500);
_clientProxy = new TcpClient<INetTester>(CreateZkClientEndPoint());
}

[Fact]
public void SimpleZkTest()
{
Task.Delay(500);
var rnd = new Random();

var a = rnd.Next(0, 100);
var b = rnd.Next(0, 100);

var result = _clientProxy.Proxy.Min(a, b);
Assert.Equal<int>(Math.Min(a, b), result);
Task.Delay(500);
}

[Fact]
public async Task CalculateAsyncTest()
{
var rnd = new Random();
Task.Delay(500);

Check warning on line 76 in src/Tests/Unit/ServiceWireTests/TcpZkTests.cs

View workflow job for this annotation

GitHub Actions / build_linux

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.

Check warning on line 76 in src/Tests/Unit/ServiceWireTests/TcpZkTests.cs

View workflow job for this annotation

GitHub Actions / build_windows

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.
var rnd = new Random();

var a = rnd.Next(0, 100);
var b = rnd.Next(0, 100);

var result = await _clientProxy.Proxy.CalculateAsync(a, b);
Assert.Equal(a + b, result);
Task.Delay(500);

Check warning on line 84 in src/Tests/Unit/ServiceWireTests/TcpZkTests.cs

View workflow job for this annotation

GitHub Actions / build_linux

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.

Check warning on line 84 in src/Tests/Unit/ServiceWireTests/TcpZkTests.cs

View workflow job for this annotation

GitHub Actions / build_windows

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.
}

[Fact]
public void SimpleParallelZkTest()
{
Task.Delay(500);
var rnd = new Random();
Parallel.For(0, 12, (index, state) =>
{
var a = rnd.Next(0, 100);
var b = rnd.Next(0, 100);

var result = _clientProxy.Proxy.Min(a, b);
var result = _clientProxy.Proxy.Min(a, b);

if (Math.Min(a, b) != result)
{
state.Break();
Assert.Equal(Math.Min(a, b), result);
}
if (Math.Min(a, b) != result)
{
state.Break();
Assert.Equal(Math.Min(a, b), result);
}
Task.Delay(500);
});
Task.Delay(500);
}

[Fact]
public void ResponseZkTest()
{
Task.Delay(500);
const int count = 50;
const int start = 0;

Expand All @@ -119,34 +127,38 @@ public void ResponseZkTest()
Assert.True(false);
}
}
Task.Delay(500);
}

[Fact]
public void ResponseParallelTest()
{
Task.Delay(500);
Random rnd = new Random(DateTime.Now.Millisecond);
Parallel.For(0, 12, (index, state) =>
{
const int count = 50;
const int start = 0;
const int count = 50;
const int start = 0;

var result = _clientProxy.Proxy.Range(start, count);
var result = _clientProxy.Proxy.Range(start, count);

for (var i = start; i < count; i++)
for (var i = start; i < count; i++)
{
int temp;
if (result.TryGetValue(i, out temp))
{
if(i != temp) state.Break();
Assert.Equal(i, temp);
}
else
{
int temp;
if (result.TryGetValue(i, out temp))
{
if(i != temp) state.Break();
Assert.Equal(i, temp);
}
else
{
state.Break();
Assert.True(false);
}
state.Break();
Assert.True(false);
}
}
Task.Delay(500);
});
Task.Delay(500);
}

public void Dispose()
Expand Down

0 comments on commit 766fd40

Please sign in to comment.