Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal/commands/server: prevent test panic on timeout #5249

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
8 changes: 2 additions & 6 deletions internal/cmd/commands/server/controller_db_swap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func TestReloadControllerDatabase(t *testing.T) {
exitCode := cmd.Run(args)
if exitCode != 0 {
output := cmd.UI.(*cli.MockUi).ErrorWriter.String() + cmd.UI.(*cli.MockUi).OutputWriter.String()
t.Errorf("got a non-zero exit status: %s", output)
fmt.Printf("%s: got a non-zero exit status: %s", t.Name(), output)
}
}()

Expand Down Expand Up @@ -241,7 +241,6 @@ func TestReloadControllerDatabase_InvalidNewDatabaseState(t *testing.T) {
cfgHcl := fmt.Sprintf(dbSwapConfig, urlA, controllerKey, workerAuthKey, recoveryKey)
require.NoError(t, os.WriteFile(td+"/config.hcl", []byte(cfgHcl), 0o644))

errCh := make(chan error, 1)
wg := &sync.WaitGroup{}
wg.Add(1)
go func() {
Expand All @@ -251,15 +250,12 @@ func TestReloadControllerDatabase_InvalidNewDatabaseState(t *testing.T) {
exitCode := cmd.Run(args)
if exitCode != 0 {
output := cmd.UI.(*cli.MockUi).ErrorWriter.String() + cmd.UI.(*cli.MockUi).OutputWriter.String()
errCh <- fmt.Errorf("got a non-zero exit status: %s", output)
close(errCh)
fmt.Printf("%s: got a non-zero exit status: %s", t.Name(), output)
}
}()

// Wait until things are up and running (or timeout).
select {
case err := <-errCh:
t.Fatal(err)
case <-cmd.startedCh:
case <-time.After(15 * time.Second):
t.Fatal("timeout")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ listener "tcp" {
`
)

func TestRealodControllerRateLimits(t *testing.T) {
func TestReloadControllerRateLimits(t *testing.T) {
td := t.TempDir()

controllerKey := config.DevKeyGeneration()
Expand All @@ -209,7 +209,7 @@ func TestRealodControllerRateLimits(t *testing.T) {
exitCode := cmd.Run(args)
if exitCode != 0 {
output := cmd.UI.(*cli.MockUi).ErrorWriter.String() + cmd.UI.(*cli.MockUi).OutputWriter.String()
t.Errorf("got a non-zero exit status: %s", output)
fmt.Printf("%s: got a non-zero exit status: %s", t.Name(), output)
}
}()

Expand Down Expand Up @@ -282,7 +282,7 @@ func TestRealodControllerRateLimits(t *testing.T) {
wg.Wait()
}

func TestRealodControllerRateLimitsSameConfig(t *testing.T) {
func TestReloadControllerRateLimitsSameConfig(t *testing.T) {
td := t.TempDir()

// Create and migrate database A and B.
Expand All @@ -308,7 +308,7 @@ func TestRealodControllerRateLimitsSameConfig(t *testing.T) {
exitCode := cmd.Run(args)
if exitCode != 0 {
output := cmd.UI.(*cli.MockUi).ErrorWriter.String() + cmd.UI.(*cli.MockUi).OutputWriter.String()
t.Errorf("got a non-zero exit status: %s", output)
fmt.Printf("%s: got a non-zero exit status: %s", t.Name(), output)
}
}()

Expand Down Expand Up @@ -377,7 +377,7 @@ func TestRealodControllerRateLimitsSameConfig(t *testing.T) {
wg.Wait()
}

func TestRealodControllerRateLimitsDisable(t *testing.T) {
func TestReloadControllerRateLimitsDisable(t *testing.T) {
td := t.TempDir()

controllerKey := config.DevKeyGeneration()
Expand All @@ -402,7 +402,7 @@ func TestRealodControllerRateLimitsDisable(t *testing.T) {
exitCode := cmd.Run(args)
if exitCode != 0 {
output := cmd.UI.(*cli.MockUi).ErrorWriter.String() + cmd.UI.(*cli.MockUi).OutputWriter.String()
t.Errorf("got a non-zero exit status: %s", output)
fmt.Printf("%s: got a non-zero exit status: %s", t.Name(), output)
}
}()

Expand Down Expand Up @@ -475,7 +475,7 @@ func TestRealodControllerRateLimitsDisable(t *testing.T) {
wg.Wait()
}

func TestRealodControllerRateLimitsEnable(t *testing.T) {
func TestReloadControllerRateLimitsEnable(t *testing.T) {
td := t.TempDir()

controllerKey := config.DevKeyGeneration()
Expand All @@ -501,7 +501,7 @@ func TestRealodControllerRateLimitsEnable(t *testing.T) {
exitCode := cmd.Run(args)
if exitCode != 0 {
output := cmd.UI.(*cli.MockUi).ErrorWriter.String() + cmd.UI.(*cli.MockUi).OutputWriter.String()
t.Errorf("got a non-zero exit status: %s", output)
fmt.Printf("%s: got a non-zero exit status: %s", t.Name(), output)
}
}()

Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/commands/server/listener_reload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func TestServer_ReloadListener(t *testing.T) {
defer wg.Done()
if code := cmd.Run(args); code != 0 {
output := cmd.UI.(*cli.MockUi).ErrorWriter.String() + cmd.UI.(*cli.MockUi).OutputWriter.String()
t.Errorf("got a non-zero exit status: %s", output)
fmt.Printf("%s: got a non-zero exit status: %s", t.Name(), output)
}
}()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestServer_ReloadInitialUpstreams(t *testing.T) {
defer wg.Done()
if code := cmd.Run(nil); code != 0 {
output := cmd.UI.(*cli.MockUi).ErrorWriter.String() + cmd.UI.(*cli.MockUi).OutputWriter.String()
t.Errorf("got a non-zero exit status: %s", output)
fmt.Printf("%s: got a non-zero exit status: %s", t.Name(), output)
}
}()

Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/commands/server/worker_tags_reload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestServer_ReloadWorkerTags(t *testing.T) {
defer wg.Done()
if code := cmd.Run(nil); code != 0 {
output := cmd.UI.(*cli.MockUi).ErrorWriter.String() + cmd.UI.(*cli.MockUi).OutputWriter.String()
t.Errorf("got a non-zero exit status: %s", output)
fmt.Printf("%s: got a non-zero exit status: %s", t.Name(), output)
}
}()

Expand Down
Loading