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:
parent
7565b8a8d9
commit
69eebcd241
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue