Skip to content

Commit 7061abf

Browse files
committed
Increase retry timeout, print container logs on failure
Signed-off-by: Dom Del Nano <ddelnano@gmail.com>
1 parent 64a203e commit 7061abf

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/utils/testingutils/docker/elastic.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
package docker
2020

2121
import (
22+
"bytes"
2223
"fmt"
24+
"time"
2325

2426
"github.com/olivere/elastic/v7"
2527
"github.com/ory/dockertest/v3"
@@ -101,6 +103,9 @@ func SetupElastic() (*elastic.Client, func(), error) {
101103
return nil, cleanup, err
102104
}
103105

106+
// Increase retry timeout to 3 minutes (default is 1 minute)
107+
pool.MaxWait = 3 * time.Minute
108+
104109
clientPort := "9200"
105110
var client *elastic.Client
106111
err = pool.Retry(func() error {
@@ -113,6 +118,23 @@ func SetupElastic() (*elastic.Client, func(), error) {
113118
return err
114119
})
115120
if err != nil {
121+
// Dump container logs on failure for debugging
122+
var stdout, stderr bytes.Buffer
123+
logsErr := pool.Client.Logs(docker.LogsOptions{
124+
Container: resource.Container.ID,
125+
OutputStream: &stdout,
126+
ErrorStream: &stderr,
127+
Stdout: true,
128+
Stderr: true,
129+
Tail: "100",
130+
})
131+
if logsErr != nil {
132+
log.WithError(logsErr).Error("Failed to get container logs")
133+
} else {
134+
log.Errorf("Elasticsearch container stdout:\n%s", stdout.String())
135+
log.Errorf("Elasticsearch container stderr:\n%s", stderr.String())
136+
}
137+
116138
purgeErr := pool.Purge(resource)
117139
if purgeErr != nil {
118140
log.WithError(err).Error("Failed to purge pool")

0 commit comments

Comments
 (0)