task lifecycle: make e2e service job test block until poststart task has started

This commit is contained in:
Jasmine Dahilig 2020-08-20 08:07:18 -07:00
parent ee522ab587
commit 681eb407db
2 changed files with 24 additions and 2 deletions

View File

@ -8,7 +8,7 @@ job "service-lifecycle" {
datacenters = ["dc1"]
type = "batch"
type = "service"
group "test" {
@ -65,6 +65,7 @@ EOT
template {
data = <<EOT
#!/bin/sh
trap "rm ${NOMAD_ALLOC_DIR}/sidecar-running" SIGINT SIGTERM
touch ${NOMAD_ALLOC_DIR}/sidecar-ran
touch ${NOMAD_ALLOC_DIR}/sidecar-running
sleep 5
@ -96,6 +97,7 @@ EOT
template {
data = <<EOT
#!/bin/sh
trap "rm ${NOMAD_ALLOC_DIR}/main-running" SIGINT SIGTERM
touch ${NOMAD_ALLOC_DIR}/main-ran
touch ${NOMAD_ALLOC_DIR}/main-running
touch ${NOMAD_ALLOC_DIR}/main-started

View File

@ -1,11 +1,13 @@
package lifecycle
import (
"fmt"
"github.com/hashicorp/nomad/api"
"github.com/hashicorp/nomad/e2e/e2eutil"
"github.com/hashicorp/nomad/e2e/framework"
"github.com/hashicorp/nomad/helper/uuid"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/nomad/testutil"
"github.com/stretchr/testify/require"
)
@ -76,7 +78,25 @@ func (tc *LifecycleE2ETest) TestServiceJob(f *framework.F) {
require.Equal(1, len(allocs))
allocID := allocs[0].ID
e2eutil.WaitForAllocRunning(t, nomadClient, allocID)
//e2eutil.WaitForAllocRunning(t, nomadClient, allocID)
testutil.WaitForResult(func() (bool, error) {
alloc, _, err := nomadClient.Allocations().Info(allocID, nil)
if err != nil {
return false, err
}
if alloc.ClientStatus != structs.AllocClientStatusRunning {
return false, fmt.Errorf("expected status running, but was: %s", alloc.ClientStatus)
}
if alloc.TaskStates["poststart"].StartedAt.IsZero() {
return false, fmt.Errorf("poststart task hasn't started")
}
return true, nil
}, func(err error) {
t.Fatalf("failed to wait on alloc: %v", err)
})
alloc, _, err := nomadClient.Allocations().Info(allocID, nil)
require.NoError(err)