Skip to content

Commit

Permalink
fix: Make sure container runs before reading output
Browse files Browse the repository at this point in the history
  • Loading branch information
HofmeisterAn committed Oct 28, 2024
1 parent 56b6fed commit fde3b4b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: CI
on:
pull_request:
branches:
- master
- main

jobs:
build:
Expand Down
18 changes: 5 additions & 13 deletions test/Docker.DotNet.Tests/IContainerOperationsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ await _dockerClient.Containers.StopContainerAsync(
[Fact]
public async Task GetContainerLogs_Tty_False_Follow_False_ReadsLogs()
{
using var containerLogsCts = new CancellationTokenSource(TimeSpan.FromSeconds(60));
var logList = new List<string>();

var createContainerResponse = await _dockerClient.Containers.CreateContainerAsync(
Expand All @@ -154,9 +153,7 @@ await _dockerClient.Containers.StartContainerAsync(
_cts.Token
);

containerLogsCts.CancelAfter(TimeSpan.FromSeconds(5));

var containerLogsTask = _dockerClient.Containers.GetContainerLogsAsync(
await _dockerClient.Containers.GetContainerLogsAsync(
createContainerResponse.ID,
new ContainerLogsParameters
{
Expand All @@ -165,7 +162,7 @@ await _dockerClient.Containers.StartContainerAsync(
Timestamps = true,
Follow = false
},
containerLogsCts.Token,
default,
new Progress<string>(m => { logList.Add(m); _output.WriteLine(m); })
);

Expand All @@ -175,7 +172,6 @@ await _dockerClient.Containers.StopContainerAsync(
_cts.Token
);

await containerLogsTask;
_output.WriteLine($"Line count: {logList.Count}");

Assert.NotEmpty(logList);
Expand All @@ -184,7 +180,6 @@ await _dockerClient.Containers.StopContainerAsync(
[Fact]
public async Task GetContainerLogs_Tty_True_Follow_False_ReadsLogs()
{
using var containerLogsCts = new CancellationTokenSource(TimeSpan.FromSeconds(60));
var logList = new List<string>();

var createContainerResponse = await _dockerClient.Containers.CreateContainerAsync(
Expand All @@ -203,9 +198,9 @@ await _dockerClient.Containers.StartContainerAsync(
_cts.Token
);

containerLogsCts.CancelAfter(TimeSpan.FromSeconds(5));
await Task.Delay(TimeSpan.FromSeconds(5));

var containerLogsTask = _dockerClient.Containers.GetContainerLogsAsync(
await _dockerClient.Containers.GetContainerLogsAsync(
createContainerResponse.ID,
new ContainerLogsParameters
{
Expand All @@ -214,19 +209,16 @@ await _dockerClient.Containers.StartContainerAsync(
Timestamps = true,
Follow = false
},
containerLogsCts.Token,
default,
new Progress<string>(m => { _output.WriteLine(m); logList.Add(m); })
);

await Task.Delay(TimeSpan.FromSeconds(5));

await _dockerClient.Containers.StopContainerAsync(
createContainerResponse.ID,
new ContainerStopParameters(),
_cts.Token
);

await containerLogsTask;
_output.WriteLine($"Line count: {logList.Count}");

Assert.NotEmpty(logList);
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// optional list of paths to consider when calculating version height.
],
"publicReleaseRefSpec": [
"^refs/heads/master$", // we release out of master
"^refs/heads/main$", // we release out of main
"^refs/tags/v\\d+\\.\\d+" // we also release tags starting with vN.N
],
"cloudBuild": {
Expand Down

0 comments on commit fde3b4b

Please sign in to comment.