Skip to content

Commit ff118d5

Browse files
authored
Merge pull request #13 from devjoes/big-refactor-fix-parallelization-bug
Big refactor fix parallelization bug
2 parents 09bebf9 + de5d8dd commit ff118d5

43 files changed

Lines changed: 1001 additions & 297 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

DockerizedTesting.Kafka.Tests/DockerizedTesting.Kafka.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.1</TargetFramework>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
55

66
<IsPackable>false</IsPackable>
77
</PropertyGroup>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"parallelizeAssembly": true
3+
}

DockerizedTesting.Mongo.Tests/DockerizedTesting.Mongo.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.1</TargetFramework>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
55

66
<IsPackable>false</IsPackable>
77

DockerizedTesting.Mongo.Tests/MongoFixtureTests.cs

Lines changed: 29 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Linq;
33
using System.Reflection;
44
using System.Threading.Tasks;
5+
using DockerizedTesting.Containers;
56
using MongoDB.Driver;
67
using Xunit;
78

@@ -52,35 +53,34 @@ public async Task DisposeKillsMongo()
5253
Assert.True(ex.InnerException is MongoConnectionException || ex.InnerException is TimeoutException);
5354
}
5455

55-
[Fact]
56-
public async Task ContainersAreRemovedOnShutdown()
57-
{
58-
int rnd = new Random().Next(10000,12000-1);
59-
async Task<string> StartStopContainer()
60-
{
61-
var fixture = new MongoFixture();
62-
var options = new MongoFixtureOptionsWithOwnHost();
63-
options.ContainerHost.RemoveContainersOnExit = true;
64-
// This ensures that the container will be unique and not being used by a diff test.
65-
fixture.Ports[0] = rnd;
66-
await fixture.Start(options);
67-
Assert.True(fixture.ContainerStarting);
68-
Assert.True(fixture.ContainerStarted);
69-
string id = fixture.ContainerId;
70-
await Task.Delay(1000);
71-
fixture.Dispose();
72-
await Task.Delay(1000);
73-
options.ContainerHost.Dispose();
74-
await Task.Delay(1000);
75-
return id;
76-
}
77-
78-
var id1 = await StartStopContainer();
79-
await Task.Delay(5000);
80-
var id2 = await StartStopContainer();
81-
82-
Assert.NotEqual(id1,id2);
83-
}
56+
//[Fact]
57+
//public async Task ContainersAreRemovedOnShutdown()
58+
//{
59+
// int rnd = new Random().Next(10000,12000-1);
60+
// async Task<string> StartStopContainer()
61+
// {
62+
// var fixture = new MongoFixture();
63+
// var options = new MongoFixtureOptionsWithOwnHost();
64+
// // This ensures that the container will be unique and not being used by a diff test.
65+
// fixture.Ports[0] = rnd;
66+
// await fixture.Start(options);
67+
// Assert.True(fixture.ContainerStarting);
68+
// Assert.True(fixture.ContainerStarted);
69+
// string id = fixture.ContainerId;
70+
// await Task.Delay(1000);
71+
// fixture.Dispose();
72+
// await Task.Delay(1000);
73+
// options.ContainerHost.Dispose();
74+
// await Task.Delay(1000);
75+
// return id;
76+
// }
77+
78+
// var id1 = await StartStopContainer();
79+
// await Task.Delay(5000);
80+
// var id2 = await StartStopContainer();
81+
82+
// Assert.NotEqual(id1,id2);
83+
//}
8484

8585
[Fact]
8686
public async Task ThreadSafetyTest() =>
@@ -105,17 +105,6 @@ public class Foo
105105
public int Bar { get; set; }
106106
}
107107

108-
public class MongoFixtureOptionsWithOwnHost:MongoFixtureOptions
109-
{
110-
public MongoFixtureOptionsWithOwnHost()
111-
{
112-
var ctor = typeof(ContainerHost).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance,
113-
null, new Type[0],
114-
null);
115-
this.ContainerHost = (IContainerHost) ctor.Invoke(null);
116-
}
117-
public override IContainerHost ContainerHost { get; }
118-
}
119108
}
120109

121110
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"parallelizeAssembly": true
3+
}

DockerizedTesting.MsSql.Tests/DockerizedTesting.MsSql.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.0</TargetFramework>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
55

66
<IsPackable>false</IsPackable>
77
</PropertyGroup>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"parallelizeAssembly": true
3+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
6+
<IsPackable>false</IsPackable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
11+
<PackageReference Include="xunit" Version="2.4.0" />
12+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
13+
<PackageReference Include="coverlet.collector" Version="1.0.1" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<ProjectReference Include="..\DockerizedTesting.RabbitMQ\DockerizedTesting.RabbitMQ.csproj" />
18+
</ItemGroup>
19+
20+
</Project>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using System.Text;
3+
using System.Threading.Tasks;
4+
using RabbitMQ.Client;
5+
using Xunit;
6+
7+
namespace DockerizedTesting.RabbitMQ.Tests
8+
{
9+
public class RabbitMqFixtureTests : IClassFixture<RabbitMqFixture>
10+
{
11+
private readonly RabbitMqFixture fixture;
12+
13+
public RabbitMqFixtureTests(RabbitMqFixture fixture)
14+
{
15+
fixture.Start().Wait();
16+
this.fixture = fixture;
17+
}
18+
19+
[Fact]
20+
public void RabbitIsReachable()
21+
{
22+
var factory = this.fixture.SetupConnectionFactory(new ConnectionFactory());
23+
using (var connection = factory.CreateConnection())
24+
{
25+
using (var channel = connection.CreateModel())
26+
{
27+
channel.QueueDeclare(queue: "hello",
28+
durable: false,
29+
exclusive: false,
30+
autoDelete: false,
31+
arguments: null);
32+
33+
string message = "Hello World!";
34+
var body = Encoding.UTF8.GetBytes(message);
35+
36+
channel.BasicPublish(exchange: "",
37+
routingKey: "hello",
38+
basicProperties: null,
39+
body: body);
40+
}
41+
}
42+
}
43+
}
44+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
6+
<Authors>Joe Shearn</Authors>
7+
<Description>A fixture for XUnit that start up a rabbit queue to test your code with. Whilst it was built for XUnit it should be framework agnostic.</Description>
8+
<PackageLicenseFile>license.txt</PackageLicenseFile>
9+
<PackageProjectUrl>https://github.com/devjoes/DockerizedTesting</PackageProjectUrl>
10+
<RepositoryUrl>https://github.com/devjoes/DockerizedTesting</RepositoryUrl>
11+
<PackageTags>docker rabbitmq rabbit unittesting testing</PackageTags>
12+
</PropertyGroup>
13+
14+
<ItemGroup>
15+
<PackageReference Include="RabbitMQ.Client" Version="6.0.0" />
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<ProjectReference Include="..\DockerizedTesting\DockerizedTesting.csproj" />
20+
</ItemGroup>
21+
22+
<ItemGroup>
23+
<None Include="..\DockerizedTesting.Mongo\license.txt">
24+
<Pack>True</Pack>
25+
<PackagePath></PackagePath>
26+
</None>
27+
</ItemGroup>
28+
29+
</Project>

0 commit comments

Comments
 (0)