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

[Bug]: ExitCode unavailable when autoremove set to true

Open xas opened this issue 6 months ago • 1 comments

Testcontainers version

3.9.0

Using the latest Testcontainers version?

Yes

Host OS

Linux

Host arch

WSL on Windows 11

.NET version

8.0

Docker version

Client:       Podman Engine
Version:      4.6.2
API Version:  4.6.2
Go Version:   go1.18.1
Built:        Thu Jan  1 01:00:00 1970
OS/Arch:      linux/amd64

Docker info

version:
  APIVersion: 4.6.2
  Built: 0
  BuiltTime: Thu Jan  1 01:00:00 1970
  GitCommit: ""
  GoVersion: go1.18.1
  Os: linux
  OsArch: linux/amd64
  Version: 4.6.2

What happened?

I have a simple console application that exits after 5 seconds with a specific exit code. Running on command line or with a podman run, I was able to get the right exit code.

But never with TestContainers. I always get a 0 exit code.

After a lot of tests, I was able to make it work. I just had to remove the parameter in the ContainerBuilder building code: .WithAutoRemove(true)

Is it normal ?

The cleaning is running too early ?

PS: RYUK is disabled

Relevant log output

No response

Additional information

Sample code:

using System;
using System.Threading;

Console.WriteLine("Hello, World!");

Console.WriteLine("--- Arguments ---");
foreach (string arg in args)
{
    Console.WriteLine(arg);
}

Console.WriteLine("--- Environment ---");
foreach (var arg in Environment.GetEnvironmentVariables())
{
    Console.WriteLine($"{arg}");
}

Environment.ExitCode = 11;

Thread.Sleep(5000);```

xas avatar Aug 28 '24 14:08 xas