Skip to content

Commit 0a7fe2e

Browse files
committed
Enable verbose logging of when a test starts and stops to see which test(s) freeze in GHA
1 parent 19585bf commit 0a7fe2e

File tree

7 files changed

+71
-22
lines changed

7 files changed

+71
-22
lines changed

.github/workflows/wf_build-and-test.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
run: ${{ github.workspace }}\.ci\windows\gha-setup.ps1
3636
- name: Test
3737
timeout-minutes: 25
38-
run: dotnet test ${{ github.workspace }}\Build.csproj --no-restore --no-build --logger 'console;verbosity=detailed'
38+
run: dotnet test ${{ github.workspace }}\Build.csproj --environment=RABBITMQ_CLIENT_TESTS_VERBOSE=true --no-restore --no-build --logger 'console;verbosity=detailed'
3939
- name: Check for errors in RabbitMQ logs
4040
run: ${{ github.workspace }}\.ci\windows\gha-log-check.ps1
4141
- name: Maybe upload RabbitMQ logs
@@ -63,7 +63,7 @@ jobs:
6363
run: ${{ github.workspace }}/.ci/ubuntu/cluster/gha-setup.sh
6464
- name: Test
6565
timeout-minutes: 25
66-
run: dotnet test ${{ github.workspace }}/Build.csproj --no-restore --no-build --logger "console;verbosity=detailed"
66+
run: dotnet test ${{ github.workspace }}/Build.csproj --environment=RABBITMQ_CLIENT_TESTS_VERBOSE=true --no-restore --no-build --logger "console;verbosity=detailed"
6767
- name: Check for errors in RabbitMQ logs
6868
run: ${{ github.workspace}}/.ci/ubuntu/cluster/gha-logs.sh check
6969
- name: Collect RabbitMQ logs (on failure)

Tests/Consumer/ConsumerPauseTests.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@
1313

1414
namespace Tests.Consumer;
1515

