Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 59 additions & 45 deletions cmd/spicedb/migrate_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,57 +43,71 @@ func TestMigrate(t *testing.T) {
}

t.Run(engineKey, func(t *testing.T) {
engineKey := engineKey
for retryCount := range 5 {
engineKey := engineKey

r := testdatastore.RunDatastoreEngineWithBridge(t, engineKey, bridgeNetworkName)
db := r.NewDatabase(t)
r := testdatastore.RunDatastoreEngineWithBridge(t, engineKey, bridgeNetworkName)
db := r.NewDatabase(t)

envVars := []string{}
if wev, ok := r.(testdatastore.RunningEngineForTestWithEnvVars); ok {
envVars = wev.ExternalEnvVars()
}

// Run the migrate command and wait for it to complete.
resource, err := pool.RunWithOptions(&dockertest.RunOptions{
Repository: "authzed/spicedb",
Tag: "ci",
Cmd: []string{"migrate", "head", "--datastore-engine", engineKey, "--datastore-conn-uri", db},
NetworkID: bridgeNetworkName,
Env: envVars,
}, func(config *docker.HostConfig) {
config.RestartPolicy = docker.RestartPolicy{
Name: "no",
envVars := []string{}
if wev, ok := r.(testdatastore.RunningEngineForTestWithEnvVars); ok {
envVars = wev.ExternalEnvVars()
}
})
require.NoError(t, err)

waitCtx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()

// Ensure the command completed successfully.
status, err := pool.Client.WaitContainerWithContext(resource.Container.ID, waitCtx)
require.NoError(t, err)

if status != 0 {
stream := new(bytes.Buffer)

lerr := pool.Client.Logs(docker.LogsOptions{
Context: waitCtx,
OutputStream: stream,
ErrorStream: stream,
Stdout: true,
Stderr: true,
Container: resource.Container.ID,

// Run the migrate command and wait for it to complete.
resource, err := pool.RunWithOptions(&dockertest.RunOptions{
Repository: "authzed/spicedb",
Tag: "ci",
Cmd: []string{"migrate", "head", "--datastore-engine", engineKey, "--datastore-conn-uri", db},
NetworkID: bridgeNetworkName,
Env: envVars,
}, func(config *docker.HostConfig) {
config.RestartPolicy = docker.RestartPolicy{
Name: "no",
}
})
require.NoError(t, lerr)
if err != nil && retryCount < 4 {
// On error, retry a few times before failing
t.Logf("retrying migration for engine %s due to error: %v", engineKey, err)
continue
}

require.Fail(t, "Got non-zero exit code", stream.String())
}
require.NoError(t, err)

waitCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
Copy link
Contributor

@miparnisari miparnisari Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we even have a timeout here..? i say let the thing take as long as it wants: remove the retry stuff and the waitCtx.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want the test to hang

Copy link
Contributor

@miparnisari miparnisari Nov 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it won't hang, that's what go test -timeout XXX is for: https://github.com/authzed/actions/blob/main/go-test/action.yaml#L11

ugh we don't use that action for these. can you add -timeout 20m to

func testWithArgs(ctx context.Context, args ...string) ([]string, error) {
testArgs := append([]string{
"test",
"-failfast",
"-count=1",
"-race",
}, args...)
return testArgs, nil
}
?

Also FYI, github actions have a default timeout of 360 minutes per step.

defer cancel()

// Ensure the command completed successfully.
status, err := pool.Client.WaitContainerWithContext(resource.Container.ID, waitCtx)
if err != nil && retryCount < 4 {
// On error, retry a few times before failing
t.Logf("retrying migration for engine %s due to error: %v", engineKey, err)
continue
}

t.Cleanup(func() {
// When you're done, kill and remove the container
_ = pool.Purge(resource)
})
require.NoError(t, err)

if status != 0 {
stream := new(bytes.Buffer)

lerr := pool.Client.Logs(docker.LogsOptions{
Context: waitCtx,
OutputStream: stream,
ErrorStream: stream,
Stdout: true,
Stderr: true,
Container: resource.Container.ID,
})
require.NoError(t, lerr)

require.Fail(t, "Got non-zero exit code", stream.String())
}

t.Cleanup(func() {
// When you're done, kill and remove the container
_ = pool.Purge(resource)
})
}
})
}
}
Loading