testcontainers-dotnet icon indicating copy to clipboard operation
testcontainers-dotnet copied to clipboard

[Bug]: Kafka tests fail randomly when run by GH actions

Open digital88 opened this issue 2 months ago • 1 comments

Testcontainers version

latest

Using the latest Testcontainers version?

Yes

Host OS

GH actions VM OS

Host arch

GH actions VM arch

.NET version

GH actions VM preinstalled NET SDK

Docker version

-

Docker info

-

What happened?

Based on GH actions run results in this PR Kafka tests seem to sometimes fail randomly.

Case 1: https://github.com/testcontainers/testcontainers-dotnet/pull/1584/checks?check_run_id=56729139285 Case 2: https://github.com/testcontainers/testcontainers-dotnet/pull/1584/checks?check_run_id=57187335689

See also this comment.

Relevant log output

https://github.com/testcontainers/testcontainers-dotnet/pull/1584/checks?check_run_id=56729139285
https://github.com/testcontainers/testcontainers-dotnet/pull/1584/checks?check_run_id=57187335689

Additional information

The tests themselves are passing without errors, but the test process hungs and is killed after timeout.

digital88 avatar Dec 06 '25 11:12 digital88

It looks like the two failed runs aren't related. As I mentioned in the PR, the best next step is to try reproducing the issue in GH Codespaces to see if we see it again.

The first one looks completely broken. For the other, the tests pass, but the test host process didn't finish.

Run: 56729139285
[xUnit.net 00:00:13.50]     Testcontainers.Kafka.KafkaContainerTest+KafkaDefaultConfiguration.ConsumerReturnsProducerMessage [FAIL]
[xUnit.net 00:00:13.52]     Testcontainers.Kafka.KafkaContainerTest+KafkaZooKeeperConfiguration.ConsumerReturnsProducerMessage [FAIL]
  Failed Testcontainers.Kafka.KafkaContainerTest+KafkaDefaultConfiguration.ConsumerReturnsProducerMessage [12 s]
  Error Message:
   DotNet.Testcontainers.Containers.ContainerNotRunningException : Container 345296ef82728204040f14546d28f761d0f8f0f589924dde2c813444f7abfce4 exited with code 1.
  Stdout: 
    2025-11-30T16:09:04.928204009Z ===> User
    2025-11-30T16:09:04.930552075Z uid=1000(appuser) gid=1000(appuser) groups=1000(appuser)
    2025-11-30T16:09:04.930975002Z ===> Configuring ...
  Stderr: 
    2025-11-30T16:09:04.923999848Z /testcontainers.sh: line 6: zookeeper-server-start: command not found
    2025-11-30T16:09:04.938975359Z Error: environment variable "KAFKA_PROCESS_ROLES" is not set
    2025-11-30T16:09:04.938986239Z Usage:
    2025-11-30T16:09:04.938989836Z   ub ensure <environment-variable> [flags]
    2025-11-30T16:09:04.938993112Z 
    2025-11-30T16:09:04.938995887Z Flags:
    2025-11-30T16:09:04.938998652Z   -h, --help   help for ensure
    2025-11-30T16:09:04.939001488Z 
    2025-11-30T16:09:04.968691456Z error in executing the command: environment variable "KAFKA_PROCESS_ROLES" is not set
  Stack Trace:
     at DotNet.Testcontainers.Containers.DockerContainer.ThrowIfContainerNotRunningAsync(WaitStrategyMode waitStrategyMode, Exception innerException) in /_/src/Testcontainers/Containers/DockerContainer.cs:line 737
   at DotNet.Testcontainers.Containers.DockerContainer.CheckReadinessAsync(WaitStrategy waitStrategy, CancellationToken ct) in /_/src/Testcontainers/Containers/DockerContainer.cs:line 690
   at DotNet.Testcontainers.Configurations.WaitStrategy.<>c__DisplayClass29_0.<<WaitUntilAsync>g__UntilAsync|0>d.MoveNext() in /_/src/Testcontainers/Configurations/WaitStrategies/WaitStrategy.cs:line 197
