Skip to content

Commit

Permalink
chore(test): Update Minio config in tests (#965)
Browse files Browse the repository at this point in the history
The blob store tests have started failing because the new release of
Minio container is checking the data directory for IO-DIRECT access.
Switching to the default `/data` directory seems to fix this issue.

In addition, the healthcheck should be using the readiness probe instead
of the liveness probe because sometimes the server is not yet ready to
accept connections even if it is up.

Also reduces the parallelism in E2E test runs because lately they have
been failing -- possibly due to resource contention.

Signed-off-by: Charith Ellawala <charith@cerbos.dev>
  • Loading branch information
charithe committed Jun 2, 2022
1 parent 065aa68 commit 3fa5b03
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 14 deletions.
4 changes: 2 additions & 2 deletions e2e/run.sh
Expand Up @@ -29,7 +29,7 @@ stop_kind() {
run_tests() {
(
cd "$SCRIPT_DIR"
telepresence connect --no-report -- go test -v -failfast -p=2 --tags="tests e2e" "$@"
telepresence connect --no-report -- go test -v -failfast -p=1 --tags="tests e2e" "$@"
)
}

Expand All @@ -41,5 +41,5 @@ if [[ "$#" -gt "0" ]]; then
# E.g. e2e/run.sh ./mysql/... -args -run-id=xxxxx -no-cleanup
run_tests "$@"
else
run_tests ./... -args -no-cleanup="$E2E_NO_CLEANUP"
run_tests ./... -args -no-cleanup="$E2E_NO_CLEANUP" -command-timeout=4m
fi
47 changes: 35 additions & 12 deletions internal/storage/blob/tests.go
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
"github.com/ory/dockertest/v3"
"github.com/ory/dockertest/v3/docker"
"github.com/stretchr/testify/require"
"gocloud.dev/blob"

Expand Down Expand Up @@ -148,21 +149,50 @@ func startMinio(ctx context.Context, t *testing.T, bucketName string) string {
options := &dockertest.RunOptions{
Repository: "minio/minio",
Tag: "latest",
Cmd: []string{"server", t.TempDir()},
Cmd: []string{"server", "/data"},
Env: []string{"MINIO_ACCESS_KEY=" + minioUsername, "MINIO_SECRET_KEY=" + minioPassword},
}

resource, err := pool.RunWithOptions(options)
is.NoError(err, "Could not start resource: %s", err)

go func() {
_ = pool.Client.Logs(docker.LogsOptions{
Context: ctx,
Stderr: true,
Stdout: true,
Follow: true,
Timestamps: true,
RawTerminal: true,
Container: resource.Container.ID,
OutputStream: os.Stdout,
})
}()

endpoint := fmt.Sprintf("localhost:%s", resource.GetPort("9000/tcp"))
client, err := minio.New(endpoint, &minio.Options{
Creds: credentials.NewStaticV4(minioUsername, minioPassword, ""),
Secure: false,
})
is.NoError(err, "Could not instantiate minio client", err)

cancelFn, err := client.HealthCheck(1 * time.Second)
is.NoError(err, "Failed to start healthcheck: %v", err)

t.Cleanup(cancelFn)

// Minio health check request
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("http://%s/minio/health/live", endpoint), nil)
is.NoError(err)
// exponential backoff-retry, because the application in the container might not be ready to accept connections yet
// the minio client does not do service discovery for you (i.e. it does not check if connection can be established), so we have to use the health check
err = pool.Retry(func() error {
if client.IsOffline() {
return fmt.Errorf("healthcheck fail")
}

req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("http://%s/minio/health/ready", endpoint), nil)
if err != nil {
return err
}

resp, err := http.DefaultClient.Do(req)
if err != nil {
return err
Expand All @@ -176,20 +206,13 @@ func startMinio(ctx context.Context, t *testing.T, bucketName string) string {
})
is.NoError(err, "Could not connect to docker: %s", err)

// now we can instantiate minio client
client, err := minio.New(endpoint, &minio.Options{
Creds: credentials.NewStaticV4(minioUsername, minioPassword, ""),
Secure: false,
})
is.NoError(err, "Could not instantiate minio client", err)

t.Cleanup(func() {
err = pool.Purge(resource)
is.NoError(err, "Could not purge resource: %s", err)
})

err = client.MakeBucket(ctx, bucketName, minio.MakeBucketOptions{})
is.NoError(err, "Failed to create bucket %q: %s", bucketName, err)
is.NoError(err, "Failed to create bucket %q: %v", bucketName, err)

return endpoint
}

0 comments on commit 3fa5b03

Please sign in to comment.