github.com/hernad/nomad@v1.6.112/e2e/connect/client.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: MPL-2.0 3 4 package connect 5 6 import ( 7 "os" 8 9 capi "github.com/hashicorp/consul/api" 10 "github.com/hernad/nomad/e2e/e2eutil" 11 "github.com/hernad/nomad/e2e/framework" 12 "github.com/hernad/nomad/helper/uuid" 13 ) 14 15 const ( 16 consulNamespace = "default" 17 ) 18 19 type ConnectClientStateE2ETest struct { 20 framework.TC 21 jobIDs []string 22 } 23 24 func (tc *ConnectClientStateE2ETest) BeforeAll(f *framework.F) { 25 e2eutil.WaitForLeader(f.T(), tc.Nomad()) 26 e2eutil.WaitForNodesReady(f.T(), tc.Nomad(), 1) 27 } 28 29 func (tc *ConnectClientStateE2ETest) AfterEach(f *framework.F) { 30 if os.Getenv("NOMAD_TEST_SKIPCLEANUP") == "1" { 31 return 32 } 33 34 for _, id := range tc.jobIDs { 35 tc.Nomad().Jobs().Deregister(id, true, nil) 36 } 37 tc.jobIDs = []string{} 38 tc.Nomad().System().GarbageCollect() 39 } 40 41 func (tc *ConnectClientStateE2ETest) TestClientRestart(f *framework.F) { 42 t := f.T() 43 44 jobID := "connect" + uuid.Generate()[0:8] 45 tc.jobIDs = append(tc.jobIDs, jobID) 46 client := tc.Nomad() 47 consulClient := tc.Consul() 48 49 allocs := e2eutil.RegisterAndWaitForAllocs(t, client, 50 "connect/input/demo.nomad", jobID, "") 51 f.Equal(2, len(allocs)) 52 53 e2eutil.RequireConsulStatus(f.Assertions, consulClient, consulNamespace, "count-api-sidecar-proxy", capi.HealthPassing) 54 nodeID := allocs[0].NodeID 55 56 restartID, err := e2eutil.AgentRestart(client, nodeID) 57 if restartID != "" { 58 tc.jobIDs = append(tc.jobIDs, restartID) 59 } 60 if err != nil { 61 t.Skip("node cannot be restarted", err) 62 } 63 64 e2eutil.RequireConsulStatus(f.Assertions, consulClient, consulNamespace, "count-api-sidecar-proxy", capi.HealthPassing) 65 }