Skip to content

Commit fbfc045

Browse files
Test passes locally but not in GitHub Actions - switch to using FluentAssertions to give more visibility of failure reasons. Also increase the wait time in case remote service is slower than a local computer.
1 parent c4d7a2b commit fbfc045

2 files changed

Lines changed: 13 additions & 16 deletions

File tree

DockerComposeFixture.Tests/DockerComposeFixture.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11+
<PackageReference Include="FluentAssertions" Version="6.12.0" />
1112
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
1213
<PackageReference Include="xunit" Version="2.9.0" />
1314
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">

DockerComposeFixture.Tests/Logging/LoggerTests.cs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.IO;
43
using System.Linq;
5-
using System.Text;
64
using System.Threading;
75
using System.Threading.Tasks;
86
using DockerComposeFixture.Logging;
97
using DockerComposeFixture.Tests.Utils;
8+
using FluentAssertions;
109
using Xunit;
11-
using Xunit.Abstractions;
1210

1311
namespace DockerComposeFixture.Tests.Logging
1412
{
1513
public class LoggerTests
1614
{
17-
public LoggerTests()
18-
{
19-
}
20-
2115
[Fact]
22-
public void OnNext_LogsItemsToFile_WhenCalled()
16+
public async Task OnNext_LogsItemsToFile_WhenCalled()
2317
{
24-
string tmpFile = Path.GetTempFileName();
18+
var tmpFile = Path.GetTempFileName();
19+
2520
int GetFileLineCount(string file)
2621
{
2722
using (var fs = new FileStream(file, FileMode.OpenOrCreate, FileAccess.Read, FileShare.Write))
@@ -40,16 +35,17 @@ int GetFileLineCount(string file)
4035
counter.Subscribe(logger);
4136
}
4237

43-
var task = new Task(() => counter.Count());
38+
var task = new Task(() => counter.Count(delay: 10));
4439

4540
task.Start();
46-
Thread.Sleep(30);
47-
Assert.True(GetFileLineCount(tmpFile) > 0);
48-
Assert.True(GetFileLineCount(tmpFile) < 10);
49-
task.Wait();
50-
Assert.Equal(10, GetFileLineCount(tmpFile));
41+
Thread.Sleep(50);
42+
var fileLineCount = GetFileLineCount(tmpFile);
43+
fileLineCount.Should().BeInRange(1, 9);
44+
await task;
45+
fileLineCount = GetFileLineCount(tmpFile);
46+
fileLineCount.Should().Be(10);
5147
var lines = File.ReadAllLines(tmpFile);
52-
Assert.Equal("1,2,3,4,5,6,7,8,9,10".Split(","), lines);
48+
lines.Should().BeEquivalentTo("1,2,3,4,5,6,7,8,9,10".Split(","));
5349
File.Delete(tmpFile);
5450
}
5551
}

0 commit comments

Comments
 (0)