fix: Fail in goroutine after tests have completed (#23158) (#23164)

* fix panic: Fail in goroutine after TestProxy_Config_ReloadTls has completed

* fix proxy test

* feedback

* track the command output code and stdout/err
This commit is contained in:
Hamid Ghaf
2023-09-19 09:07:47 -07:00
committed by GitHub
parent db1c24d904
commit 1e4f08b75e

View File

@@ -405,14 +405,14 @@ listener "tcp" {
cmd.client = serverClient
cmd.startedCh = make(chan struct{})
var output string
var code int
wg := &sync.WaitGroup{}
wg.Add(1)
go func() {
code := cmd.Run([]string{"-config", configPath})
code = cmd.Run([]string{"-config", configPath})
if code != 0 {
t.Errorf("non-zero return code when running agent: %d", code)
t.Logf("STDOUT from agent:\n%s", ui.OutputWriter.String())
t.Logf("STDERR from agent:\n%s", ui.ErrorWriter.String())
output = ui.ErrorWriter.String() + ui.OutputWriter.String()
}
wg.Done()
}()
@@ -427,6 +427,9 @@ listener "tcp" {
defer func() {
cmd.ShutdownCh <- struct{}{}
wg.Wait()
if code != 0 {
t.Fatalf("got a non-zero exit status: %d, stdout/stderr: %s", code, output)
}
}()
//----------------------------------------------------
@@ -2037,14 +2040,14 @@ listener "tcp" {
cmd.client = serverClient
cmd.startedCh = make(chan struct{})
var output string
var code int
wg := &sync.WaitGroup{}
wg.Add(1)
go func() {
code := cmd.Run([]string{"-config", configPath})
code = cmd.Run([]string{"-config", configPath})
if code != 0 {
t.Errorf("non-zero return code when running agent: %d", code)
t.Logf("STDOUT from agent:\n%s", ui.OutputWriter.String())
t.Logf("STDERR from agent:\n%s", ui.ErrorWriter.String())
output = ui.ErrorWriter.String() + ui.OutputWriter.String()
}
wg.Done()
}()
@@ -2059,6 +2062,9 @@ listener "tcp" {
defer func() {
cmd.ShutdownCh <- struct{}{}
wg.Wait()
if code != 0 {
t.Fatalf("got a non-zero exit status: %d, stdout/stderr: %s", code, output)
}
}()
conf := api.DefaultConfig()
@@ -2352,12 +2358,13 @@ func TestAgent_Config_ReloadTls(t *testing.T) {
logger := logging.NewVaultLogger(hclog.Trace)
ui, cmd := testAgentCommand(t, logger)
var output string
var code int
wg.Add(1)
args := []string{"-config", configFile.Name()}
go func() {
if code := cmd.Run(args); code != 0 {
output := ui.ErrorWriter.String() + ui.OutputWriter.String()
t.Errorf("got a non-zero exit status: %s", output)
if code = cmd.Run(args); code != 0 {
output = ui.ErrorWriter.String() + ui.OutputWriter.String()
}
wg.Done()
}()
@@ -2424,8 +2431,11 @@ func TestAgent_Config_ReloadTls(t *testing.T) {
// Shut down
cmd.ShutdownCh <- struct{}{}
wg.Wait()
if code != 0 {
t.Fatalf("got a non-zero exit status: %d, stdout/stderr: %s", code, output)
}
}
// TestAgent_NonTLSListener_SIGHUP tests giving a SIGHUP signal to a listener
@@ -2469,12 +2479,13 @@ vault {
cmd.startedCh = make(chan struct{})
var output string
var code int
wg := &sync.WaitGroup{}
wg.Add(1)
go func() {
if code := cmd.Run([]string{"-config", configPath}); code != 0 {
output := ui.ErrorWriter.String() + ui.OutputWriter.String()
t.Errorf("got a non-zero exit status: %s", output)
if code = cmd.Run([]string{"-config", configPath}); code != 0 {
output = ui.ErrorWriter.String() + ui.OutputWriter.String()
}
wg.Done()
}()
@@ -2495,6 +2506,10 @@ vault {
close(cmd.ShutdownCh)
wg.Wait()
if code != 0 {
t.Fatalf("got a non-zero exit status: %d, stdout/stderr: %s", code, output)
}
}
// Get a randomly assigned port and then free it again before returning it.