github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/e2e/connect/client.go (about)

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