<commit_before>package e2eutil

import (
	"github.com/hashicorp/nomad/api"
	"github.com/hashicorp/nomad/e2e/framework"
	"github.com/hashicorp/nomad/helper"
	"github.com/hashicorp/nomad/helper/uuid"
	"github.com/hashicorp/nomad/jobspec"
	"github.com/hashicorp/nomad/testutil"
	. "github.com/onsi/gomega"
	"github.com/stretchr/testify/require"
	"testing"
	"time"
)

// retries is used to control how many times to retry checking if the cluster has a leader yet
const retries = 500

func WaitForLeader(t *testing.T, nomadClient *api.Client) {
	statusAPI := nomadClient.Status()

	testutil.WaitForResultRetries(retries, func() (bool, error) {
		leader, err := statusAPI.Leader()
		return leader != "", err
	}, func(err error) {
		t.Fatalf("failed to find leader: %v", err)
	})
}

func RegisterAndWaitForAllocs(f *framework.F, nomadClient *api.Client, jobFile string, prefix string) (string, []*api.AllocationListStub) {
	// Parse job
	job, err := jobspec.ParseFile(jobFile)
	require := require.New(f.T())
	require.Nil(err)
	uuid := uuid.Generate()
	jobId := helper.StringToPtr(prefix + uuid[0:8])
	job.ID = jobId

	// Register job
	jobs := nomadClient.Jobs()
	resp, _, err := jobs.Register(job, nil)
	require.Nil(err)
	require.NotEmpty(resp.EvalID)
<commit_msg>e2e: goimports e2eutil/utils.go<commit_after>package e2eutil

import (
	"testing"
	"time"

	"github.com/hashicorp/nomad/api"
	"github.com/hashicorp/nomad/e2e/framework"
	"github.com/hashicorp/nomad/helper"
	"github.com/hashicorp/nomad/helper/uuid"
	"github.com/hashicorp/nomad/jobspec"
	"github.com/hashicorp/nomad/testutil"
	. "github.com/onsi/gomega"
	"github.com/stretchr/testify/require"
)

// retries is used to control how many times to retry checking if the cluster has a leader yet
const retries = 500

func WaitForLeader(t *testing.T, nomadClient *api.Client) {
	statusAPI := nomadClient.Status()

	testutil.WaitForResultRetries(retries, func() (bool, error) {
		leader, err := statusAPI.Leader()
		return leader != "", err
	}, func(err error) {
		t.Fatalf("failed to find leader: %v", err)
	})
}

func RegisterAndWaitForAllocs(f *framework.F, nomadClient *api.Client, jobFile string, prefix string) (string, []*api.AllocationListStub) {
	// Parse job
	job, err := jobspec.ParseFile(jobFile)
	require := require.New(f.T())
	require.Nil(err)
	uuid := uuid.Generate()
	jobId := helper.StringToPtr(prefix + uuid[0:8])
	job.ID = jobId

	// Register job
	jobs := nomadClient.Jobs()
	resp, _, err := jobs.Register(job, nil)
	require.Nil(err)
	require.NotEmpty(resp.EvalID)

{'fraction_non_alphanumeric': 0.14725621792341098, 'fraction_numerical': 0.006316620607974733, 'mean_word_length': 4.65625, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4185714', 'n_tokens_mistral': 968, 'n_tokens_neox': 956, 'n_words': 192}