Skip to content

Commit

Permalink
tests: use standard library testing.TB
Browse files Browse the repository at this point in the history
Glint pulled in an updated version of mitchellh/go-testing-interface
which broke some existing tests because the update added a Parallel()
method to testing.T. This switches to the standard library testing.TB
which doesn't have a Parallel() method.
  • Loading branch information
Mahmood Ali authored and isabeldepapel committed Jun 9, 2021
1 parent 0edda11 commit 122a4cb
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 23 deletions.
2 changes: 1 addition & 1 deletion command/agent/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (

// makeHTTPServer returns a test server whose logs will be written to
// the passed writer. If the writer is nil, the logs are written to stderr.
func makeHTTPServer(t testing.T, cb func(c *Config)) *TestAgent {
func makeHTTPServer(t testing.TB, cb func(c *Config)) *TestAgent {
return NewTestAgent(t, t.Name(), cb)
}

Expand Down
7 changes: 3 additions & 4 deletions command/agent/testagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import (
"os"
"path/filepath"
"strings"
"testing"
"time"

testing "github.com/mitchellh/go-testing-interface"

metrics "github.com/armon/go-metrics"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/nomad/api"
Expand All @@ -39,7 +38,7 @@ var TempDir = os.TempDir()
// is removed after shutdown.
type TestAgent struct {
// T is the testing object
T testing.T
T testing.TB

// Name is an optional name of the agent.
Name string
Expand Down Expand Up @@ -92,7 +91,7 @@ type TestAgent struct {
// NewTestAgent returns a started agent with the given name and
// configuration. The caller should call Shutdown() to stop the agent and
// remove temporary directories.
func NewTestAgent(t testing.T, name string, configCallback func(*Config)) *TestAgent {
func NewTestAgent(t testing.TB, name string, configCallback func(*Config)) *TestAgent {
a := &TestAgent{
T: t,
Name: name,
Expand Down
8 changes: 4 additions & 4 deletions nomad/state/testing.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package state

import (
testing "github.com/mitchellh/go-testing-interface"
"testing"

"github.com/hashicorp/nomad/helper/testlog"
"github.com/hashicorp/nomad/helper/uuid"
"github.com/hashicorp/nomad/nomad/mock"
"github.com/hashicorp/nomad/nomad/structs"
)

func TestStateStore(t testing.T) *StateStore {
func TestStateStore(t testing.TB) *StateStore {
config := &StateStoreConfig{
Logger: testlog.HCLogger(t),
Region: "global",
Expand All @@ -24,14 +24,14 @@ func TestStateStore(t testing.T) *StateStore {
return state
}

func TestStateStorePublisher(t testing.T) *StateStoreConfig {
func TestStateStorePublisher(t testing.TB) *StateStoreConfig {
return &StateStoreConfig{
Logger: testlog.HCLogger(t),
Region: "global",
EnablePublisher: true,
}
}
func TestStateStoreCfg(t testing.T, cfg *StateStoreConfig) *StateStore {
func TestStateStoreCfg(t testing.TB, cfg *StateStoreConfig) *StateStore {
state, err := NewStateStore(cfg)
if err != nil {
t.Fatalf("err: %v", err)
Expand Down
10 changes: 5 additions & 5 deletions scheduler/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package scheduler
import (
"fmt"
"sync"
"testing"
"time"

testing "github.com/mitchellh/go-testing-interface"
"github.com/stretchr/testify/require"

"github.com/hashicorp/go-memdb"
Expand Down Expand Up @@ -41,7 +41,7 @@ func (r *RejectPlan) ReblockEval(*structs.Evaluation) error {
// store copy and provides the planner interface. It can be extended for various
// testing uses or for invoking the scheduler without side effects.
type Harness struct {
t testing.T
t testing.TB
State *state.StateStore

Planner Planner
Expand All @@ -59,7 +59,7 @@ type Harness struct {
}

// NewHarness is used to make a new testing harness
func NewHarness(t testing.T) *Harness {
func NewHarness(t testing.TB) *Harness {
state := state.TestStateStore(t)
h := &Harness{
t: t,
Expand All @@ -71,7 +71,7 @@ func NewHarness(t testing.T) *Harness {

// NewHarnessWithState creates a new harness with the given state for testing
// purposes.
func NewHarnessWithState(t testing.T, state *state.StateStore) *Harness {
func NewHarnessWithState(t testing.TB, state *state.StateStore) *Harness {
return &Harness{
t: t,
State: state,
Expand Down Expand Up @@ -272,7 +272,7 @@ func (h *Harness) Process(factory Factory, eval *structs.Evaluation) error {
return sched.Process(eval)
}

func (h *Harness) AssertEvalStatus(t testing.T, state string) {
func (h *Harness) AssertEvalStatus(t testing.TB, state string) {
require.Len(t, h.Evals, 1)
update := h.Evals[0]
require.Equal(t, state, update.Status)
Expand Down
18 changes: 9 additions & 9 deletions testutil/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package testutil
import (
"fmt"
"os"
"testing"
"time"

"github.com/hashicorp/nomad/nomad/structs"
"github.com/kr/pretty"
testing "github.com/mitchellh/go-testing-interface"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -83,7 +83,7 @@ func IsAppVeyor() bool {
type rpcFn func(string, interface{}, interface{}) error

// WaitForLeader blocks until a leader is elected.
func WaitForLeader(t testing.T, rpc rpcFn) {
func WaitForLeader(t testing.TB, rpc rpcFn) {
t.Helper()
WaitForResult(func() (bool, error) {
args := &structs.GenericRequest{}
Expand All @@ -96,7 +96,7 @@ func WaitForLeader(t testing.T, rpc rpcFn) {
}

// WaitForClient blocks until the client can be found
func WaitForClient(t testing.T, rpc rpcFn, nodeID string) {
func WaitForClient(t testing.TB, rpc rpcFn, nodeID string) {
t.Helper()
WaitForResult(func() (bool, error) {
req := structs.NodeSpecificRequest{
Expand All @@ -123,7 +123,7 @@ func WaitForClient(t testing.T, rpc rpcFn, nodeID string) {
//
// Useful for tests that change cluster topology (e.g. kill a node)
// that should wait until cluster is stable.
func WaitForVotingMembers(t testing.T, rpc rpcFn, nPeers int) {
func WaitForVotingMembers(t testing.TB, rpc rpcFn, nPeers int) {
WaitForResult(func() (bool, error) {
args := &structs.GenericRequest{}
args.AllowStale = true
Expand Down Expand Up @@ -152,7 +152,7 @@ func WaitForVotingMembers(t testing.T, rpc rpcFn, nPeers int) {
}

// RegisterJobWithToken registers a job and uses the job's Region and Namespace.
func RegisterJobWithToken(t testing.T, rpc rpcFn, job *structs.Job, token string) {
func RegisterJobWithToken(t testing.TB, rpc rpcFn, job *structs.Job, token string) {
WaitForResult(func() (bool, error) {
args := &structs.JobRegisterRequest{}
args.Job = job
Expand All @@ -169,11 +169,11 @@ func RegisterJobWithToken(t testing.T, rpc rpcFn, job *structs.Job, token string
t.Logf("Job %q registered", job.ID)
}

func RegisterJob(t testing.T, rpc rpcFn, job *structs.Job) {
func RegisterJob(t testing.TB, rpc rpcFn, job *structs.Job) {
RegisterJobWithToken(t, rpc, job, "")
}

func WaitForRunningWithToken(t testing.T, rpc rpcFn, job *structs.Job, token string) []*structs.AllocListStub {
func WaitForRunningWithToken(t testing.TB, rpc rpcFn, job *structs.Job, token string) []*structs.AllocListStub {
RegisterJobWithToken(t, rpc, job, token)

var resp structs.JobAllocationsResponse
Expand Down Expand Up @@ -211,12 +211,12 @@ func WaitForRunningWithToken(t testing.T, rpc rpcFn, job *structs.Job, token str
}

// WaitForRunning runs a job and blocks until all allocs are out of pending.
func WaitForRunning(t testing.T, rpc rpcFn, job *structs.Job) []*structs.AllocListStub {
func WaitForRunning(t testing.TB, rpc rpcFn, job *structs.Job) []*structs.AllocListStub {
return WaitForRunningWithToken(t, rpc, job, "")
}

// WaitForFiles blocks until all the files in the slice are present
func WaitForFiles(t testing.T, files []string) {
func WaitForFiles(t testing.TB, files []string) {
assert := assert.New(t)
WaitForResult(func() (bool, error) {
for _, f := range files {
Expand Down

0 comments on commit 122a4cb

Please sign in to comment.