Skip to content

Commit 4994996

Browse files
authored
Merge pull request #16 from devjoes/fix-ci-build-error
add timeout
2 parents eb9a4f1 + d93f373 commit 4994996

5 files changed

Lines changed: 12 additions & 4 deletions

File tree

DockerizedTesting.RabbitMQ/RabbitMqFixture.cs

100644100755
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public ConnectionFactory SetupConnectionFactory(ConnectionFactory connectionFact
5252
return connectionFactory;
5353
}
5454

55+
private int success = 0;
5556
protected override async Task<bool> IsContainerRunning(int[] ports)
5657
{
5758
try
@@ -68,10 +69,12 @@ protected override async Task<bool> IsContainerRunning(int[] ports)
6869

6970
}
7071
}
71-
return await Task.FromResult(true);
72+
this.success++;
73+
return await Task.FromResult(this.success >= 5); // Rabbit seems to work then stop?
7274
}
7375
catch
7476
{
77+
this.success = 0;
7578
return await Task.FromResult(false);
7679
}
7780
}

DockerizedTesting.RabbitMQ/RabbitMqFixtureOptions.cs

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace DockerizedTesting.RabbitMQ
66
public class RabbitMqFixtureOptions : FixtureOptions
77
{
88
public override IDockerImageProvider ImageProvider { get; } = new DockerHubImageProvider("bitnami/rabbitmq:latest");
9-
public override int DelayMs => 2000;
9+
public override int DelayMs => 5000;
1010
public string UserName { get; set; } = "user";
1111
public string Password { get; set; } = "D0cK3rIz3d_T3sting!!";
1212

DockerizedTesting.Tests/ImageProviders/DockerProjectImageProviderTests.cs

100644100755
File mode changed.

DockerizedTesting/Fixtures/BaseFixture.cs

100644100755
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,17 @@ protected async Task WaitForContainer(int[] ports)
4747
{
4848
this.ContainerStarted = false;
4949
int attempts = 0;
50+
var sw = System.Diagnostics.Stopwatch.StartNew();
5051
do
5152
{
5253
this.ContainerStarted = await this.IsContainerRunning(ports);
5354
await Task.Delay(this.Options.DelayMs);
5455
} while (!this.ContainerStarted && attempts++ <= this.Options.MaxRetries);
56+
sw.Stop();
57+
if (!this.ContainerStarted)
58+
{
59+
throw new TimeoutException($"Container failed to start after {sw.Elapsed} ({this.Options.MaxRetries} attempts)");
60+
}
5561
}
5662

5763
protected async Task<string> StartContainer(int[] ports)
@@ -71,7 +77,6 @@ public virtual async Task Start(T opts)
7177
this.ContainerStarting = true;
7278
this.ContainerId = await this.StartContainer(this.Ports);
7379
await this.WaitForContainer(this.Ports);
74-
this.ContainerStarted = true;
7580
}
7681

7782
public bool IsDisposed { get; protected set; }

Examples/ExampleDatabase.Tests/ExampleDatabase.Tests.csproj

100644100755
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>

0 commit comments

Comments
 (0)