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