Skip to content

PostgreSQL backup tool with Point-In-Time-Recovery and restore verification

TEST (backend): Log the container's state and output when the egress delay probe is refused, so the next Azurite flake shows whether it crashed

Rostislav Dugin6189ebb6e30e
diff --git a/backend/internal/util/testing/containers/netem.go b/backend/internal/util/testing/containers/netem.go
index e80dfb44..efadb885 100644
--- a/backend/internal/util/testing/containers/netem.go
+++ b/backend/internal/util/testing/containers/netem.go
@@ -32,6 +32,7 @@ func AddEgressDelay(t *testing.T, handle ContainerHandle, delay time.Duration) {
handshakeDuration, err := MeasureTcpHandshake(t, handle)
if err != nil {
+ logContainerStateAndOutputTail(t, handle.Container)
t.Fatalf("failed to dial the container after adding egress delay: %v", err)
}
@@ -78,6 +79,30 @@ func MeasureTcpHandshake(t *testing.T, handle ContainerHandle) (time.Duration, e
return handshakeDuration, nil
}
+// A refused dial to a container that passed its readiness check means its server went away, and
+// only the container's state and output say whether it crashed or was killed.
+func logContainerStateAndOutputTail(t *testing.T, target testcontainers.Container) {
+ t.Helper()
+
+ state, err := target.State(context.Background())
+ if err != nil {
+ t.Logf("failed to read container state: %v", err)
+ } else {
+ t.Logf(
+ "container status %s, exit code %d, OOM killed %t, error %q",
+ state.Status, state.ExitCode, state.OOMKilled, state.Error,
+ )
+ }
+
+ inspect, err := target.Inspect(context.Background())
+ if err != nil {
+ t.Logf("failed to inspect container: %v", err)
+ return
+ }
+
+ logContainerOutputTail(t, target, inspect.Config.Image)
+}
+
func getContainerAddress(t *testing.T, handle ContainerHandle) string {
t.Helper()