simplify logic to check for vault read event

defer shutdown to cleanup after failed run

Co-Authored-By: Michael Schurter <mschurter@hashicorp.com>

update comment to include ctx note for shutdown
This commit is contained in:
Drew Bailey 2019-09-27 15:53:30 -04:00
parent 7565b8a8d9
commit 69eebcd241
No known key found for this signature in database
GPG Key ID: FBA61B9FB7CCE1A7
2 changed files with 4 additions and 7 deletions

View File

@ -89,7 +89,7 @@ type TaskPrestartHook interface {
// Prestart is called before the task is started including after every // Prestart is called before the task is started including after every
// restart. Prestart is not called if the allocation is terminal. // restart. Prestart is not called if the allocation is terminal.
// //
// The context is cancelled if the task is killed. // The context is cancelled if the task is killed or shutdown.
Prestart(context.Context, *TaskPrestartRequest, *TaskPrestartResponse) error Prestart(context.Context, *TaskPrestartRequest, *TaskPrestartResponse) error
} }

View File

@ -1766,6 +1766,7 @@ func TestTaskRunner_Template_BlockingPreStart(t *testing.T) {
tr, err := NewTaskRunner(conf) tr, err := NewTaskRunner(conf)
require.NoError(t, err) require.NoError(t, err)
go tr.Run() go tr.Run()
defer tr.Shutdown()
testutil.WaitForResult(func() (bool, error) { testutil.WaitForResult(func() (bool, error) {
ts := tr.TaskState() ts := tr.TaskState()
@ -1774,18 +1775,14 @@ func TestTaskRunner_Template_BlockingPreStart(t *testing.T) {
return false, fmt.Errorf("no events yet") return false, fmt.Errorf("no events yet")
} }
foundMissingVaultSecretEvent := false
for _, e := range ts.Events { for _, e := range ts.Events {
if e.Type == "Template" && strings.Contains(e.DisplayMessage, "vault.read(foo/secret)") { if e.Type == "Template" && strings.Contains(e.DisplayMessage, "vault.read(foo/secret)") {
foundMissingVaultSecretEvent = true return true, nil
} }
} }
if !foundMissingVaultSecretEvent { return false, fmt.Errorf("no missing vault secret template event yet: %#v", ts.Events)
return false, fmt.Errorf("no missing vault secret template event yet: %#v", ts.Events)
}
return true, nil
}, func(err error) { }, func(err error) {
require.NoError(t, err) require.NoError(t, err)
}) })