github.com/hernad/nomad@v1.6.112/e2e/clientstate/allocs_test.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: MPL-2.0 3 4 package clientstate 5 6 import ( 7 "testing" 8 "time" 9 10 "github.com/hernad/nomad/e2e/e2eutil" 11 "github.com/hernad/nomad/helper/uuid" 12 "github.com/shoenig/test/must" 13 "github.com/shoenig/test/wait" 14 ) 15 16 func TestClientAllocs(t *testing.T) { 17 nomad := e2eutil.NomadClient(t) 18 19 e2eutil.WaitForLeader(t, nomad) 20 e2eutil.WaitForNodesReady(t, nomad, 1) 21 22 t.Run("testAllocZombie", testAllocZombie) 23 } 24 25 // testAllocZombie ensures that a restart of a dead allocation does not cause 26 // it to come back to life in a not-quite alive state. 27 // 28 // https://github.com/hernad/nomad/issues/17079 29 func testAllocZombie(t *testing.T) { 30 nomad := e2eutil.NomadClient(t) 31 32 jobID := "alloc-zombie-" + uuid.Short() 33 jobIDs := []string{jobID} 34 t.Cleanup(e2eutil.CleanupJobsAndGC(t, &jobIDs)) 35 36 // start the job and wait for alloc to become failed 37 err := e2eutil.Register(jobID, "./input/alloc_zombie.nomad") 38 must.NoError(t, err) 39 40 allocID := e2eutil.SingleAllocID(t, jobID, "", 0) 41 42 // wait for alloc to be marked as failed 43 e2eutil.WaitForAllocStatus(t, nomad, allocID, "failed") 44 45 // wait for additional failures to know we got rescheduled 46 must.Wait(t, wait.InitialSuccess( 47 wait.BoolFunc(func() bool { 48 statuses, err := e2eutil.AllocStatusesRescheduled(jobID, "") 49 must.NoError(t, err) 50 return len(statuses) > 2 51 }), 52 wait.Timeout(1*time.Minute), 53 wait.Gap(1*time.Second), 54 )) 55 56 // now attempt to restart our initial allocation 57 // which should do nothing but give us an error 58 output, err := e2eutil.Command("nomad", "alloc", "restart", allocID) 59 must.ErrorContains(t, err, "restart of an alloc that should not run") 60 must.StrContains(t, output, "Failed to restart allocation") 61 }