16-
public class ConsumerPauseTests(ITestOutputHelper testOutputHelper) : IntegrationTest(testOutputHelper), IDisposable
16+
public class ConsumerPauseTests(ITestOutputHelper testOutputHelper) : IntegrationTest(testOutputHelper)
1717
{
1818
private readonly HttpApiClient _httpApiClient = new();
1919

20-
public void Dispose() => _httpApiClient.Dispose();
20+
public override Task DisposeAsync()
21+
{
22+
_httpApiClient.Dispose();
23+
return base.DisposeAsync();
24+
}
2125

2226
[Fact]
2327
public async Task PauseShouldStopMessageArrivalUnpauseShouldResumeIt()

Tests/IntegrationTest.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,11 @@ public IntegrationTest(ITestOutputHelper testOutputHelper,
5050
_testDisplayName = InitTestDisplayName();
5151
_containerId = $"{_testDisplayName}:{Now}";
5252

53-
// TODO only if verbose
54-
// testOutputHelper.WriteLine($"Running test: {_testDisplayName}");
53+
if (SystemUtils.IsVerbose)
54+
{
55+
_testOutputHelper.WriteLine("{0} [DEBUG] [START] {1}", DateTime.Now, _testDisplayName);
56+
}
57+
5558
_connectionSettingBuilder = InitConnectionSettingsBuilder();
5659
}
5760

@@ -80,8 +83,11 @@ public virtual async Task InitializeAsync()
8083

8184
public virtual async Task DisposeAsync()
8285
{
83-
// TODO only if verbose
84-
// _testOutputHelper.WriteLine($"Disposing test: {_testDisplayName}");
86+
if (SystemUtils.IsVerbose)
87+
{
88+
_testOutputHelper.WriteLine("{0} [DEBUG] [END] {1}", DateTime.Now, _testDisplayName);
89+
}
90+
8591
if (_management is not null && _management.State == State.Open)
8692
{
8793
try

Tests/Recovery/CustomPublisherConsumerRecoveryTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313
namespace Tests.Recovery;
1414

15-
public class CustomPublisherConsumerRecoveryTests(ITestOutputHelper testOutputHelper) : IntegrationTest(testOutputHelper, false)
15+
public class CustomPublisherConsumerRecoveryTests(ITestOutputHelper testOutputHelper)
16+
: IntegrationTest(testOutputHelper, setupConnectionAndManagement: false)
1617
{
1718
/// <summary>
1819
/// The consumer and the publisher should not restart if the recovery is disabled

Tests/Rpc/RecoveryRPCTests.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// This source code is dual-licensed under the Apache License, version
2+
// 2.0, and the Mozilla Public License, version 2.0.
3+
// Copyright (c) 2017-2024 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
4+
15
using System;
26
using System.Threading;
37
using System.Threading.Tasks;
@@ -9,10 +13,14 @@
913
namespace Tests.Rpc
1014
{
1115
public class RecoveryRpcTests(ITestOutputHelper testOutputHelper)
16+
: IntegrationTest(testOutputHelper, setupConnectionAndManagement: false)
1217
{
1318
[Fact]
1419
public async Task RpcServerAndClientShouldRecoverAfterKillConnection()
1520
{
21+
Assert.Null(_connection);
22+
Assert.Null(_management);
23+
1624
string containerId = $"rpc-server-client-recovery-{DateTime.Now}";
1725
IConnection connection = await AmqpConnection.CreateAsync(ConnectionSettingBuilder.Create()
1826
.ContainerId(containerId).RecoveryConfiguration(RecoveryConfiguration.Create().Topology(true)).Build());
@@ -56,7 +64,7 @@ public async Task RpcServerAndClientShouldRecoverAfterKillConnection()
5664
}
5765
catch (Exception e)
5866
{
59-
testOutputHelper.WriteLine($"Error sending message: {e.Message}");
67+
_testOutputHelper.WriteLine($"Error sending message: {e.Message}");
6068
await Task.Delay(700);
6169
}
6270

Tests/SystemUtils.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111

1212
namespace Tests;
1313

14+
// TODO this could be merged into IntegrationTest
1415
public static class SystemUtils
1516
{
1617
const string DefaultRabbitMqHost = "localhost";
1718
private static readonly HttpApiClient s_httpApiClient = new();
1819
private static readonly string s_rabbitMqHost = InitRabbitMqHost();
1920
private static readonly bool s_isRunningInCI = InitIsRunningInCI();
21+
private static readonly bool s_isVerbose = InitIsVerbose();
2022
private static readonly bool s_isCluster;
2123
private static readonly ushort s_clusterSize;
2224
private static readonly TimeSpan s_initialDelaySpan = TimeSpan.FromMilliseconds(100);
@@ -25,6 +27,7 @@ public static class SystemUtils
2527

2628
public static string RabbitMqHost => s_rabbitMqHost;
2729
public static bool IsRunningInCI => s_isRunningInCI;
30+
public static bool IsVerbose => s_isVerbose;
2831
public static bool IsCluster => s_isCluster;
2932
public static ushort ClusterSize => s_clusterSize;
3033

@@ -307,4 +310,14 @@ private static bool InitIsRunningInCI()
307310

308311
return false;
309312
}
313+
314+
private static bool InitIsVerbose()
315+
{
316+
if (bool.TryParse(Environment.GetEnvironmentVariable("RABBITMQ_CLIENT_TESTS_VERBOSE"), out bool isVerbose))
317+
{
318+
return isVerbose;
319+
}
320+
321+
return false;
322+
}
310323
}

build.ps1

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
[CmdletBinding(PositionalBinding=$false)]
22
param(
3-
[switch]$RunTests
3+
[switch]$RunTests,
4+
[switch]$RunTestsUntilFailure
45
)
56

7+
New-Variable -Name verbose -Option Constant `
8+
-Value ($VerbosePreference -ne 'SilentlyContinue')
9+
610
$ErrorActionPreference = 'Stop'
711
Set-StrictMode -Version Latest
812
$PSNativeCommandUseErrorActionPreference = $true
@@ -18,17 +22,30 @@ New-Variable -Name build_csproj_file -Option Constant `
1822
-Value (Join-Path -Path $PSScriptRoot -ChildPath 'Build.csproj')
1923

2024
dotnet build $build_csproj_file
21-
Write-Host "Done building." -ForegroundColor "Green"
2225

23-
if ($RunTests) {
24-
Write-Host "Running tests: Build.csproj traversal (all frameworks)" -ForegroundColor "Magenta"
25-
dotnet test $build_csproj_file --no-build --logger 'console;verbosity=detailed'
26-
if ($LastExitCode -ne 0)
26+
Write-Host "[INFO] done building." -ForegroundColor "Green"
27+
28+
if ($RunTests -or $RunTestsUntilFailure)
29+
{
30+
Do
2731
{
28-
Write-Host "Error with tests, aborting build." -Foreground "Red"
29-
Exit 1
30-
}
31-
Write-Host "Tests passed!" -ForegroundColor "Green"
32+
Write-Host "Running tests: Build.csproj traversal (all frameworks)" -ForegroundColor "Magenta"
33+
if ($verbose)
34+
{
35+
dotnet test $build_csproj_file --environment=RABBITMQ_CLIENT_TESTS_VERBOSE=true --no-build --logger 'console;verbosity=detailed'
36+
}
37+
else
38+
{
39+
dotnet test $build_csproj_file --no-build --logger 'console;verbosity=detailed'
40+
}
41+
if ($LASTEXITCODE -ne 0)
42+
{
43+
Write-Host "[ERROR] tests errored, exiting" -Foreground "Red"
44+
Exit 1
45+
}
46+
else
47+
{
48+
Write-Host "[INFO] tests passed" -ForegroundColor "Green"
49+
}
50+
} While ($RunTestsUntilFailure)
3251
}
33-
34-
Write-Host "Done."

0 commit comments

Comments
 (0)