--- End of stack trace from previous location ---
   at DotNet.Testcontainers.Configurations.WaitStrategy.WaitUntilAsync(Func`1 wait, TimeSpan interval, TimeSpan timeout, Int32 retries, CancellationToken ct) in /_/src/Testcontainers/Configurations/WaitStrategies/WaitStrategy.cs:line 226
   at DotNet.Testcontainers.Containers.DockerContainer.CheckReadinessAsync(IEnumerable`1 waitStrategies, CancellationToken ct) in /_/src/Testcontainers/Containers/DockerContainer.cs:line 711
   at DotNet.Testcontainers.Containers.DockerContainer.UnsafeStartAsync(CancellationToken ct) in /_/src/Testcontainers/Containers/DockerContainer.cs:line 557
   at DotNet.Testcontainers.Containers.DockerContainer.StartAsync(CancellationToken ct) in /_/src/Testcontainers/Containers/DockerContainer.cs:line 340
   at Testcontainers.Kafka.KafkaContainerTest.InitializeAsync() in /home/runner/work/testcontainers-dotnet/testcontainers-dotnet/tests/Testcontainers.Kafka.Tests/KafkaContainerTest.cs:line 14
  Failed Testcontainers.Kafka.KafkaContainerTest+KafkaZooKeeperConfiguration.ConsumerReturnsProducerMessage [12 s]
  Error Message:
   DotNet.Testcontainers.Containers.ContainerNotRunningException : Container fd281d29b4fdc540c9081191ca84f193d44d6c5e911a83f4407dec06a44388e0 exited with code 1.
  Stdout: 
    2025-11-30T16:09:04.918445039Z ===> User
    2025-11-30T16:09:04.920693839Z uid=1000(appuser) gid=1000(appuser) groups=1000(appuser)
    2025-11-30T16:09:04.921011037Z ===> Configuring ...
  Stderr: 
    2025-11-30T16:09:04.915006716Z /testcontainers.sh: line 6: zookeeper-server-start: command not found
    2025-11-30T16:09:04.928692930Z Error: environment variable "KAFKA_PROCESS_ROLES" is not set
    2025-11-30T16:09:04.928748371Z Usage:
    2025-11-30T16:09:04.928755945Z   ub ensure <environment-variable> [flags]
    2025-11-30T16:09:04.928760013Z 
    2025-11-30T16:09:04.928763269Z Flags:
    2025-11-30T16:09:04.928766285Z   -h, --help   help for ensure
    2025-11-30T16:09:04.928769330Z 
    2025-11-30T16:09:04.960356141Z error in executing the command: environment variable "KAFKA_PROCESS_ROLES" is not set
  Stack Trace:
     at DotNet.Testcontainers.Containers.DockerContainer.ThrowIfContainerNotRunningAsync(WaitStrategyMode waitStrategyMode, Exception innerException) in /_/src/Testcontainers/Containers/DockerContainer.cs:line 737
   at DotNet.Testcontainers.Containers.DockerContainer.CheckReadinessAsync(WaitStrategy waitStrategy, CancellationToken ct) in /_/src/Testcontainers/Containers/DockerContainer.cs:line 690
   at DotNet.Testcontainers.Configurations.WaitStrategy.<>c__DisplayClass29_0.<<WaitUntilAsync>g__UntilAsync|0>d.MoveNext() in /_/src/Testcontainers/Configurations/WaitStrategies/WaitStrategy.cs:line 197
--- End of stack trace from previous location ---
   at DotNet.Testcontainers.Configurations.WaitStrategy.WaitUntilAsync(Func`1 wait, TimeSpan interval, TimeSpan timeout, Int32 retries, CancellationToken ct) in /_/src/Testcontainers/Configurations/WaitStrategies/WaitStrategy.cs:line 226
   at DotNet.Testcontainers.Containers.DockerContainer.CheckReadinessAsync(IEnumerable`1 waitStrategies, CancellationToken ct) in /_/src/Testcontainers/Containers/DockerContainer.cs:line 711
   at DotNet.Testcontainers.Containers.DockerContainer.UnsafeStartAsync(CancellationToken ct) in /_/src/Testcontainers/Containers/DockerContainer.cs:line 557
   at DotNet.Testcontainers.Containers.DockerContainer.StartAsync(CancellationToken ct) in /_/src/Testcontainers/Containers/DockerContainer.cs:line 340
   at Testcontainers.Kafka.KafkaContainerTest.InitializeAsync() in /home/runner/work/testcontainers-dotnet/testcontainers-dotnet/tests/Testcontainers.Kafka.Tests/KafkaContainerTest.cs:line 14

HofmeisterAn avatar Dec 06 '25 13:12 HofmeisterAn