From 98c7abe541cf59cece46a45083d54f461832d502 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Wed, 13 Jun 2018 15:33:25 -0700 Subject: [PATCH] Tests only use testlog package logger --- client/allocdir/alloc_dir_test.go | 24 ++- client/allocdir/task_dir_linux_test.go | 3 +- client/allocdir/task_dir_test.go | 9 +- .../taskrunner/task_runner_test.go | 17 +- client/client_test.go | 6 +- client/driver/docker_coordinator_test.go | 9 +- client/driver/docker_test.go | 11 +- client/driver/driver_test.go | 12 +- client/driver/executor/executor_linux_test.go | 12 +- client/driver/executor/executor_test.go | 26 ++- client/driver/logging/rotator_test.go | 21 ++- .../driver/logging/syslog_parser_unix_test.go | 7 +- client/driver/qemu_test.go | 5 +- client/fingerprint/arch_test.go | 3 +- client/fingerprint/cgroup_test.go | 9 +- client/fingerprint/consul_test.go | 5 +- client/fingerprint/cpu_test.go | 5 +- client/fingerprint/env_aws_test.go | 11 +- client/fingerprint/env_gce_test.go | 5 +- client/fingerprint/fingerprint_test.go | 6 - client/fingerprint/host_test.go | 3 +- client/fingerprint/memory_test.go | 5 +- client/fingerprint/network_test.go | 13 +- client/fingerprint/network_windows_test.go | 2 +- client/fingerprint/nomad_test.go | 3 +- client/fingerprint/signal_test.go | 3 +- client/fingerprint/storage_test.go | 3 +- client/fingerprint/vault_test.go | 3 +- client/fingerprint_manager_test.go | 4 +- client/fs_endpoint_test.go | 4 +- client/servers/manager_internal_test.go | 12 +- client/servers/manager_test.go | 4 +- client/stats/cpu_test.go | 4 +- client/vaultclient/vaultclient_test.go | 11 +- command/agent/agent_test.go | 22 +-- command/agent/consul/int_test.go | 11 +- command/agent/retry_join_test.go | 10 +- .../deployments_watcher_test.go | 3 +- nomad/deploymentwatcher/testutil_test.go | 9 -- nomad/fsm.go | 2 +- nomad/fsm_test.go | 2 +- nomad/periodic_test.go | 43 +++-- nomad/state/state_store.go | 2 +- nomad/testing.go | 3 +- nomad/vault_test.go | 49 +++--- scheduler/context_test.go | 5 +- scheduler/reconcile_test.go | 149 +++++++++--------- scheduler/util_test.go | 7 +- 48 files changed, 273 insertions(+), 324 deletions(-) diff --git a/client/allocdir/alloc_dir_test.go b/client/allocdir/alloc_dir_test.go index 93799a78d..aed8bb19e 100644 --- a/client/allocdir/alloc_dir_test.go +++ b/client/allocdir/alloc_dir_test.go @@ -15,6 +15,7 @@ import ( cstructs "github.com/hashicorp/nomad/client/structs" "github.com/hashicorp/nomad/client/testutil" + "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/nomad/structs" "github.com/kr/pretty" ) @@ -45,13 +46,6 @@ var ( } ) -func testLogger() *log.Logger { - if testing.Verbose() { - return log.New(os.Stderr, "", log.LstdFlags) - } - return log.New(ioutil.Discard, "", log.LstdFlags) -} - // Test that AllocDir.Build builds just the alloc directory. func TestAllocDir_BuildAlloc(t *testing.T) { tmp, err := ioutil.TempDir("", "AllocDir") @@ -60,7 +54,7 @@ func TestAllocDir_BuildAlloc(t *testing.T) { } defer os.RemoveAll(tmp) - d := NewAllocDir(testLogger(), tmp) + d := NewAllocDir(testlog.Logger(t), tmp) defer d.Destroy() d.NewTaskDir(t1.Name) d.NewTaskDir(t2.Name) @@ -97,7 +91,7 @@ func TestAllocDir_MountSharedAlloc(t *testing.T) { } defer os.RemoveAll(tmp) - d := NewAllocDir(testLogger(), tmp) + d := NewAllocDir(testlog.Logger(t), tmp) defer d.Destroy() if err := d.Build(); err != nil { t.Fatalf("Build() failed: %v", err) @@ -142,7 +136,7 @@ func TestAllocDir_Snapshot(t *testing.T) { } defer os.RemoveAll(tmp) - d := NewAllocDir(testLogger(), tmp) + d := NewAllocDir(testlog.Logger(t), tmp) defer d.Destroy() if err := d.Build(); err != nil { t.Fatalf("Build() failed: %v", err) @@ -229,13 +223,13 @@ func TestAllocDir_Move(t *testing.T) { defer os.RemoveAll(tmp2) // Create two alloc dirs - d1 := NewAllocDir(testLogger(), tmp1) + d1 := NewAllocDir(testlog.Logger(t), tmp1) if err := d1.Build(); err != nil { t.Fatalf("Build() failed: %v", err) } defer d1.Destroy() - d2 := NewAllocDir(testLogger(), tmp2) + d2 := NewAllocDir(testlog.Logger(t), tmp2) if err := d2.Build(); err != nil { t.Fatalf("Build() failed: %v", err) } @@ -290,7 +284,7 @@ func TestAllocDir_EscapeChecking(t *testing.T) { } defer os.RemoveAll(tmp) - d := NewAllocDir(testLogger(), tmp) + d := NewAllocDir(testlog.Logger(t), tmp) if err := d.Build(); err != nil { t.Fatalf("Build() failed: %v", err) } @@ -331,7 +325,7 @@ func TestAllocDir_ReadAt_SecretDir(t *testing.T) { } defer os.RemoveAll(tmp) - d := NewAllocDir(testLogger(), tmp) + d := NewAllocDir(testlog.Logger(t), tmp) if err := d.Build(); err != nil { t.Fatalf("Build() failed: %v", err) } @@ -416,7 +410,7 @@ func TestAllocDir_CreateDir(t *testing.T) { // TestAllocDir_Copy asserts that AllocDir.Copy does a deep copy of itself and // all TaskDirs. func TestAllocDir_Copy(t *testing.T) { - a := NewAllocDir(testLogger(), "foo") + a := NewAllocDir(testlog.Logger(t), "foo") a.NewTaskDir("bar") a.NewTaskDir("baz") diff --git a/client/allocdir/task_dir_linux_test.go b/client/allocdir/task_dir_linux_test.go index 43faf3c85..0f4da6bce 100644 --- a/client/allocdir/task_dir_linux_test.go +++ b/client/allocdir/task_dir_linux_test.go @@ -6,6 +6,7 @@ import ( "path/filepath" "testing" + "github.com/hashicorp/nomad/helper/testlog" "golang.org/x/sys/unix" ) @@ -21,7 +22,7 @@ func TestLinuxSpecialDirs(t *testing.T) { } defer os.RemoveAll(allocDir) - td := newTaskDir(testLogger(), allocDir, "test") + td := newTaskDir(testlog.Logger(t), allocDir, "test") // Despite the task dir not existing, unmountSpecialDirs should *not* // return an error diff --git a/client/allocdir/task_dir_test.go b/client/allocdir/task_dir_test.go index bc213ce1a..318e48413 100644 --- a/client/allocdir/task_dir_test.go +++ b/client/allocdir/task_dir_test.go @@ -7,6 +7,7 @@ import ( "testing" cstructs "github.com/hashicorp/nomad/client/structs" + "github.com/hashicorp/nomad/helper/testlog" ) // Test that building a chroot will skip nonexistent directories. @@ -17,7 +18,7 @@ func TestTaskDir_EmbedNonexistent(t *testing.T) { } defer os.RemoveAll(tmp) - d := NewAllocDir(testLogger(), tmp) + d := NewAllocDir(testlog.Logger(t), tmp) defer d.Destroy() td := d.NewTaskDir(t1.Name) if err := d.Build(); err != nil { @@ -39,7 +40,7 @@ func TestTaskDir_EmbedDirs(t *testing.T) { } defer os.RemoveAll(tmp) - d := NewAllocDir(testLogger(), tmp) + d := NewAllocDir(testlog.Logger(t), tmp) defer d.Destroy() td := d.NewTaskDir(t1.Name) if err := d.Build(); err != nil { @@ -96,7 +97,7 @@ func TestTaskDir_NonRoot_Image(t *testing.T) { } defer os.RemoveAll(tmp) - d := NewAllocDir(testLogger(), tmp) + d := NewAllocDir(testlog.Logger(t), tmp) defer d.Destroy() td := d.NewTaskDir(t1.Name) if err := d.Build(); err != nil { @@ -119,7 +120,7 @@ func TestTaskDir_NonRoot(t *testing.T) { } defer os.RemoveAll(tmp) - d := NewAllocDir(testLogger(), tmp) + d := NewAllocDir(testlog.Logger(t), tmp) defer d.Destroy() td := d.NewTaskDir(t1.Name) if err := d.Build(); err != nil { diff --git a/client/allocrunner/taskrunner/task_runner_test.go b/client/allocrunner/taskrunner/task_runner_test.go index 20d7e6f15..a0aa7c79d 100644 --- a/client/allocrunner/taskrunner/task_runner_test.go +++ b/client/allocrunner/taskrunner/task_runner_test.go @@ -3,7 +3,6 @@ package taskrunner import ( "fmt" "io/ioutil" - "log" "net/http" "net/http/httptest" "os" @@ -24,23 +23,13 @@ import ( cstructs "github.com/hashicorp/nomad/client/structs" "github.com/hashicorp/nomad/client/vaultclient" "github.com/hashicorp/nomad/command/agent/consul" + "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/nomad/mock" "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/testutil" "github.com/kr/pretty" ) -func testLogger() *log.Logger { - return prefixedTestLogger("") -} - -func prefixedTestLogger(prefix string) *log.Logger { - if testing.Verbose() { - return log.New(os.Stderr, prefix, log.LstdFlags|log.Lmicroseconds) - } - return log.New(ioutil.Discard, "", 0) -} - // Returns a tracker that never restarts. func noRestartsTracker() *restarts.RestartTracker { policy := &structs.RestartPolicy{Attempts: 0, Mode: structs.RestartPolicyModeFail} @@ -104,7 +93,7 @@ func testTaskRunner(t *testing.T, restarts bool) *taskRunnerTestCtx { // // Callers should defer Cleanup() to cleanup after completion func testTaskRunnerFromAlloc(t *testing.T, restarts bool, alloc *structs.Allocation) *taskRunnerTestCtx { - logger := testLogger() + logger := testlog.Logger(t) conf := config.DefaultConfig() conf.Node = mock.Node() conf.StateDir = os.TempDir() @@ -122,7 +111,7 @@ func testTaskRunnerFromAlloc(t *testing.T, restarts bool, alloc *structs.Allocat upd := &MockTaskStateUpdater{} task := alloc.Job.TaskGroups[0].Tasks[0] - allocDir := allocdir.NewAllocDir(testLogger(), filepath.Join(conf.AllocDir, alloc.ID)) + allocDir := allocdir.NewAllocDir(testlog.Logger(t), filepath.Join(conf.AllocDir, alloc.ID)) if err := allocDir.Build(); err != nil { t.Fatalf("error building alloc dir: %v", err) return nil diff --git a/client/client_test.go b/client/client_test.go index 5d44ad878..03b466cbf 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -3,7 +3,6 @@ package client import ( "fmt" "io/ioutil" - "log" "os" "path/filepath" "testing" @@ -14,6 +13,7 @@ import ( consulApi "github.com/hashicorp/nomad/client/consul" "github.com/hashicorp/nomad/client/driver" "github.com/hashicorp/nomad/command/agent/consul" + "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/helper/uuid" "github.com/hashicorp/nomad/nomad" "github.com/hashicorp/nomad/nomad/mock" @@ -602,7 +602,7 @@ func TestClient_SaveRestoreState(t *testing.T) { } // Create a new client - logger := log.New(c1.config.LogOutput, "", log.LstdFlags) + logger := testlog.Logger(t) catalog := consul.NewMockCatalog(logger) mockService := consulApi.NewMockConsulServiceClient(t) mockService.Logger = logger @@ -650,7 +650,7 @@ func TestClient_Init(t *testing.T) { config: &config.Config{ AllocDir: allocDir, }, - logger: log.New(os.Stderr, "", log.LstdFlags), + logger: testlog.Logger(t), } if err := client.init(); err != nil { t.Fatalf("err: %s", err) diff --git a/client/driver/docker_coordinator_test.go b/client/driver/docker_coordinator_test.go index c81cee99b..79bcfdc31 100644 --- a/client/driver/docker_coordinator_test.go +++ b/client/driver/docker_coordinator_test.go @@ -6,6 +6,7 @@ import ( "time" docker "github.com/fsouza/go-dockerclient" + "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/helper/uuid" "github.com/hashicorp/nomad/testutil" ) @@ -52,7 +53,7 @@ func TestDockerCoordinator_ConcurrentPulls(t *testing.T) { // Add a delay so we can get multiple queued up mock := newMockImageClient(mapping, 10*time.Millisecond) config := &dockerCoordinatorConfig{ - logger: testLogger(), + logger: testlog.Logger(t), cleanup: true, client: mock, removeDelay: 100 * time.Millisecond, @@ -99,7 +100,7 @@ func TestDockerCoordinator_Pull_Remove(t *testing.T) { // Add a delay so we can get multiple queued up mock := newMockImageClient(mapping, 10*time.Millisecond) config := &dockerCoordinatorConfig{ - logger: testLogger(), + logger: testlog.Logger(t), cleanup: true, client: mock, removeDelay: 1 * time.Millisecond, @@ -162,7 +163,7 @@ func TestDockerCoordinator_Remove_Cancel(t *testing.T) { mock := newMockImageClient(mapping, 1*time.Millisecond) config := &dockerCoordinatorConfig{ - logger: testLogger(), + logger: testlog.Logger(t), cleanup: true, client: mock, removeDelay: 100 * time.Millisecond, @@ -210,7 +211,7 @@ func TestDockerCoordinator_No_Cleanup(t *testing.T) { mock := newMockImageClient(mapping, 1*time.Millisecond) config := &dockerCoordinatorConfig{ - logger: testLogger(), + logger: testlog.Logger(t), cleanup: false, client: mock, removeDelay: 1 * time.Millisecond, diff --git a/client/driver/docker_test.go b/client/driver/docker_test.go index 151f034a7..674cae9b2 100644 --- a/client/driver/docker_test.go +++ b/client/driver/docker_test.go @@ -24,6 +24,7 @@ import ( "github.com/hashicorp/nomad/client/fingerprint" cstructs "github.com/hashicorp/nomad/client/structs" "github.com/hashicorp/nomad/client/testutil" + "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/helper/uuid" "github.com/hashicorp/nomad/nomad/mock" "github.com/hashicorp/nomad/nomad/structs" @@ -225,7 +226,7 @@ func TestDockerDriver_Fingerprint_Bridge(t *testing.T) { conf := testConfig(t) conf.Node = mock.Node() - dd := NewDockerDriver(NewDriverContext("", "", "", "", conf, conf.Node, testLogger(), nil)) + dd := NewDockerDriver(NewDriverContext("", "", "", "", conf, conf.Node, testlog.Logger(t), nil)) request := &cstructs.FingerprintRequest{Config: conf, Node: conf.Node} var response cstructs.FingerprintResponse @@ -277,7 +278,7 @@ func TestDockerDriver_Check_DockerHealthStatus(t *testing.T) { conf := testConfig(t) conf.Node = mock.Node() - dd := NewDockerDriver(NewDriverContext("", "", "", "", conf, conf.Node, testLogger(), nil)) + dd := NewDockerDriver(NewDriverContext("", "", "", "", conf, conf.Node, testlog.Logger(t), nil)) request := &cstructs.HealthCheckRequest{} var response cstructs.HealthCheckResponse @@ -1677,7 +1678,7 @@ func setupDockerVolumes(t *testing.T, cfg *config.Config, hostpath string) (*str } // Build alloc and task directory structure - allocDir := allocdir.NewAllocDir(testLogger(), filepath.Join(cfg.AllocDir, uuid.Generate())) + allocDir := allocdir.NewAllocDir(testlog.Logger(t), filepath.Join(cfg.AllocDir, uuid.Generate())) if err := allocDir.Build(); err != nil { t.Fatalf("failed to build alloc dir: %v", err) } @@ -1690,11 +1691,11 @@ func setupDockerVolumes(t *testing.T, cfg *config.Config, hostpath string) (*str // Setup driver alloc := mock.Alloc() - logger := testLogger() + logger := testlog.Logger(t) emitter := func(m string, args ...interface{}) { logger.Printf("[EVENT] "+m, args...) } - driverCtx := NewDriverContext(alloc.Job.Name, alloc.TaskGroup, task.Name, alloc.ID, cfg, cfg.Node, testLogger(), emitter) + driverCtx := NewDriverContext(alloc.Job.Name, alloc.TaskGroup, task.Name, alloc.ID, cfg, cfg.Node, testlog.Logger(t), emitter) driver := NewDockerDriver(driverCtx) // Setup execCtx diff --git a/client/driver/driver_test.go b/client/driver/driver_test.go index 11caf922c..d17ffefcc 100644 --- a/client/driver/driver_test.go +++ b/client/driver/driver_test.go @@ -3,7 +3,6 @@ package driver import ( "io" "io/ioutil" - "log" "math/rand" "os" "path/filepath" @@ -14,6 +13,7 @@ import ( "github.com/hashicorp/nomad/client/allocdir" "github.com/hashicorp/nomad/client/config" "github.com/hashicorp/nomad/client/driver/env" + "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/helper/testtask" "github.com/hashicorp/nomad/helper/uuid" "github.com/hashicorp/nomad/nomad/mock" @@ -60,10 +60,6 @@ func copyFile(src, dst string, t *testing.T) { } } -func testLogger() *log.Logger { - return log.New(os.Stderr, "", log.LstdFlags) -} - func testConfig(t *testing.T) *config.Config { conf := config.DefaultConfig() @@ -116,7 +112,7 @@ type testContext struct { func testDriverContexts(t *testing.T, task *structs.Task) *testContext { cfg := testConfig(t) cfg.Node = mock.Node() - allocDir := allocdir.NewAllocDir(testLogger(), filepath.Join(cfg.AllocDir, uuid.Generate())) + allocDir := allocdir.NewAllocDir(testlog.Logger(t), filepath.Join(cfg.AllocDir, uuid.Generate())) if err := allocDir.Build(); err != nil { t.Fatalf("AllocDir.Build() failed: %v", err) } @@ -141,7 +137,7 @@ func testDriverContexts(t *testing.T, task *structs.Task) *testContext { SetEnvvars(eb, tmpdrv.FSIsolation(), td, cfg) execCtx := NewExecContext(td, eb.Build()) - logger := testLogger() + logger := testlog.Logger(t) emitter := func(m string, args ...interface{}) { logger.Printf("[EVENT] "+m, args...) } @@ -182,7 +178,7 @@ func setupTaskEnv(t *testing.T, driver string) (*allocdir.TaskDir, map[string]st alloc.Name = "Bar" alloc.TaskResources["web"].Networks[0].DynamicPorts[0].Value = 2000 conf := testConfig(t) - allocDir := allocdir.NewAllocDir(testLogger(), filepath.Join(conf.AllocDir, alloc.ID)) + allocDir := allocdir.NewAllocDir(testlog.Logger(t), filepath.Join(conf.AllocDir, alloc.ID)) taskDir := allocDir.NewTaskDir(task.Name) eb := env.NewBuilder(conf.Node, alloc, task, conf.Region) tmpDriver, err := NewDriver(driver, NewEmptyDriverContext()) diff --git a/client/driver/executor/executor_linux_test.go b/client/driver/executor/executor_linux_test.go index 17063b4bd..3d423ddd0 100644 --- a/client/driver/executor/executor_linux_test.go +++ b/client/driver/executor/executor_linux_test.go @@ -2,7 +2,6 @@ package executor import ( "io/ioutil" - "log" "os" "path/filepath" "strconv" @@ -15,6 +14,7 @@ import ( dstructs "github.com/hashicorp/nomad/client/driver/structs" cstructs "github.com/hashicorp/nomad/client/structs" "github.com/hashicorp/nomad/client/testutil" + "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/nomad/mock" ) @@ -41,13 +41,13 @@ func testExecutorContextWithChroot(t *testing.T) (*ExecutorContext, *allocdir.Al task := alloc.Job.TaskGroups[0].Tasks[0] taskEnv := env.NewBuilder(mock.Node(), alloc, task, "global").Build() - allocDir := allocdir.NewAllocDir(testLogger(), filepath.Join(os.TempDir(), alloc.ID)) + allocDir := allocdir.NewAllocDir(testlog.Logger(t), filepath.Join(os.TempDir(), alloc.ID)) if err := allocDir.Build(); err != nil { - log.Fatalf("AllocDir.Build() failed: %v", err) + t.Fatalf("AllocDir.Build() failed: %v", err) } if err := allocDir.NewTaskDir(task.Name).Build(false, chrootEnv, cstructs.FSIsolationChroot); err != nil { allocDir.Destroy() - log.Fatalf("allocDir.NewTaskDir(%q) failed: %v", task.Name, err) + t.Fatalf("allocDir.NewTaskDir(%q) failed: %v", task.Name, err) } td := allocDir.TaskDirs[task.Name] ctx := &ExecutorContext{ @@ -71,7 +71,7 @@ func TestExecutor_IsolationAndConstraints(t *testing.T) { execCmd.ResourceLimits = true execCmd.User = dstructs.DefaultUnprivilegedUser - executor := NewExecutor(log.New(os.Stdout, "", log.LstdFlags)) + executor := NewExecutor(testlog.Logger(t)) if err := executor.SetContext(ctx); err != nil { t.Fatalf("Unexpected error: %v", err) @@ -151,7 +151,7 @@ func TestExecutor_ClientCleanup(t *testing.T) { ctx.Task.LogConfig.MaxFileSizeMB = 300 defer allocDir.Destroy() - executor := NewExecutor(log.New(os.Stdout, "", log.LstdFlags)) + executor := NewExecutor(testlog.Logger(t)) if err := executor.SetContext(ctx); err != nil { t.Fatalf("Unexpected error") diff --git a/client/driver/executor/executor_test.go b/client/driver/executor/executor_test.go index e3a41571c..ddb5169ba 100644 --- a/client/driver/executor/executor_test.go +++ b/client/driver/executor/executor_test.go @@ -2,7 +2,6 @@ package executor import ( "io/ioutil" - "log" "os" "path/filepath" "strings" @@ -13,15 +12,12 @@ import ( "github.com/hashicorp/nomad/client/allocdir" "github.com/hashicorp/nomad/client/driver/env" cstructs "github.com/hashicorp/nomad/client/structs" + "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/nomad/mock" tu "github.com/hashicorp/nomad/testutil" "github.com/mitchellh/go-ps" ) -func testLogger() *log.Logger { - return log.New(os.Stderr, "", log.LstdFlags) -} - // testExecutorContext returns an ExecutorContext and AllocDir. // // The caller is responsible for calling AllocDir.Destroy() to cleanup. @@ -30,13 +26,13 @@ func testExecutorContext(t *testing.T) (*ExecutorContext, *allocdir.AllocDir) { task := alloc.Job.TaskGroups[0].Tasks[0] taskEnv := env.NewBuilder(mock.Node(), alloc, task, "global").Build() - allocDir := allocdir.NewAllocDir(testLogger(), filepath.Join(os.TempDir(), alloc.ID)) + allocDir := allocdir.NewAllocDir(testlog.Logger(t), filepath.Join(os.TempDir(), alloc.ID)) if err := allocDir.Build(); err != nil { - log.Fatalf("AllocDir.Build() failed: %v", err) + t.Fatalf("AllocDir.Build() failed: %v", err) } if err := allocDir.NewTaskDir(task.Name).Build(false, nil, cstructs.FSIsolationNone); err != nil { allocDir.Destroy() - log.Fatalf("allocDir.NewTaskDir(%q) failed: %v", task.Name, err) + t.Fatalf("allocDir.NewTaskDir(%q) failed: %v", task.Name, err) } td := allocDir.TaskDirs[task.Name] ctx := &ExecutorContext{ @@ -54,7 +50,7 @@ func TestExecutor_Start_Invalid(t *testing.T) { execCmd := ExecCommand{Cmd: invalid, Args: []string{"1"}} ctx, allocDir := testExecutorContext(t) defer allocDir.Destroy() - executor := NewExecutor(log.New(os.Stdout, "", log.LstdFlags)) + executor := NewExecutor(testlog.Logger(t)) if err := executor.SetContext(ctx); err != nil { t.Fatalf("Unexpected error") @@ -70,7 +66,7 @@ func TestExecutor_Start_Wait_Failure_Code(t *testing.T) { execCmd := ExecCommand{Cmd: "/bin/date", Args: []string{"fail"}} ctx, allocDir := testExecutorContext(t) defer allocDir.Destroy() - executor := NewExecutor(log.New(os.Stdout, "", log.LstdFlags)) + executor := NewExecutor(testlog.Logger(t)) if err := executor.SetContext(ctx); err != nil { t.Fatalf("Unexpected error") @@ -98,7 +94,7 @@ func TestExecutor_Start_Wait(t *testing.T) { execCmd := ExecCommand{Cmd: "/bin/echo", Args: []string{"hello world"}} ctx, allocDir := testExecutorContext(t) defer allocDir.Destroy() - executor := NewExecutor(log.New(os.Stdout, "", log.LstdFlags)) + executor := NewExecutor(testlog.Logger(t)) if err := executor.SetContext(ctx); err != nil { t.Fatalf("Unexpected error") @@ -137,7 +133,7 @@ func TestExecutor_WaitExitSignal(t *testing.T) { execCmd := ExecCommand{Cmd: "/bin/sleep", Args: []string{"10000"}} ctx, allocDir := testExecutorContext(t) defer allocDir.Destroy() - executor := NewExecutor(log.New(os.Stdout, "", log.LstdFlags)) + executor := NewExecutor(testlog.Logger(t)) if err := executor.SetContext(ctx); err != nil { t.Fatalf("Unexpected error") @@ -180,7 +176,7 @@ func TestExecutor_Start_Kill(t *testing.T) { execCmd := ExecCommand{Cmd: "/bin/sleep", Args: []string{"10 && hello world"}} ctx, allocDir := testExecutorContext(t) defer allocDir.Destroy() - executor := NewExecutor(log.New(os.Stdout, "", log.LstdFlags)) + executor := NewExecutor(testlog.Logger(t)) if err := executor.SetContext(ctx); err != nil { t.Fatalf("Unexpected error") @@ -230,7 +226,7 @@ func TestExecutor_MakeExecutable(t *testing.T) { f.Chmod(os.FileMode(0610)) // Make a fake executor - executor := NewExecutor(log.New(os.Stdout, "", log.LstdFlags)) + executor := NewExecutor(testlog.Logger(t)) err = executor.(*UniversalExecutor).makeExecutable(f.Name()) if err != nil { @@ -259,7 +255,7 @@ func TestScanPids(t *testing.T) { p5 := NewFakeProcess(20, 18) // Make a fake executor - executor := NewExecutor(log.New(os.Stdout, "", log.LstdFlags)).(*UniversalExecutor) + executor := NewExecutor(testlog.Logger(t)).(*UniversalExecutor) nomadPids, err := executor.scanPids(5, []ps.Process{p1, p2, p3, p4, p5}) if err != nil { diff --git a/client/driver/logging/rotator_test.go b/client/driver/logging/rotator_test.go index 4fcf23952..d988c6493 100644 --- a/client/driver/logging/rotator_test.go +++ b/client/driver/logging/rotator_test.go @@ -3,24 +3,23 @@ package logging import ( "fmt" "io/ioutil" - "log" "math/rand" "os" "path/filepath" "testing" + "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/testutil" ) var ( - logger = log.New(os.Stdout, "", log.LstdFlags) pathPrefix = "logrotator" baseFileName = "redis.stdout" ) func TestFileRotator_IncorrectPath(t *testing.T) { t.Parallel() - if _, err := NewFileRotator("/foo", baseFileName, 10, 10, logger); err == nil { + if _, err := NewFileRotator("/foo", baseFileName, 10, 10, testlog.Logger(t)); err == nil { t.Fatalf("expected error") } } @@ -34,7 +33,7 @@ func TestFileRotator_CreateNewFile(t *testing.T) { } defer os.RemoveAll(path) - _, err = NewFileRotator(path, baseFileName, 10, 10, logger) + _, err = NewFileRotator(path, baseFileName, 10, 10, testlog.Logger(t)) if err != nil { t.Fatalf("test setup err: %v", err) } @@ -62,7 +61,7 @@ func TestFileRotator_OpenLastFile(t *testing.T) { t.Fatalf("test setup failure: %v", err) } - fr, err := NewFileRotator(path, baseFileName, 10, 10, logger) + fr, err := NewFileRotator(path, baseFileName, 10, 10, testlog.Logger(t)) if err != nil { t.Fatalf("test setup err: %v", err) } @@ -86,7 +85,7 @@ func TestFileRotator_WriteToCurrentFile(t *testing.T) { t.Fatalf("test setup failure: %v", err) } - fr, err := NewFileRotator(path, baseFileName, 10, 5, logger) + fr, err := NewFileRotator(path, baseFileName, 10, 5, testlog.Logger(t)) if err != nil { t.Fatalf("test setup err: %v", err) } @@ -119,7 +118,7 @@ func TestFileRotator_RotateFiles(t *testing.T) { } defer os.RemoveAll(path) - fr, err := NewFileRotator(path, baseFileName, 10, 5, logger) + fr, err := NewFileRotator(path, baseFileName, 10, 5, testlog.Logger(t)) if err != nil { t.Fatalf("test setup err: %v", err) } @@ -178,7 +177,7 @@ func TestFileRotator_RotateFiles_Boundary(t *testing.T) { } defer os.RemoveAll(path) - fr, err := NewFileRotator(path, baseFileName, 10, 5, logger) + fr, err := NewFileRotator(path, baseFileName, 10, 5, testlog.Logger(t)) if err != nil { t.Fatalf("test setup err: %v", err) } @@ -244,7 +243,7 @@ func TestFileRotator_WriteRemaining(t *testing.T) { t.Fatalf("test setup failure: %v", err) } - fr, err := NewFileRotator(path, baseFileName, 10, 5, logger) + fr, err := NewFileRotator(path, baseFileName, 10, 5, testlog.Logger(t)) if err != nil { t.Fatalf("test setup err: %v", err) } @@ -317,7 +316,7 @@ func TestFileRotator_PurgeOldFiles(t *testing.T) { } defer os.RemoveAll(path) - fr, err := NewFileRotator(path, baseFileName, 2, 2, logger) + fr, err := NewFileRotator(path, baseFileName, 2, 2, testlog.Logger(t)) if err != nil { t.Fatalf("test setup err: %v", err) } @@ -367,7 +366,7 @@ func benchmarkRotatorWithInputSize(size int, b *testing.B) { } defer os.RemoveAll(path) - fr, err := NewFileRotator(path, baseFileName, 5, 1024*1024, logger) + fr, err := NewFileRotator(path, baseFileName, 5, 1024*1024, testlog.Logger(b)) if err != nil { b.Fatalf("test setup err: %v", err) } diff --git a/client/driver/logging/syslog_parser_unix_test.go b/client/driver/logging/syslog_parser_unix_test.go index bed6682a0..38d0b6b8a 100644 --- a/client/driver/logging/syslog_parser_unix_test.go +++ b/client/driver/logging/syslog_parser_unix_test.go @@ -4,17 +4,16 @@ package logging import ( "bytes" - "log" - "os" "testing" syslog "github.com/RackSec/srslog" + "github.com/hashicorp/nomad/helper/testlog" ) func TestLogParser_Priority(t *testing.T) { t.Parallel() line := []byte("<30>2016-02-10T10:16:43-08:00 d-thinkpad docker/e2a1e3ebd3a3[22950]: 1:C 10 Feb 18:16:43.391 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf") - d := NewDockerLogParser(log.New(os.Stdout, "", log.LstdFlags)) + d := NewDockerLogParser(testlog.Logger(t)) p, _, err := d.parsePriority(line) if err != nil { t.Fatalf("got an err: %v", err) @@ -33,7 +32,7 @@ func TestLogParser_Priority(t *testing.T) { func TestLogParser_Priority_UnixFormatter(t *testing.T) { t.Parallel() line := []byte("<30>Feb 6, 10:16:43 docker/e2a1e3ebd3a3[22950]: 1:C 10 Feb 18:16:43.391 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf") - d := NewDockerLogParser(log.New(os.Stdout, "", log.LstdFlags)) + d := NewDockerLogParser(testlog.Logger(t)) p, _, err := d.parsePriority(line) if err != nil { t.Fatalf("got an err: %v", err) diff --git a/client/driver/qemu_test.go b/client/driver/qemu_test.go index b3d442b09..51f021068 100644 --- a/client/driver/qemu_test.go +++ b/client/driver/qemu_test.go @@ -14,6 +14,7 @@ import ( "github.com/hashicorp/consul/lib/freeport" "github.com/hashicorp/nomad/client/config" cstructs "github.com/hashicorp/nomad/client/structs" + "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/testutil" @@ -65,7 +66,7 @@ func TestQemuDriver_Fingerprint(t *testing.T) { } func TestQemuDriver_StartOpen_Wait(t *testing.T) { - logger := testLogger() + logger := testlog.Logger(t) if !testutil.IsTravis() { t.Parallel() } @@ -143,7 +144,7 @@ func TestQemuDriver_GracefulShutdown(t *testing.T) { } ctestutils.QemuCompatible(t) - logger := testLogger() + logger := testlog.Logger(t) // Graceful shutdown may be really slow unfortunately killTimeout := 3 * time.Minute diff --git a/client/fingerprint/arch_test.go b/client/fingerprint/arch_test.go index 320ccc321..58c600b6a 100644 --- a/client/fingerprint/arch_test.go +++ b/client/fingerprint/arch_test.go @@ -5,11 +5,12 @@ import ( "github.com/hashicorp/nomad/client/config" cstructs "github.com/hashicorp/nomad/client/structs" + "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/nomad/structs" ) func TestArchFingerprint(t *testing.T) { - f := NewArchFingerprint(testLogger()) + f := NewArchFingerprint(testlog.Logger(t)) node := &structs.Node{ Attributes: make(map[string]string), } diff --git a/client/fingerprint/cgroup_test.go b/client/fingerprint/cgroup_test.go index 2dc1d51ec..b3894d2d2 100644 --- a/client/fingerprint/cgroup_test.go +++ b/client/fingerprint/cgroup_test.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/nomad/client/config" cstructs "github.com/hashicorp/nomad/client/structs" + "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/nomad/structs" ) @@ -42,7 +43,7 @@ func (m *MountPointDetectorEmptyMountPoint) MountPoint() (string, error) { func TestCGroupFingerprint(t *testing.T) { { f := &CGroupFingerprint{ - logger: testLogger(), + logger: testlog.Logger(t), lastState: cgroupUnavailable, mountPointDetector: &MountPointDetectorMountPointFail{}, } @@ -65,7 +66,7 @@ func TestCGroupFingerprint(t *testing.T) { { f := &CGroupFingerprint{ - logger: testLogger(), + logger: testlog.Logger(t), lastState: cgroupUnavailable, mountPointDetector: &MountPointDetectorValidMountPoint{}, } @@ -87,7 +88,7 @@ func TestCGroupFingerprint(t *testing.T) { { f := &CGroupFingerprint{ - logger: testLogger(), + logger: testlog.Logger(t), lastState: cgroupUnavailable, mountPointDetector: &MountPointDetectorEmptyMountPoint{}, } @@ -108,7 +109,7 @@ func TestCGroupFingerprint(t *testing.T) { } { f := &CGroupFingerprint{ - logger: testLogger(), + logger: testlog.Logger(t), lastState: cgroupAvailable, mountPointDetector: &MountPointDetectorValidMountPoint{}, } diff --git a/client/fingerprint/consul_test.go b/client/fingerprint/consul_test.go index 400ab01f4..a96c73b07 100644 --- a/client/fingerprint/consul_test.go +++ b/client/fingerprint/consul_test.go @@ -9,12 +9,13 @@ import ( "github.com/hashicorp/nomad/client/config" cstructs "github.com/hashicorp/nomad/client/structs" + "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/nomad/structs" "github.com/stretchr/testify/assert" ) func TestConsulFingerprint(t *testing.T) { - fp := NewConsulFingerprint(testLogger()) + fp := NewConsulFingerprint(testlog.Logger(t)) node := &structs.Node{ Attributes: make(map[string]string), } @@ -170,7 +171,7 @@ const mockConsulResponse = ` // See https://github.com/hashicorp/nomad/issues/3326 func TestConsulFingerprint_UnexpectedResponse(t *testing.T) { assert := assert.New(t) - fp := NewConsulFingerprint(testLogger()) + fp := NewConsulFingerprint(testlog.Logger(t)) node := &structs.Node{ Attributes: make(map[string]string), } diff --git a/client/fingerprint/cpu_test.go b/client/fingerprint/cpu_test.go index 5bb761970..07dd64d3d 100644 --- a/client/fingerprint/cpu_test.go +++ b/client/fingerprint/cpu_test.go @@ -5,11 +5,12 @@ import ( "github.com/hashicorp/nomad/client/config" cstructs "github.com/hashicorp/nomad/client/structs" + "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/nomad/structs" ) func TestCPUFingerprint(t *testing.T) { - f := NewCPUFingerprint(testLogger()) + f := NewCPUFingerprint(testlog.Logger(t)) node := &structs.Node{ Attributes: make(map[string]string), } @@ -52,7 +53,7 @@ func TestCPUFingerprint(t *testing.T) { // TestCPUFingerprint_OverrideCompute asserts that setting cpu_total_compute in // the client config overrides the detected CPU freq (if any). func TestCPUFingerprint_OverrideCompute(t *testing.T) { - f := NewCPUFingerprint(testLogger()) + f := NewCPUFingerprint(testlog.Logger(t)) node := &structs.Node{ Attributes: make(map[string]string), } diff --git a/client/fingerprint/env_aws_test.go b/client/fingerprint/env_aws_test.go index 2a94561df..e69bf5a50 100644 --- a/client/fingerprint/env_aws_test.go +++ b/client/fingerprint/env_aws_test.go @@ -10,12 +10,13 @@ import ( "github.com/hashicorp/nomad/client/config" cstructs "github.com/hashicorp/nomad/client/structs" + "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/nomad/structs" ) func TestEnvAWSFingerprint_nonAws(t *testing.T) { os.Setenv("AWS_ENV_URL", "http://127.0.0.1/latest/meta-data/") - f := NewEnvAWSFingerprint(testLogger()) + f := NewEnvAWSFingerprint(testlog.Logger(t)) node := &structs.Node{ Attributes: make(map[string]string), } @@ -33,7 +34,7 @@ func TestEnvAWSFingerprint_nonAws(t *testing.T) { } func TestEnvAWSFingerprint_aws(t *testing.T) { - f := NewEnvAWSFingerprint(testLogger()) + f := NewEnvAWSFingerprint(testlog.Logger(t)) node := &structs.Node{ Attributes: make(map[string]string), } @@ -167,7 +168,7 @@ func TestNetworkFingerprint_AWS(t *testing.T) { defer ts.Close() os.Setenv("AWS_ENV_URL", ts.URL+"/latest/meta-data/") - f := NewEnvAWSFingerprint(testLogger()) + f := NewEnvAWSFingerprint(testlog.Logger(t)) node := &structs.Node{ Attributes: make(map[string]string), } @@ -216,7 +217,7 @@ func TestNetworkFingerprint_AWS_network(t *testing.T) { defer ts.Close() os.Setenv("AWS_ENV_URL", ts.URL+"/latest/meta-data/") - f := NewEnvAWSFingerprint(testLogger()) + f := NewEnvAWSFingerprint(testlog.Logger(t)) { node := &structs.Node{ Attributes: make(map[string]string), @@ -297,7 +298,7 @@ func TestNetworkFingerprint_AWS_network(t *testing.T) { func TestNetworkFingerprint_notAWS(t *testing.T) { os.Setenv("AWS_ENV_URL", "http://127.0.0.1/latest/meta-data/") - f := NewEnvAWSFingerprint(testLogger()) + f := NewEnvAWSFingerprint(testlog.Logger(t)) node := &structs.Node{ Attributes: make(map[string]string), } diff --git a/client/fingerprint/env_gce_test.go b/client/fingerprint/env_gce_test.go index 9d1a2c4bc..445643765 100644 --- a/client/fingerprint/env_gce_test.go +++ b/client/fingerprint/env_gce_test.go @@ -11,12 +11,13 @@ import ( "github.com/hashicorp/nomad/client/config" cstructs "github.com/hashicorp/nomad/client/structs" + "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/nomad/structs" ) func TestGCEFingerprint_nonGCE(t *testing.T) { os.Setenv("GCE_ENV_URL", "http://127.0.0.1/computeMetadata/v1/instance/") - f := NewEnvGCEFingerprint(testLogger()) + f := NewEnvGCEFingerprint(testlog.Logger(t)) node := &structs.Node{ Attributes: make(map[string]string), } @@ -90,7 +91,7 @@ func testFingerprint_GCE(t *testing.T, withExternalIp bool) { })) defer ts.Close() os.Setenv("GCE_ENV_URL", ts.URL+"/computeMetadata/v1/instance/") - f := NewEnvGCEFingerprint(testLogger()) + f := NewEnvGCEFingerprint(testlog.Logger(t)) request := &cstructs.FingerprintRequest{Config: &config.Config{}, Node: node} var response cstructs.FingerprintResponse diff --git a/client/fingerprint/fingerprint_test.go b/client/fingerprint/fingerprint_test.go index 41a7e6549..ca14bd9b7 100644 --- a/client/fingerprint/fingerprint_test.go +++ b/client/fingerprint/fingerprint_test.go @@ -3,8 +3,6 @@ package fingerprint // This file contains helper methods for testing fingerprinters import ( - "log" - "os" "testing" "github.com/hashicorp/nomad/client/config" @@ -12,10 +10,6 @@ import ( "github.com/hashicorp/nomad/nomad/structs" ) -func testLogger() *log.Logger { - return log.New(os.Stderr, "", log.LstdFlags) -} - func assertFingerprintOK(t *testing.T, fp Fingerprint, node *structs.Node) *cstructs.FingerprintResponse { request := &cstructs.FingerprintRequest{Config: new(config.Config), Node: node} var response cstructs.FingerprintResponse diff --git a/client/fingerprint/host_test.go b/client/fingerprint/host_test.go index 79ef870c5..6fafca0d9 100644 --- a/client/fingerprint/host_test.go +++ b/client/fingerprint/host_test.go @@ -5,11 +5,12 @@ import ( "github.com/hashicorp/nomad/client/config" cstructs "github.com/hashicorp/nomad/client/structs" + "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/nomad/structs" ) func TestHostFingerprint(t *testing.T) { - f := NewHostFingerprint(testLogger()) + f := NewHostFingerprint(testlog.Logger(t)) node := &structs.Node{ Attributes: make(map[string]string), } diff --git a/client/fingerprint/memory_test.go b/client/fingerprint/memory_test.go index 5190f8b4e..24365cebc 100644 --- a/client/fingerprint/memory_test.go +++ b/client/fingerprint/memory_test.go @@ -5,13 +5,14 @@ import ( "github.com/hashicorp/nomad/client/config" cstructs "github.com/hashicorp/nomad/client/structs" + "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/nomad/structs" "github.com/stretchr/testify/require" ) func TestMemoryFingerprint(t *testing.T) { - f := NewMemoryFingerprint(testLogger()) + f := NewMemoryFingerprint(testlog.Logger(t)) node := &structs.Node{ Attributes: make(map[string]string), } @@ -34,7 +35,7 @@ func TestMemoryFingerprint(t *testing.T) { } func TestMemoryFingerprint_Override(t *testing.T) { - f := NewMemoryFingerprint(testLogger()) + f := NewMemoryFingerprint(testlog.Logger(t)) node := &structs.Node{ Attributes: make(map[string]string), } diff --git a/client/fingerprint/network_test.go b/client/fingerprint/network_test.go index fd01a9ea8..527865ed6 100644 --- a/client/fingerprint/network_test.go +++ b/client/fingerprint/network_test.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/nomad/client/config" cstructs "github.com/hashicorp/nomad/client/structs" + "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/nomad/structs" ) @@ -184,7 +185,7 @@ func TestNetworkFingerprint_basic(t *testing.T) { t.Skipf("Environment variable %+q not empty, skipping test", skipOnlineTestsEnvVar) } - f := &NetworkFingerprint{logger: testLogger(), interfaceDetector: &DefaultNetworkInterfaceDetector{}} + f := &NetworkFingerprint{logger: testlog.Logger(t), interfaceDetector: &DefaultNetworkInterfaceDetector{}} node := &structs.Node{ Attributes: make(map[string]string), } @@ -235,7 +236,7 @@ func TestNetworkFingerprint_basic(t *testing.T) { } func TestNetworkFingerprint_default_device_absent(t *testing.T) { - f := &NetworkFingerprint{logger: testLogger(), interfaceDetector: &NetworkInterfaceDetectorOnlyLo{}} + f := &NetworkFingerprint{logger: testlog.Logger(t), interfaceDetector: &NetworkInterfaceDetectorOnlyLo{}} node := &structs.Node{ Attributes: make(map[string]string), } @@ -258,7 +259,7 @@ func TestNetworkFingerprint_default_device_absent(t *testing.T) { } func TestNetworkFingerPrint_default_device(t *testing.T) { - f := &NetworkFingerprint{logger: testLogger(), interfaceDetector: &NetworkInterfaceDetectorOnlyLo{}} + f := &NetworkFingerprint{logger: testlog.Logger(t), interfaceDetector: &NetworkInterfaceDetectorOnlyLo{}} node := &structs.Node{ Attributes: make(map[string]string), } @@ -309,7 +310,7 @@ func TestNetworkFingerPrint_default_device(t *testing.T) { } func TestNetworkFingerPrint_LinkLocal_Allowed(t *testing.T) { - f := &NetworkFingerprint{logger: testLogger(), interfaceDetector: &NetworkInterfaceDetectorMultipleInterfaces{}} + f := &NetworkFingerprint{logger: testlog.Logger(t), interfaceDetector: &NetworkInterfaceDetectorMultipleInterfaces{}} node := &structs.Node{ Attributes: make(map[string]string), } @@ -356,7 +357,7 @@ func TestNetworkFingerPrint_LinkLocal_Allowed(t *testing.T) { } func TestNetworkFingerPrint_LinkLocal_Allowed_MixedIntf(t *testing.T) { - f := &NetworkFingerprint{logger: testLogger(), interfaceDetector: &NetworkInterfaceDetectorMultipleInterfaces{}} + f := &NetworkFingerprint{logger: testlog.Logger(t), interfaceDetector: &NetworkInterfaceDetectorMultipleInterfaces{}} node := &structs.Node{ Attributes: make(map[string]string), } @@ -410,7 +411,7 @@ func TestNetworkFingerPrint_LinkLocal_Allowed_MixedIntf(t *testing.T) { } func TestNetworkFingerPrint_LinkLocal_Disallowed(t *testing.T) { - f := &NetworkFingerprint{logger: testLogger(), interfaceDetector: &NetworkInterfaceDetectorMultipleInterfaces{}} + f := &NetworkFingerprint{logger: testlog.Logger(t), interfaceDetector: &NetworkInterfaceDetectorMultipleInterfaces{}} node := &structs.Node{ Attributes: make(map[string]string), } diff --git a/client/fingerprint/network_windows_test.go b/client/fingerprint/network_windows_test.go index 0cc8acfdf..2bea592ca 100644 --- a/client/fingerprint/network_windows_test.go +++ b/client/fingerprint/network_windows_test.go @@ -3,7 +3,7 @@ package fingerprint import "testing" func TestNetworkFingerPrint_linkspeed_parse(t *testing.T) { - f := &NetworkFingerprint{logger: testLogger(), interfaceDetector: &DefaultNetworkInterfaceDetector{}} + f := &NetworkFingerprint{logger: testlog.Logger(t), interfaceDetector: &DefaultNetworkInterfaceDetector{}} var outputTests = []struct { in string diff --git a/client/fingerprint/nomad_test.go b/client/fingerprint/nomad_test.go index 2060fd8e2..d3bdadf45 100644 --- a/client/fingerprint/nomad_test.go +++ b/client/fingerprint/nomad_test.go @@ -5,12 +5,13 @@ import ( "github.com/hashicorp/nomad/client/config" cstructs "github.com/hashicorp/nomad/client/structs" + "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/version" ) func TestNomadFingerprint(t *testing.T) { - f := NewNomadFingerprint(testLogger()) + f := NewNomadFingerprint(testlog.Logger(t)) node := &structs.Node{ Attributes: make(map[string]string), } diff --git a/client/fingerprint/signal_test.go b/client/fingerprint/signal_test.go index bf61f7544..ff0577125 100644 --- a/client/fingerprint/signal_test.go +++ b/client/fingerprint/signal_test.go @@ -3,11 +3,12 @@ package fingerprint import ( "testing" + "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/nomad/structs" ) func TestSignalFingerprint(t *testing.T) { - fp := NewSignalFingerprint(testLogger()) + fp := NewSignalFingerprint(testlog.Logger(t)) node := &structs.Node{ Attributes: make(map[string]string), } diff --git a/client/fingerprint/storage_test.go b/client/fingerprint/storage_test.go index c4388905f..509521bb3 100644 --- a/client/fingerprint/storage_test.go +++ b/client/fingerprint/storage_test.go @@ -4,11 +4,12 @@ import ( "strconv" "testing" + "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/nomad/structs" ) func TestStorageFingerprint(t *testing.T) { - fp := NewStorageFingerprint(testLogger()) + fp := NewStorageFingerprint(testlog.Logger(t)) node := &structs.Node{ Attributes: make(map[string]string), } diff --git a/client/fingerprint/vault_test.go b/client/fingerprint/vault_test.go index 25e7f1386..3ca1fa448 100644 --- a/client/fingerprint/vault_test.go +++ b/client/fingerprint/vault_test.go @@ -5,6 +5,7 @@ import ( "github.com/hashicorp/nomad/client/config" cstructs "github.com/hashicorp/nomad/client/structs" + "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/testutil" ) @@ -13,7 +14,7 @@ func TestVaultFingerprint(t *testing.T) { tv := testutil.NewTestVault(t) defer tv.Stop() - fp := NewVaultFingerprint(testLogger()) + fp := NewVaultFingerprint(testlog.Logger(t)) node := &structs.Node{ Attributes: make(map[string]string), } diff --git a/client/fingerprint_manager_test.go b/client/fingerprint_manager_test.go index 464a5d186..11c8d49ae 100644 --- a/client/fingerprint_manager_test.go +++ b/client/fingerprint_manager_test.go @@ -2,8 +2,6 @@ package client import ( "fmt" - "log" - "os" "testing" "github.com/hashicorp/nomad/client/config" @@ -17,7 +15,7 @@ func TestFingerprintManager_Run_MockDriver(t *testing.T) { require := require.New(t) testClient := TestClient(t, nil) - testClient.logger = log.New(os.Stderr, "", log.LstdFlags) + testClient.logger = testlog.Logger(t) defer testClient.Shutdown() fm := NewFingerprintManager( diff --git a/client/fs_endpoint_test.go b/client/fs_endpoint_test.go index 09515554b..49d5d7ec5 100644 --- a/client/fs_endpoint_test.go +++ b/client/fs_endpoint_test.go @@ -5,7 +5,6 @@ import ( "fmt" "io" "io/ioutil" - "log" "math" "net" "os" @@ -20,6 +19,7 @@ import ( "github.com/hashicorp/nomad/client/config" sframer "github.com/hashicorp/nomad/client/lib/streamframer" cstructs "github.com/hashicorp/nomad/client/structs" + "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/helper/uuid" "github.com/hashicorp/nomad/nomad" "github.com/hashicorp/nomad/nomad/mock" @@ -41,7 +41,7 @@ func tempAllocDir(t testing.TB) *allocdir.AllocDir { t.Fatalf("failed to chmod dir: %v", err) } - return allocdir.NewAllocDir(log.New(os.Stderr, "", log.LstdFlags), dir) + return allocdir.NewAllocDir(testlog.Logger(t), dir) } type nopWriteCloser struct { diff --git a/client/servers/manager_internal_test.go b/client/servers/manager_internal_test.go index e6ad03bb3..dc17be1f9 100644 --- a/client/servers/manager_internal_test.go +++ b/client/servers/manager_internal_test.go @@ -2,12 +2,12 @@ package servers import ( "fmt" - "log" "math/rand" "net" - "os" "testing" "time" + + "github.com/hashicorp/nomad/helper/testlog" ) func init() { @@ -36,14 +36,14 @@ func (cp *fauxConnPool) Ping(net.Addr) error { } func testManager(t *testing.T) (m *Manager) { - logger := log.New(os.Stderr, "", 0) + logger := testlog.Logger(t) shutdownCh := make(chan struct{}) m = New(logger, shutdownCh, &fauxConnPool{}) return m } -func testManagerFailProb(failPct float64) (m *Manager) { - logger := log.New(os.Stderr, "", 0) +func testManagerFailProb(t *testing.T, failPct float64) (m *Manager) { + logger := testlog.Logger(t) shutdownCh := make(chan struct{}) m = New(logger, shutdownCh, &fauxConnPool{failPct: failPct}) return m @@ -136,7 +136,7 @@ func TestManagerInternal_refreshServerRebalanceTimer(t *testing.T) { {1000000, 19, 10 * time.Minute}, } - logger := log.New(os.Stderr, "", log.LstdFlags) + logger := testlog.Logger(t) shutdownCh := make(chan struct{}) for _, s := range clusters { diff --git a/client/servers/manager_test.go b/client/servers/manager_test.go index 33d76469b..235064797 100644 --- a/client/servers/manager_test.go +++ b/client/servers/manager_test.go @@ -2,10 +2,8 @@ package servers_test import ( "fmt" - "log" "math/rand" "net" - "os" "strings" "testing" @@ -115,7 +113,7 @@ func TestServers_FindServer(t *testing.T) { } func TestServers_New(t *testing.T) { - logger := log.New(os.Stderr, "", log.LstdFlags) + logger := testlog.Logger(t) shutdownCh := make(chan struct{}) m := servers.New(logger, shutdownCh, &fauxConnPool{}) if m == nil { diff --git a/client/stats/cpu_test.go b/client/stats/cpu_test.go index b6d9f1d27..b963d91a6 100644 --- a/client/stats/cpu_test.go +++ b/client/stats/cpu_test.go @@ -1,13 +1,13 @@ package stats import ( - "log" "math" "os" "testing" "time" shelpers "github.com/hashicorp/nomad/helper/stats" + "github.com/hashicorp/nomad/helper/testlog" "github.com/stretchr/testify/assert" ) @@ -26,7 +26,7 @@ func TestHostStats_CPU(t *testing.T) { assert := assert.New(t) assert.Nil(shelpers.Init()) - logger := log.New(os.Stderr, "", log.LstdFlags|log.Lmicroseconds) + logger := testlog.Logger(t) cwd, err := os.Getwd() assert.Nil(err) hs := NewHostStatsCollector(logger, cwd) diff --git a/client/vaultclient/vaultclient_test.go b/client/vaultclient/vaultclient_test.go index 98fd7af99..faa9c6695 100644 --- a/client/vaultclient/vaultclient_test.go +++ b/client/vaultclient/vaultclient_test.go @@ -1,13 +1,12 @@ package vaultclient import ( - "log" - "os" "strings" "testing" "time" "github.com/hashicorp/nomad/client/config" + "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/testutil" vaultapi "github.com/hashicorp/vault/api" ) @@ -17,7 +16,7 @@ func TestVaultClient_TokenRenewals(t *testing.T) { v := testutil.NewTestVault(t) defer v.Stop() - logger := log.New(os.Stderr, "TEST: ", log.Lshortfile|log.LstdFlags) + logger := testlog.Logger(t) v.Config.ConnectionRetryIntv = 100 * time.Millisecond v.Config.TaskTokenTTL = "4s" c, err := NewVaultClient(v.Config, logger, nil) @@ -101,7 +100,7 @@ func TestVaultClient_Heap(t *testing.T) { conf.VaultConfig.Token = "testvaulttoken" conf.VaultConfig.TaskTokenTTL = "10s" - logger := log.New(os.Stderr, "TEST: ", log.Lshortfile|log.LstdFlags) + logger := testlog.Logger(t) c, err := NewVaultClient(conf.VaultConfig, logger, nil) if err != nil { t.Fatal(err) @@ -204,7 +203,7 @@ func TestVaultClient_RenewNonRenewableLease(t *testing.T) { v := testutil.NewTestVault(t) defer v.Stop() - logger := log.New(os.Stderr, "TEST: ", log.Lshortfile|log.LstdFlags) + logger := testlog.Logger(t) v.Config.ConnectionRetryIntv = 100 * time.Millisecond v.Config.TaskTokenTTL = "4s" c, err := NewVaultClient(v.Config, logger, nil) @@ -253,7 +252,7 @@ func TestVaultClient_RenewNonexistentLease(t *testing.T) { v := testutil.NewTestVault(t) defer v.Stop() - logger := log.New(os.Stderr, "TEST: ", log.Lshortfile|log.LstdFlags) + logger := testlog.Logger(t) v.Config.ConnectionRetryIntv = 100 * time.Millisecond v.Config.TaskTokenTTL = "4s" c, err := NewVaultClient(v.Config, logger, nil) diff --git a/command/agent/agent_test.go b/command/agent/agent_test.go index 89c556808..c7377152a 100644 --- a/command/agent/agent_test.go +++ b/command/agent/agent_test.go @@ -2,7 +2,6 @@ package agent import ( "io/ioutil" - "log" "os" "path/filepath" "strings" @@ -11,6 +10,7 @@ import ( cstructs "github.com/hashicorp/nomad/client/structs" "github.com/hashicorp/nomad/helper" + "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/nomad/structs" sconfig "github.com/hashicorp/nomad/nomad/structs/config" "github.com/stretchr/testify/assert" @@ -333,10 +333,7 @@ func TestAget_Client_TelemetryConfiguration(t *testing.T) { // API health check depending on configuration. func TestAgent_HTTPCheck(t *testing.T) { t.Parallel() - logger := log.New(ioutil.Discard, "", 0) - if testing.Verbose() { - logger = log.New(os.Stdout, "[TestAgent_HTTPCheck] ", log.Lshortfile) - } + logger := testlog.Logger(t) agent := func() *Agent { return &Agent{ logger: logger, @@ -417,14 +414,11 @@ func TestAgent_HTTPCheckPath(t *testing.T) { // Agent.agentHTTPCheck only needs a config and logger a := &Agent{ config: DevConfig(), - logger: log.New(ioutil.Discard, "", 0), + logger: testlog.Logger(t), } if err := a.config.normalizeAddrs(); err != nil { t.Fatalf("error normalizing config: %v", err) } - if testing.Verbose() { - a.logger = log.New(os.Stderr, "", log.LstdFlags) - } // Assert server check uses /v1/agent/health?type=server isServer := true @@ -638,7 +632,7 @@ func TestServer_Reload_TLS_WithNilConfiguration(t *testing.T) { t.Parallel() assert := assert.New(t) - logger := log.New(ioutil.Discard, "", 0) + logger := testlog.Logger(t) agent := &Agent{ logger: logger, @@ -662,7 +656,7 @@ func TestServer_Reload_TLS_UpgradeToTLS(t *testing.T) { dir := tmpDir(t) defer os.RemoveAll(dir) - logger := log.New(ioutil.Discard, "", 0) + logger := testlog.Logger(t) agentConfig := &Config{ TLSConfig: &sconfig.TLSConfig{}, @@ -704,7 +698,7 @@ func TestServer_Reload_TLS_DowngradeFromTLS(t *testing.T) { dir := tmpDir(t) defer os.RemoveAll(dir) - logger := log.New(ioutil.Discard, "", 0) + logger := testlog.Logger(t) agentConfig := &Config{ TLSConfig: &sconfig.TLSConfig{ @@ -927,7 +921,7 @@ func TestServer_ShouldReload_ReturnTrueForFileChanges(t *testing.T) { content := []byte(oldCertificate) dir, err := ioutil.TempDir("", "certificate") if err != nil { - log.Fatal(err) + t.Fatal(err) } defer os.RemoveAll(dir) // clean up @@ -940,7 +934,7 @@ func TestServer_ShouldReload_ReturnTrueForFileChanges(t *testing.T) { key = "../../helper/tlsutil/testdata/nomad-foo-key.pem" ) - logger := log.New(ioutil.Discard, "", 0) + logger := testlog.Logger(t) agentConfig := &Config{ TLSConfig: &sconfig.TLSConfig{ diff --git a/command/agent/consul/int_test.go b/command/agent/consul/int_test.go index 29db75326..fb8c06cd9 100644 --- a/command/agent/consul/int_test.go +++ b/command/agent/consul/int_test.go @@ -2,7 +2,6 @@ package consul_test import ( "io/ioutil" - "log" "os" "path/filepath" "testing" @@ -16,18 +15,12 @@ import ( "github.com/hashicorp/nomad/client/config" "github.com/hashicorp/nomad/client/vaultclient" "github.com/hashicorp/nomad/command/agent/consul" + "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/nomad/mock" "github.com/hashicorp/nomad/nomad/structs" "github.com/stretchr/testify/assert" ) -func testLogger() *log.Logger { - if testing.Verbose() { - return log.New(os.Stderr, "", log.LstdFlags) - } - return log.New(ioutil.Discard, "", 0) -} - // TestConsul_Integration asserts TaskRunner properly registers and deregisters // services and checks with Consul using an embedded Consul agent. func TestConsul_Integration(t *testing.T) { @@ -129,7 +122,7 @@ func TestConsul_Integration(t *testing.T) { }, } - logger := testLogger() + logger := testlog.Logger(t) logUpdate := func(name, state string, event *structs.TaskEvent, lazySync bool) { logger.Printf("[TEST] test.updater: name=%q state=%q event=%v", name, state, event) } diff --git a/command/agent/retry_join_test.go b/command/agent/retry_join_test.go index 596f7b046..153eed04f 100644 --- a/command/agent/retry_join_test.go +++ b/command/agent/retry_join_test.go @@ -2,12 +2,12 @@ package agent import ( "fmt" - "io/ioutil" "log" "os" "testing" "time" + "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/testutil" "github.com/mitchellh/cli" "github.com/stretchr/testify/require" @@ -92,7 +92,7 @@ func TestRetryJoin_Server_NonCloud(t *testing.T) { discover: &MockDiscover{}, serverJoin: mockJoin, serverEnabled: true, - logger: log.New(ioutil.Discard, "", 0), + logger: testlog.Logger(t), errCh: make(chan struct{}), } @@ -123,7 +123,7 @@ func TestRetryJoin_Server_Cloud(t *testing.T) { discover: mockDiscover, serverJoin: mockJoin, serverEnabled: true, - logger: log.New(ioutil.Discard, "", 0), + logger: testlog.Logger(t), errCh: make(chan struct{}), } @@ -155,7 +155,7 @@ func TestRetryJoin_Server_MixedProvider(t *testing.T) { discover: mockDiscover, serverJoin: mockJoin, serverEnabled: true, - logger: log.New(ioutil.Discard, "", 0), + logger: testlog.Logger(t), errCh: make(chan struct{}), } @@ -186,7 +186,7 @@ func TestRetryJoin_Client(t *testing.T) { discover: &MockDiscover{}, clientJoin: mockJoin, clientEnabled: true, - logger: log.New(ioutil.Discard, "", 0), + logger: testlog.Logger(t), errCh: make(chan struct{}), } diff --git a/nomad/deploymentwatcher/deployments_watcher_test.go b/nomad/deploymentwatcher/deployments_watcher_test.go index 1221a7a04..b86ef0ca5 100644 --- a/nomad/deploymentwatcher/deployments_watcher_test.go +++ b/nomad/deploymentwatcher/deployments_watcher_test.go @@ -7,6 +7,7 @@ import ( memdb "github.com/hashicorp/go-memdb" "github.com/hashicorp/nomad/helper" + "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/helper/uuid" "github.com/hashicorp/nomad/nomad/mock" "github.com/hashicorp/nomad/nomad/structs" @@ -18,7 +19,7 @@ import ( func testDeploymentWatcher(t *testing.T, qps float64, batchDur time.Duration) (*Watcher, *mockBackend) { m := newMockBackend(t) - w := NewDeploymentsWatcher(testLogger(), m, qps, batchDur) + w := NewDeploymentsWatcher(testlog.Logger(t), m, qps, batchDur) return w, m } diff --git a/nomad/deploymentwatcher/testutil_test.go b/nomad/deploymentwatcher/testutil_test.go index 96753a758..73ea07ae0 100644 --- a/nomad/deploymentwatcher/testutil_test.go +++ b/nomad/deploymentwatcher/testutil_test.go @@ -1,8 +1,6 @@ package deploymentwatcher import ( - "log" - "os" "reflect" "strings" "sync" @@ -13,10 +11,6 @@ import ( mocker "github.com/stretchr/testify/mock" ) -func testLogger() *log.Logger { - return log.New(os.Stderr, "", log.LstdFlags|log.Lmicroseconds) -} - type mockBackend struct { mocker.Mock index uint64 @@ -125,17 +119,14 @@ type matchDeploymentStatusUpdateConfig struct { func matchDeploymentStatusUpdateRequest(c *matchDeploymentStatusUpdateConfig) func(args *structs.DeploymentStatusUpdateRequest) bool { return func(args *structs.DeploymentStatusUpdateRequest) bool { if args.DeploymentUpdate.DeploymentID != c.DeploymentID { - testLogger().Printf("deployment ids dont match") return false } if args.DeploymentUpdate.Status != c.Status && args.DeploymentUpdate.StatusDescription != c.StatusDescription { - testLogger().Printf("status's dont match") return false } if c.Eval && args.Eval == nil || !c.Eval && args.Eval != nil { - testLogger().Printf("evals dont match") return false } diff --git a/nomad/fsm.go b/nomad/fsm.go index d507ebf9b..0ef79d909 100644 --- a/nomad/fsm.go +++ b/nomad/fsm.go @@ -135,7 +135,7 @@ func NewFSM(config *FSMConfig) (*nomadFSM, error) { evalBroker: config.EvalBroker, periodicDispatcher: config.Periodic, blockedEvals: config.Blocked, - logger: log.New(config.LogOutput, "", log.LstdFlags), + logger: log.New(config.LogOutput, "", log.LstdFlags|log.Lmicroseconds), config: config, state: state, timetable: NewTimeTable(timeTableGranularity, timeTableLimit), diff --git a/nomad/fsm_test.go b/nomad/fsm_test.go index 418fd7842..f2fa2d1cf 100644 --- a/nomad/fsm_test.go +++ b/nomad/fsm_test.go @@ -47,7 +47,7 @@ func testStateStore(t *testing.T) *state.StateStore { func testFSM(t *testing.T) *nomadFSM { broker := testBroker(t, 0) - dispatcher, _ := testPeriodicDispatcher() + dispatcher, _ := testPeriodicDispatcher(t) fsmConfig := &FSMConfig{ EvalBroker: broker, Periodic: dispatcher, diff --git a/nomad/periodic_test.go b/nomad/periodic_test.go index f2c9b8a52..a4f56cb56 100644 --- a/nomad/periodic_test.go +++ b/nomad/periodic_test.go @@ -2,9 +2,7 @@ package nomad import ( "fmt" - "log" "math/rand" - "os" "reflect" "sort" "strconv" @@ -13,6 +11,7 @@ import ( "testing" "time" + "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/nomad/mock" "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/testutil" @@ -78,8 +77,8 @@ func (t times) Less(i, j int) bool { return t[i].Before(t[j]) } // testPeriodicDispatcher returns an enabled PeriodicDispatcher which uses the // MockJobEvalDispatcher. -func testPeriodicDispatcher() (*PeriodicDispatch, *MockJobEvalDispatcher) { - logger := log.New(os.Stderr, "", log.LstdFlags) +func testPeriodicDispatcher(t *testing.T) (*PeriodicDispatch, *MockJobEvalDispatcher) { + logger := testlog.Logger(t) m := NewMockJobEvalDispatcher() d := NewPeriodicDispatch(logger, m) d.SetEnabled(true) @@ -105,7 +104,7 @@ func testPeriodicJob(times ...time.Time) *structs.Job { // This tests the reported issue: https://github.com/hashicorp/nomad/issues/2829 func TestPeriodicDispatch_SetEnabled(t *testing.T) { t.Parallel() - p, _ := testPeriodicDispatcher() + p, _ := testPeriodicDispatcher(t) // SetEnabled has been called once but do it again. p.SetEnabled(true) @@ -128,7 +127,7 @@ func TestPeriodicDispatch_SetEnabled(t *testing.T) { func TestPeriodicDispatch_Add_NonPeriodic(t *testing.T) { t.Parallel() - p, _ := testPeriodicDispatcher() + p, _ := testPeriodicDispatcher(t) job := mock.Job() if err := p.Add(job); err != nil { t.Fatalf("Add of non-periodic job failed: %v; expect no-op", err) @@ -142,7 +141,7 @@ func TestPeriodicDispatch_Add_NonPeriodic(t *testing.T) { func TestPeriodicDispatch_Add_Periodic_Parameterized(t *testing.T) { t.Parallel() - p, _ := testPeriodicDispatcher() + p, _ := testPeriodicDispatcher(t) job := mock.PeriodicJob() job.ParameterizedJob = &structs.ParameterizedJobConfig{} if err := p.Add(job); err != nil { @@ -157,7 +156,7 @@ func TestPeriodicDispatch_Add_Periodic_Parameterized(t *testing.T) { func TestPeriodicDispatch_Add_Periodic_Stopped(t *testing.T) { t.Parallel() - p, _ := testPeriodicDispatcher() + p, _ := testPeriodicDispatcher(t) job := mock.PeriodicJob() job.Stop = true if err := p.Add(job); err != nil { @@ -172,7 +171,7 @@ func TestPeriodicDispatch_Add_Periodic_Stopped(t *testing.T) { func TestPeriodicDispatch_Add_UpdateJob(t *testing.T) { t.Parallel() - p, _ := testPeriodicDispatcher() + p, _ := testPeriodicDispatcher(t) job := mock.PeriodicJob() if err := p.Add(job); err != nil { t.Fatalf("Add failed %v", err) @@ -202,7 +201,7 @@ func TestPeriodicDispatch_Add_UpdateJob(t *testing.T) { func TestPeriodicDispatch_Add_Remove_Namespaced(t *testing.T) { assert := assert.New(t) t.Parallel() - p, _ := testPeriodicDispatcher() + p, _ := testPeriodicDispatcher(t) job := mock.PeriodicJob() job2 := mock.PeriodicJob() job2.Namespace = "test" @@ -219,7 +218,7 @@ func TestPeriodicDispatch_Add_Remove_Namespaced(t *testing.T) { func TestPeriodicDispatch_Add_RemoveJob(t *testing.T) { t.Parallel() - p, _ := testPeriodicDispatcher() + p, _ := testPeriodicDispatcher(t) job := mock.PeriodicJob() if err := p.Add(job); err != nil { t.Fatalf("Add failed %v", err) @@ -244,7 +243,7 @@ func TestPeriodicDispatch_Add_RemoveJob(t *testing.T) { func TestPeriodicDispatch_Add_TriggersUpdate(t *testing.T) { t.Parallel() - p, m := testPeriodicDispatcher() + p, m := testPeriodicDispatcher(t) // Create a job that won't be evaluated for a while. job := testPeriodicJob(time.Now().Add(10 * time.Second)) @@ -287,7 +286,7 @@ func TestPeriodicDispatch_Add_TriggersUpdate(t *testing.T) { func TestPeriodicDispatch_Remove_Untracked(t *testing.T) { t.Parallel() - p, _ := testPeriodicDispatcher() + p, _ := testPeriodicDispatcher(t) if err := p.Remove("ns", "foo"); err != nil { t.Fatalf("Remove failed %v; expected a no-op", err) } @@ -295,7 +294,7 @@ func TestPeriodicDispatch_Remove_Untracked(t *testing.T) { func TestPeriodicDispatch_Remove_Tracked(t *testing.T) { t.Parallel() - p, _ := testPeriodicDispatcher() + p, _ := testPeriodicDispatcher(t) job := mock.PeriodicJob() if err := p.Add(job); err != nil { @@ -319,7 +318,7 @@ func TestPeriodicDispatch_Remove_Tracked(t *testing.T) { func TestPeriodicDispatch_Remove_TriggersUpdate(t *testing.T) { t.Parallel() - p, _ := testPeriodicDispatcher() + p, _ := testPeriodicDispatcher(t) // Create a job that will be evaluated soon. job := testPeriodicJob(time.Now().Add(1 * time.Second)) @@ -349,7 +348,7 @@ func TestPeriodicDispatch_Remove_TriggersUpdate(t *testing.T) { func TestPeriodicDispatch_ForceRun_Untracked(t *testing.T) { t.Parallel() - p, _ := testPeriodicDispatcher() + p, _ := testPeriodicDispatcher(t) if _, err := p.ForceRun("ns", "foo"); err == nil { t.Fatal("ForceRun of untracked job should fail") @@ -358,7 +357,7 @@ func TestPeriodicDispatch_ForceRun_Untracked(t *testing.T) { func TestPeriodicDispatch_ForceRun_Tracked(t *testing.T) { t.Parallel() - p, m := testPeriodicDispatcher() + p, m := testPeriodicDispatcher(t) // Create a job that won't be evaluated for a while. job := testPeriodicJob(time.Now().Add(10 * time.Second)) @@ -387,7 +386,7 @@ func TestPeriodicDispatch_ForceRun_Tracked(t *testing.T) { func TestPeriodicDispatch_Run_DisallowOverlaps(t *testing.T) { t.Parallel() - p, m := testPeriodicDispatcher() + p, m := testPeriodicDispatcher(t) // Create a job that will trigger two launches but disallows overlapping. launch1 := time.Now().Round(1 * time.Second).Add(1 * time.Second) @@ -417,7 +416,7 @@ func TestPeriodicDispatch_Run_DisallowOverlaps(t *testing.T) { func TestPeriodicDispatch_Run_Multiple(t *testing.T) { t.Parallel() - p, m := testPeriodicDispatcher() + p, m := testPeriodicDispatcher(t) // Create a job that will be launched twice. launch1 := time.Now().Round(1 * time.Second).Add(1 * time.Second) @@ -449,7 +448,7 @@ func TestPeriodicDispatch_Run_Multiple(t *testing.T) { func TestPeriodicDispatch_Run_SameTime(t *testing.T) { t.Parallel() - p, m := testPeriodicDispatcher() + p, m := testPeriodicDispatcher(t) // Create two job that will be launched at the same time. launch := time.Now().Round(1 * time.Second).Add(1 * time.Second) @@ -487,7 +486,7 @@ func TestPeriodicDispatch_Run_SameTime(t *testing.T) { func TestPeriodicDispatch_Run_SameID_Different_Namespace(t *testing.T) { t.Parallel() - p, m := testPeriodicDispatcher() + p, m := testPeriodicDispatcher(t) // Create two job that will be launched at the same time. launch := time.Now().Round(1 * time.Second).Add(1 * time.Second) @@ -534,7 +533,7 @@ func TestPeriodicDispatch_Run_SameID_Different_Namespace(t *testing.T) { // behavior. func TestPeriodicDispatch_Complex(t *testing.T) { t.Parallel() - p, m := testPeriodicDispatcher() + p, m := testPeriodicDispatcher(t) // Create some jobs launching at different times. now := time.Now().Round(1 * time.Second) diff --git a/nomad/state/state_store.go b/nomad/state/state_store.go index ac88328b9..a1e25b8f8 100644 --- a/nomad/state/state_store.go +++ b/nomad/state/state_store.go @@ -69,7 +69,7 @@ func NewStateStore(config *StateStoreConfig) (*StateStore, error) { // Create the state store s := &StateStore{ - logger: log.New(config.LogOutput, "", log.LstdFlags), + logger: log.New(config.LogOutput, "", log.LstdFlags|log.Lmicroseconds), db: db, config: config, abandonCh: make(chan struct{}), diff --git a/nomad/testing.go b/nomad/testing.go index 2859dfb63..9b81f458d 100644 --- a/nomad/testing.go +++ b/nomad/testing.go @@ -2,7 +2,6 @@ package nomad import ( "fmt" - "log" "math/rand" "net" "sync/atomic" @@ -77,7 +76,7 @@ func TestServer(t testing.T, cb func(*Config)) *Server { // Enable raft as leader if we have bootstrap on config.RaftConfig.StartAsLeader = !config.DevDisableBootstrap - logger := log.New(config.LogOutput, fmt.Sprintf("[%s] ", config.NodeName), log.LstdFlags) + logger := testlog.WithPrefix(t, fmt.Sprintf("[%s] ", config.NodeName)) catalog := consul.NewMockCatalog(logger) for i := 10; i >= 0; i-- { diff --git a/nomad/vault_test.go b/nomad/vault_test.go index 5ba75f4da..c6368b981 100644 --- a/nomad/vault_test.go +++ b/nomad/vault_test.go @@ -4,9 +4,7 @@ import ( "context" "encoding/json" "fmt" - "log" "math/rand" - "os" "reflect" "strings" "testing" @@ -15,6 +13,7 @@ import ( "golang.org/x/time/rate" "github.com/hashicorp/nomad/helper" + "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/helper/uuid" "github.com/hashicorp/nomad/nomad/mock" "github.com/hashicorp/nomad/nomad/structs" @@ -150,7 +149,7 @@ func testVaultRoleAndToken(v *testutil.TestVault, t *testing.T, vaultPolicies ma func TestVaultClient_BadConfig(t *testing.T) { t.Parallel() conf := &config.VaultConfig{} - logger := log.New(os.Stderr, "", log.LstdFlags) + logger := testlog.Logger(t) // Should be no error since Vault is not enabled _, err := NewVaultClient(nil, logger, nil) @@ -179,7 +178,7 @@ func TestVaultClient_EstablishConnection(t *testing.T) { t.Parallel() for i := 10; i >= 0; i-- { v := testutil.NewTestVaultDelayed(t) - logger := log.New(os.Stderr, "", log.LstdFlags) + logger := testlog.Logger(t) v.Config.ConnectionRetryIntv = 100 * time.Millisecond client, err := NewVaultClient(v.Config, logger, nil) if err != nil { @@ -247,7 +246,7 @@ func TestVaultClient_ValidateRole(t *testing.T) { } v.Config.Token = testVaultRoleAndToken(v, t, vaultPolicies, data, nil) - logger := log.New(os.Stderr, "", log.LstdFlags) + logger := testlog.Logger(t) v.Config.ConnectionRetryIntv = 100 * time.Millisecond client, err := NewVaultClient(v.Config, logger, nil) if err != nil { @@ -286,7 +285,7 @@ func TestVaultClient_ValidateRole_NonExistant(t *testing.T) { v.Config.Token = defaultTestVaultWhitelistRoleAndToken(v, t, 5) v.Config.Token = v.RootToken - logger := log.New(os.Stderr, "", log.LstdFlags) + logger := testlog.Logger(t) v.Config.ConnectionRetryIntv = 100 * time.Millisecond v.Config.Role = "test-nonexistent" client, err := NewVaultClient(v.Config, logger, nil) @@ -335,7 +334,7 @@ func TestVaultClient_ValidateToken(t *testing.T) { } v.Config.Token = testVaultRoleAndToken(v, t, vaultPolicies, data, []string{"token-lookup", "nomad-role-create"}) - logger := log.New(os.Stderr, "", log.LstdFlags) + logger := testlog.Logger(t) v.Config.ConnectionRetryIntv = 100 * time.Millisecond client, err := NewVaultClient(v.Config, logger, nil) if err != nil { @@ -378,7 +377,7 @@ func TestVaultClient_SetActive(t *testing.T) { v := testutil.NewTestVault(t) defer v.Stop() - logger := log.New(os.Stderr, "", log.LstdFlags) + logger := testlog.Logger(t) client, err := NewVaultClient(v.Config, logger, nil) if err != nil { t.Fatalf("failed to build vault client: %v", err) @@ -414,7 +413,7 @@ func TestVaultClient_SetConfig(t *testing.T) { // Set the configs token in a new test role v2.Config.Token = defaultTestVaultWhitelistRoleAndToken(v2, t, 20) - logger := log.New(os.Stderr, "", log.LstdFlags) + logger := testlog.Logger(t) client, err := NewVaultClient(v.Config, logger, nil) if err != nil { t.Fatalf("failed to build vault client: %v", err) @@ -470,7 +469,7 @@ func TestVaultClient_SetConfig_Disable(t *testing.T) { v := testutil.NewTestVault(t) defer v.Stop() - logger := log.New(os.Stderr, "", log.LstdFlags) + logger := testlog.Logger(t) client, err := NewVaultClient(v.Config, logger, nil) if err != nil { t.Fatalf("failed to build vault client: %v", err) @@ -508,7 +507,7 @@ func TestVaultClient_RenewalLoop(t *testing.T) { v.Config.Token = defaultTestVaultWhitelistRoleAndToken(v, t, 5) // Start the client - logger := log.New(os.Stderr, "", log.LstdFlags) + logger := testlog.Logger(t) client, err := NewVaultClient(v.Config, logger, nil) if err != nil { t.Fatalf("failed to build vault client: %v", err) @@ -566,7 +565,7 @@ func TestVaultClient_LookupToken_Invalid(t *testing.T) { } // Enable vault but use a bad address so it never establishes a conn - logger := log.New(os.Stderr, "", log.LstdFlags) + logger := testlog.Logger(t) client, err := NewVaultClient(conf, logger, nil) if err != nil { t.Fatalf("failed to build vault client: %v", err) @@ -585,7 +584,7 @@ func TestVaultClient_LookupToken_Root(t *testing.T) { v := testutil.NewTestVault(t) defer v.Stop() - logger := log.New(os.Stderr, "", log.LstdFlags) + logger := testlog.Logger(t) client, err := NewVaultClient(v.Config, logger, nil) if err != nil { t.Fatalf("failed to build vault client: %v", err) @@ -650,7 +649,7 @@ func TestVaultClient_LookupToken_Role(t *testing.T) { // Set the configs token in a new test role v.Config.Token = defaultTestVaultWhitelistRoleAndToken(v, t, 5) - logger := log.New(os.Stderr, "", log.LstdFlags) + logger := testlog.Logger(t) client, err := NewVaultClient(v.Config, logger, nil) if err != nil { t.Fatalf("failed to build vault client: %v", err) @@ -712,7 +711,7 @@ func TestVaultClient_LookupToken_RateLimit(t *testing.T) { v := testutil.NewTestVault(t) defer v.Stop() - logger := log.New(os.Stderr, "", log.LstdFlags) + logger := testlog.Logger(t) client, err := NewVaultClient(v.Config, logger, nil) if err != nil { t.Fatalf("failed to build vault client: %v", err) @@ -772,7 +771,7 @@ func TestVaultClient_CreateToken_Root(t *testing.T) { v := testutil.NewTestVault(t) defer v.Stop() - logger := log.New(os.Stderr, "", log.LstdFlags) + logger := testlog.Logger(t) client, err := NewVaultClient(v.Config, logger, nil) if err != nil { t.Fatalf("failed to build vault client: %v", err) @@ -820,7 +819,7 @@ func TestVaultClient_CreateToken_Whitelist_Role(t *testing.T) { v.Config.Token = defaultTestVaultWhitelistRoleAndToken(v, t, 5) // Start the client - logger := log.New(os.Stderr, "", log.LstdFlags) + logger := testlog.Logger(t) client, err := NewVaultClient(v.Config, logger, nil) if err != nil { t.Fatalf("failed to build vault client: %v", err) @@ -871,7 +870,7 @@ func TestVaultClient_CreateToken_Root_Target_Role(t *testing.T) { v.Config.Role = "test" // Start the client - logger := log.New(os.Stderr, "", log.LstdFlags) + logger := testlog.Logger(t) client, err := NewVaultClient(v.Config, logger, nil) if err != nil { t.Fatalf("failed to build vault client: %v", err) @@ -930,7 +929,7 @@ func TestVaultClient_CreateToken_Blacklist_Role(t *testing.T) { v.Config.Role = "test" // Start the client - logger := log.New(os.Stderr, "", log.LstdFlags) + logger := testlog.Logger(t) client, err := NewVaultClient(v.Config, logger, nil) if err != nil { t.Fatalf("failed to build vault client: %v", err) @@ -979,7 +978,7 @@ func TestVaultClient_CreateToken_Role_InvalidToken(t *testing.T) { v.Config.Token = "foo-bar" // Start the client - logger := log.New(os.Stderr, "", log.LstdFlags) + logger := testlog.Logger(t) client, err := NewVaultClient(v.Config, logger, nil) if err != nil { t.Fatalf("failed to build vault client: %v", err) @@ -1017,7 +1016,7 @@ func TestVaultClient_CreateToken_Role_Unrecoverable(t *testing.T) { v.Config.Token = defaultTestVaultWhitelistRoleAndToken(v, t, 5) // Start the client - logger := log.New(os.Stderr, "", log.LstdFlags) + logger := testlog.Logger(t) client, err := NewVaultClient(v.Config, logger, nil) if err != nil { t.Fatalf("failed to build vault client: %v", err) @@ -1051,7 +1050,7 @@ func TestVaultClient_CreateToken_Prestart(t *testing.T) { Addr: "http://127.0.0.1:0", } - logger := log.New(os.Stderr, "", log.LstdFlags) + logger := testlog.Logger(t) client, err := NewVaultClient(vconfig, logger, nil) if err != nil { t.Fatalf("failed to build vault client: %v", err) @@ -1083,7 +1082,7 @@ func TestVaultClient_RevokeTokens_PreEstablishs(t *testing.T) { Token: uuid.Generate(), Addr: "http://127.0.0.1:0", } - logger := log.New(os.Stderr, "", log.LstdFlags) + logger := testlog.Logger(t) client, err := NewVaultClient(vconfig, logger, nil) if err != nil { t.Fatalf("failed to build vault client: %v", err) @@ -1131,7 +1130,7 @@ func TestVaultClient_RevokeTokens_Root(t *testing.T) { return nil } - logger := log.New(os.Stderr, "", log.LstdFlags) + logger := testlog.Logger(t) client, err := NewVaultClient(v.Config, logger, purge) if err != nil { t.Fatalf("failed to build vault client: %v", err) @@ -1199,7 +1198,7 @@ func TestVaultClient_RevokeTokens_Role(t *testing.T) { return nil } - logger := log.New(os.Stderr, "", log.LstdFlags) + logger := testlog.Logger(t) client, err := NewVaultClient(v.Config, logger, purge) if err != nil { t.Fatalf("failed to build vault client: %v", err) diff --git a/scheduler/context_test.go b/scheduler/context_test.go index 4de024bbf..b499ff281 100644 --- a/scheduler/context_test.go +++ b/scheduler/context_test.go @@ -1,11 +1,10 @@ package scheduler import ( - "log" - "os" "reflect" "testing" + "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/helper/uuid" "github.com/hashicorp/nomad/nomad/mock" "github.com/hashicorp/nomad/nomad/state" @@ -19,7 +18,7 @@ func testContext(t testing.TB) (*state.StateStore, *EvalContext) { NodeAllocation: make(map[string][]*structs.Allocation), } - logger := log.New(os.Stderr, "", log.LstdFlags) + logger := testlog.Logger(t) ctx := NewEvalContext(state, plan, logger) return state, ctx diff --git a/scheduler/reconcile_test.go b/scheduler/reconcile_test.go index 5e039a7a9..84fbeb0ff 100644 --- a/scheduler/reconcile_test.go +++ b/scheduler/reconcile_test.go @@ -2,8 +2,6 @@ package scheduler import ( "fmt" - "log" - "os" "reflect" "regexp" "strconv" @@ -11,6 +9,7 @@ import ( "time" "github.com/hashicorp/nomad/helper" + "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/helper/uuid" "github.com/hashicorp/nomad/nomad/mock" "github.com/hashicorp/nomad/nomad/structs" @@ -38,10 +37,6 @@ var ( } ) -func testLogger() *log.Logger { - return log.New(os.Stderr, "", log.LstdFlags) -} - func allocUpdateFnIgnore(*structs.Allocation, *structs.Job, *structs.TaskGroup) (bool, bool, *structs.Allocation) { return true, false, nil } @@ -283,7 +278,7 @@ func assertResults(t *testing.T, r *reconcileResults, exp *resultExpectation) { // existing allocations func TestReconciler_Place_NoExisting(t *testing.T) { job := mock.Job() - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnIgnore, false, job.ID, job, nil, nil, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnIgnore, false, job.ID, job, nil, nil, nil, "") r := reconciler.Compute() // Assert the correct results @@ -319,7 +314,7 @@ func TestReconciler_Place_Existing(t *testing.T) { allocs = append(allocs, alloc) } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, nil, "") r := reconciler.Compute() // Assert the correct results @@ -357,7 +352,7 @@ func TestReconciler_ScaleDown_Partial(t *testing.T) { allocs = append(allocs, alloc) } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, nil, "") r := reconciler.Compute() // Assert the correct results @@ -396,7 +391,7 @@ func TestReconciler_ScaleDown_Zero(t *testing.T) { allocs = append(allocs, alloc) } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, nil, "") r := reconciler.Compute() // Assert the correct results @@ -436,7 +431,7 @@ func TestReconciler_ScaleDown_Zero_DuplicateNames(t *testing.T) { expectedStopped = append(expectedStopped, i%2) } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, nil, "") r := reconciler.Compute() // Assert the correct results @@ -471,7 +466,7 @@ func TestReconciler_Inplace(t *testing.T) { allocs = append(allocs, alloc) } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnInplace, false, job.ID, job, nil, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnInplace, false, job.ID, job, nil, allocs, nil, "") r := reconciler.Compute() // Assert the correct results @@ -509,7 +504,7 @@ func TestReconciler_Inplace_ScaleUp(t *testing.T) { allocs = append(allocs, alloc) } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnInplace, false, job.ID, job, nil, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnInplace, false, job.ID, job, nil, allocs, nil, "") r := reconciler.Compute() // Assert the correct results @@ -549,7 +544,7 @@ func TestReconciler_Inplace_ScaleDown(t *testing.T) { allocs = append(allocs, alloc) } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnInplace, false, job.ID, job, nil, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnInplace, false, job.ID, job, nil, allocs, nil, "") r := reconciler.Compute() // Assert the correct results @@ -586,7 +581,7 @@ func TestReconciler_Destructive(t *testing.T) { allocs = append(allocs, alloc) } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnDestructive, false, job.ID, job, nil, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnDestructive, false, job.ID, job, nil, allocs, nil, "") r := reconciler.Compute() // Assert the correct results @@ -622,7 +617,7 @@ func TestReconciler_Destructive_ScaleUp(t *testing.T) { allocs = append(allocs, alloc) } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnDestructive, false, job.ID, job, nil, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnDestructive, false, job.ID, job, nil, allocs, nil, "") r := reconciler.Compute() // Assert the correct results @@ -661,7 +656,7 @@ func TestReconciler_Destructive_ScaleDown(t *testing.T) { allocs = append(allocs, alloc) } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnDestructive, false, job.ID, job, nil, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnDestructive, false, job.ID, job, nil, allocs, nil, "") r := reconciler.Compute() // Assert the correct results @@ -706,7 +701,7 @@ func TestReconciler_LostNode(t *testing.T) { tainted[n.ID] = n } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, tainted, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, tainted, "") r := reconciler.Compute() // Assert the correct results @@ -756,7 +751,7 @@ func TestReconciler_LostNode_ScaleUp(t *testing.T) { tainted[n.ID] = n } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, tainted, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, tainted, "") r := reconciler.Compute() // Assert the correct results @@ -806,7 +801,7 @@ func TestReconciler_LostNode_ScaleDown(t *testing.T) { tainted[n.ID] = n } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, tainted, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, tainted, "") r := reconciler.Compute() // Assert the correct results @@ -852,7 +847,7 @@ func TestReconciler_DrainNode(t *testing.T) { tainted[n.ID] = n } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, tainted, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, tainted, "") r := reconciler.Compute() // Assert the correct results @@ -905,7 +900,7 @@ func TestReconciler_DrainNode_ScaleUp(t *testing.T) { tainted[n.ID] = n } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, tainted, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, tainted, "") r := reconciler.Compute() // Assert the correct results @@ -959,7 +954,7 @@ func TestReconciler_DrainNode_ScaleDown(t *testing.T) { tainted[n.ID] = n } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, tainted, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, tainted, "") r := reconciler.Compute() // Assert the correct results @@ -1004,7 +999,7 @@ func TestReconciler_RemovedTG(t *testing.T) { newName := "different" job.TaskGroups[0].Name = newName - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, nil, "") r := reconciler.Compute() // Assert the correct results @@ -1066,7 +1061,7 @@ func TestReconciler_JobStopped(t *testing.T) { allocs = append(allocs, alloc) } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnIgnore, false, c.jobID, c.job, nil, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnIgnore, false, c.jobID, c.job, nil, allocs, nil, "") r := reconciler.Compute() // Assert the correct results @@ -1106,7 +1101,7 @@ func TestReconciler_MultiTG(t *testing.T) { allocs = append(allocs, alloc) } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, nil, "") r := reconciler.Compute() // Assert the correct results @@ -1158,7 +1153,7 @@ func TestReconciler_MultiTG_SingleUpdateStanza(t *testing.T) { DesiredTotal: 10, } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnIgnore, false, job.ID, job, d, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnIgnore, false, job.ID, job, d, allocs, nil, "") r := reconciler.Compute() // Assert the correct results @@ -1234,7 +1229,7 @@ func TestReconciler_RescheduleLater_Batch(t *testing.T) { // Mark one as complete allocs[5].ClientStatus = structs.AllocClientStatusComplete - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnIgnore, true, job.ID, job, nil, allocs, nil, uuid.Generate()) + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnIgnore, true, job.ID, job, nil, allocs, nil, uuid.Generate()) r := reconciler.Compute() // Two reschedule attempts were already made, one more can be made at a future time @@ -1313,7 +1308,7 @@ func TestReconciler_RescheduleLaterWithBatchedEvals_Batch(t *testing.T) { FinishedAt: now.Add(10 * time.Second)}} } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnIgnore, true, job.ID, job, nil, allocs, nil, uuid.Generate()) + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnIgnore, true, job.ID, job, nil, allocs, nil, uuid.Generate()) r := reconciler.Compute() // Verify that two follow up evals were created @@ -1406,7 +1401,7 @@ func TestReconciler_RescheduleNow_Batch(t *testing.T) { // Mark one as complete allocs[5].ClientStatus = structs.AllocClientStatusComplete - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnIgnore, true, job.ID, job, nil, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnIgnore, true, job.ID, job, nil, allocs, nil, "") reconciler.now = now r := reconciler.Compute() @@ -1480,7 +1475,7 @@ func TestReconciler_RescheduleLater_Service(t *testing.T) { // Mark one as desired state stop allocs[4].DesiredStatus = structs.AllocDesiredStatusStop - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, nil, uuid.Generate()) + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, nil, uuid.Generate()) r := reconciler.Compute() // Should place a new placement and create a follow up eval for the delayed reschedule @@ -1548,7 +1543,7 @@ func TestReconciler_Service_ClientStatusComplete(t *testing.T) { // Mark one as client status complete allocs[4].ClientStatus = structs.AllocClientStatusComplete - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, nil, "") r := reconciler.Compute() // Should place a new placement for the alloc that was marked complete @@ -1604,7 +1599,7 @@ func TestReconciler_Service_DesiredStop_ClientStatusComplete(t *testing.T) { allocs[4].ClientStatus = structs.AllocClientStatusFailed allocs[4].DesiredStatus = structs.AllocDesiredStatusStop - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, nil, "") r := reconciler.Compute() // Should place a new placement for the alloc that was marked stopped @@ -1681,7 +1676,7 @@ func TestReconciler_RescheduleNow_Service(t *testing.T) { // Mark one as desired state stop allocs[4].DesiredStatus = structs.AllocDesiredStatusStop - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, nil, "") r := reconciler.Compute() // Verify that no follow up evals were created @@ -1758,7 +1753,7 @@ func TestReconciler_RescheduleNow_WithinAllowedTimeWindow(t *testing.T) { FinishedAt: now.Add(-4 * time.Second)}} allocs[1].ClientStatus = structs.AllocClientStatusFailed - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, nil, "") reconciler.now = now r := reconciler.Compute() @@ -1838,7 +1833,7 @@ func TestReconciler_RescheduleNow_EvalIDMatch(t *testing.T) { allocs[1].ClientStatus = structs.AllocClientStatusFailed allocs[1].FollowupEvalID = evalID - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, nil, evalID) + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, nil, evalID) reconciler.now = now.Add(-30 * time.Second) r := reconciler.Compute() @@ -1946,7 +1941,7 @@ func TestReconciler_RescheduleNow_Service_WithCanaries(t *testing.T) { allocs = append(allocs, alloc) } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnIgnore, false, job.ID, job2, d, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnIgnore, false, job.ID, job2, d, allocs, nil, "") r := reconciler.Compute() // Verify that no follow up evals were created @@ -2068,7 +2063,7 @@ func TestReconciler_RescheduleNow_Service_Canaries(t *testing.T) { allocs = append(allocs, alloc) } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnIgnore, false, job.ID, job2, d, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnIgnore, false, job.ID, job2, d, allocs, nil, "") reconciler.now = now r := reconciler.Compute() @@ -2194,7 +2189,7 @@ func TestReconciler_RescheduleNow_Service_Canaries_Limit(t *testing.T) { allocs = append(allocs, alloc) } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnIgnore, false, job.ID, job2, d, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnIgnore, false, job.ID, job2, d, allocs, nil, "") reconciler.now = now r := reconciler.Compute() @@ -2258,7 +2253,7 @@ func TestReconciler_DontReschedule_PreviouslyRescheduled(t *testing.T) { // Mark one as desired state stop allocs[4].DesiredStatus = structs.AllocDesiredStatusStop - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, nil, "") r := reconciler.Compute() // Should place 1 - one is a new placement to make up the desired count of 5 @@ -2345,7 +2340,7 @@ func TestReconciler_CancelDeployment_JobStop(t *testing.T) { allocs = append(allocs, alloc) } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnIgnore, false, c.jobID, c.job, c.deployment, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnIgnore, false, c.jobID, c.job, c.deployment, allocs, nil, "") r := reconciler.Compute() var updates []*structs.DeploymentStatusUpdate @@ -2422,7 +2417,7 @@ func TestReconciler_CancelDeployment_JobUpdate(t *testing.T) { allocs = append(allocs, alloc) } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnIgnore, false, job.ID, job, c.deployment, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnIgnore, false, job.ID, job, c.deployment, allocs, nil, "") r := reconciler.Compute() var updates []*structs.DeploymentStatusUpdate @@ -2471,7 +2466,7 @@ func TestReconciler_CreateDeployment_RollingUpgrade_Destructive(t *testing.T) { allocs = append(allocs, alloc) } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnDestructive, false, job.ID, job, nil, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnDestructive, false, job.ID, job, nil, allocs, nil, "") r := reconciler.Compute() d := structs.NewDeployment(job) @@ -2514,7 +2509,7 @@ func TestReconciler_CreateDeployment_RollingUpgrade_Inplace(t *testing.T) { allocs = append(allocs, alloc) } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnInplace, false, job.ID, job, nil, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnInplace, false, job.ID, job, nil, allocs, nil, "") r := reconciler.Compute() d := structs.NewDeployment(job) @@ -2556,7 +2551,7 @@ func TestReconciler_CreateDeployment_NewerCreateIndex(t *testing.T) { allocs = append(allocs, alloc) } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, nil, "") r := reconciler.Compute() d := structs.NewDeployment(job) @@ -2600,7 +2595,7 @@ func TestReconciler_DontCreateDeployment_NoChanges(t *testing.T) { allocs = append(allocs, alloc) } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, nil, "") r := reconciler.Compute() // Assert the correct results @@ -2678,7 +2673,7 @@ func TestReconciler_PausedOrFailedDeployment_NoMoreCanaries(t *testing.T) { d.TaskGroups[canary.TaskGroup].PlacedCanaries = []string{canary.ID} mockUpdateFn := allocUpdateFnMock(map[string]allocUpdateType{canary.ID: allocUpdateFnIgnore}, allocUpdateFnDestructive) - reconciler := NewAllocReconciler(testLogger(), mockUpdateFn, false, job.ID, job, d, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), mockUpdateFn, false, job.ID, job, d, allocs, nil, "") r := reconciler.Compute() // Assert the correct results @@ -2743,7 +2738,7 @@ func TestReconciler_PausedOrFailedDeployment_NoMorePlacements(t *testing.T) { allocs = append(allocs, alloc) } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnIgnore, false, job.ID, job, d, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnIgnore, false, job.ID, job, d, allocs, nil, "") r := reconciler.Compute() // Assert the correct results @@ -2817,7 +2812,7 @@ func TestReconciler_PausedOrFailedDeployment_NoMoreDestructiveUpdates(t *testing allocs = append(allocs, newAlloc) mockUpdateFn := allocUpdateFnMock(map[string]allocUpdateType{newAlloc.ID: allocUpdateFnIgnore}, allocUpdateFnDestructive) - reconciler := NewAllocReconciler(testLogger(), mockUpdateFn, false, job.ID, job, d, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), mockUpdateFn, false, job.ID, job, d, allocs, nil, "") r := reconciler.Compute() // Assert the correct results @@ -2905,7 +2900,7 @@ func TestReconciler_PausedOrFailedDeployment_Migrations(t *testing.T) { tainted[n.ID] = n } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnIgnore, false, job.ID, job, d, allocs, tainted, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnIgnore, false, job.ID, job, d, allocs, tainted, "") r := reconciler.Compute() // Assert the correct results @@ -2979,7 +2974,7 @@ func TestReconciler_DrainNode_Canary(t *testing.T) { tainted[n.ID] = n mockUpdateFn := allocUpdateFnMock(handled, allocUpdateFnDestructive) - reconciler := NewAllocReconciler(testLogger(), mockUpdateFn, false, job.ID, job, d, allocs, tainted, "") + reconciler := NewAllocReconciler(testlog.Logger(t), mockUpdateFn, false, job.ID, job, d, allocs, tainted, "") r := reconciler.Compute() // Assert the correct results @@ -3051,7 +3046,7 @@ func TestReconciler_LostNode_Canary(t *testing.T) { tainted[n.ID] = n mockUpdateFn := allocUpdateFnMock(handled, allocUpdateFnDestructive) - reconciler := NewAllocReconciler(testLogger(), mockUpdateFn, false, job.ID, job, d, allocs, tainted, "") + reconciler := NewAllocReconciler(testlog.Logger(t), mockUpdateFn, false, job.ID, job, d, allocs, tainted, "") r := reconciler.Compute() // Assert the correct results @@ -3117,7 +3112,7 @@ func TestReconciler_StopOldCanaries(t *testing.T) { allocs = append(allocs, canary) } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnDestructive, false, job.ID, job, d, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnDestructive, false, job.ID, job, d, allocs, nil, "") r := reconciler.Compute() newD := structs.NewDeployment(job) @@ -3170,7 +3165,7 @@ func TestReconciler_NewCanaries(t *testing.T) { allocs = append(allocs, alloc) } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnDestructive, false, job.ID, job, nil, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnDestructive, false, job.ID, job, nil, allocs, nil, "") r := reconciler.Compute() newD := structs.NewDeployment(job) @@ -3218,7 +3213,7 @@ func TestReconciler_NewCanaries_CountGreater(t *testing.T) { allocs = append(allocs, alloc) } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnDestructive, false, job.ID, job, nil, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnDestructive, false, job.ID, job, nil, allocs, nil, "") r := reconciler.Compute() newD := structs.NewDeployment(job) @@ -3269,7 +3264,7 @@ func TestReconciler_NewCanaries_MultiTG(t *testing.T) { } } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnDestructive, false, job.ID, job, nil, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnDestructive, false, job.ID, job, nil, allocs, nil, "") r := reconciler.Compute() newD := structs.NewDeployment(job) @@ -3322,7 +3317,7 @@ func TestReconciler_NewCanaries_ScaleUp(t *testing.T) { allocs = append(allocs, alloc) } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnDestructive, false, job.ID, job, nil, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnDestructive, false, job.ID, job, nil, allocs, nil, "") r := reconciler.Compute() newD := structs.NewDeployment(job) @@ -3370,7 +3365,7 @@ func TestReconciler_NewCanaries_ScaleDown(t *testing.T) { allocs = append(allocs, alloc) } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnDestructive, false, job.ID, job, nil, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnDestructive, false, job.ID, job, nil, allocs, nil, "") r := reconciler.Compute() newD := structs.NewDeployment(job) @@ -3447,7 +3442,7 @@ func TestReconciler_NewCanaries_FillNames(t *testing.T) { allocs = append(allocs, canary) } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnDestructive, false, job.ID, job, d, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnDestructive, false, job.ID, job, d, allocs, nil, "") r := reconciler.Compute() // Assert the correct results @@ -3516,7 +3511,7 @@ func TestReconciler_PromoteCanaries_Unblock(t *testing.T) { } mockUpdateFn := allocUpdateFnMock(handled, allocUpdateFnDestructive) - reconciler := NewAllocReconciler(testLogger(), mockUpdateFn, false, job.ID, job, d, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), mockUpdateFn, false, job.ID, job, d, allocs, nil, "") r := reconciler.Compute() // Assert the correct results @@ -3590,7 +3585,7 @@ func TestReconciler_PromoteCanaries_CanariesEqualCount(t *testing.T) { } mockUpdateFn := allocUpdateFnMock(handled, allocUpdateFnDestructive) - reconciler := NewAllocReconciler(testLogger(), mockUpdateFn, false, job.ID, job, d, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), mockUpdateFn, false, job.ID, job, d, allocs, nil, "") r := reconciler.Compute() updates := []*structs.DeploymentStatusUpdate{ @@ -3689,7 +3684,7 @@ func TestReconciler_DeploymentLimit_HealthAccounting(t *testing.T) { } mockUpdateFn := allocUpdateFnMock(handled, allocUpdateFnDestructive) - reconciler := NewAllocReconciler(testLogger(), mockUpdateFn, false, job.ID, job, d, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), mockUpdateFn, false, job.ID, job, d, allocs, nil, "") r := reconciler.Compute() // Assert the correct results @@ -3770,7 +3765,7 @@ func TestReconciler_TaintedNode_RollingUpgrade(t *testing.T) { } mockUpdateFn := allocUpdateFnMock(handled, allocUpdateFnDestructive) - reconciler := NewAllocReconciler(testLogger(), mockUpdateFn, false, job.ID, job, d, allocs, tainted, "") + reconciler := NewAllocReconciler(testlog.Logger(t), mockUpdateFn, false, job.ID, job, d, allocs, tainted, "") r := reconciler.Compute() // Assert the correct results @@ -3855,7 +3850,7 @@ func TestReconciler_FailedDeployment_PlacementLost(t *testing.T) { } mockUpdateFn := allocUpdateFnMock(handled, allocUpdateFnDestructive) - reconciler := NewAllocReconciler(testLogger(), mockUpdateFn, false, job.ID, job, d, allocs, tainted, "") + reconciler := NewAllocReconciler(testlog.Logger(t), mockUpdateFn, false, job.ID, job, d, allocs, tainted, "") r := reconciler.Compute() // Assert the correct results @@ -3910,7 +3905,7 @@ func TestReconciler_CompleteDeployment(t *testing.T) { allocs = append(allocs, alloc) } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnIgnore, false, job.ID, job, d, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnIgnore, false, job.ID, job, d, allocs, nil, "") r := reconciler.Compute() // Assert the correct results @@ -3965,7 +3960,7 @@ func TestReconciler_MarkDeploymentComplete_FailedAllocations(t *testing.T) { allocs = append(allocs, alloc) } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnIgnore, false, job.ID, job, d, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnIgnore, false, job.ID, job, d, allocs, nil, "") r := reconciler.Compute() updates := []*structs.DeploymentStatusUpdate{ @@ -4060,7 +4055,7 @@ func TestReconciler_FailedDeployment_CancelCanaries(t *testing.T) { } mockUpdateFn := allocUpdateFnMock(handled, allocUpdateFnDestructive) - reconciler := NewAllocReconciler(testLogger(), mockUpdateFn, false, job.ID, job, d, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), mockUpdateFn, false, job.ID, job, d, allocs, nil, "") r := reconciler.Compute() // Assert the correct results @@ -4129,7 +4124,7 @@ func TestReconciler_FailedDeployment_NewJob(t *testing.T) { jobNew := job.Copy() jobNew.Version += 100 - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnDestructive, false, job.ID, jobNew, d, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnDestructive, false, job.ID, jobNew, d, allocs, nil, "") r := reconciler.Compute() dnew := structs.NewDeployment(jobNew) @@ -4182,7 +4177,7 @@ func TestReconciler_MarkDeploymentComplete(t *testing.T) { allocs = append(allocs, alloc) } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnIgnore, false, job.ID, job, d, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnIgnore, false, job.ID, job, d, allocs, nil, "") r := reconciler.Compute() updates := []*structs.DeploymentStatusUpdate{ @@ -4251,7 +4246,7 @@ func TestReconciler_JobChange_ScaleUp_SecondEval(t *testing.T) { } mockUpdateFn := allocUpdateFnMock(handled, allocUpdateFnDestructive) - reconciler := NewAllocReconciler(testLogger(), mockUpdateFn, false, job.ID, job, d, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), mockUpdateFn, false, job.ID, job, d, allocs, nil, "") r := reconciler.Compute() // Assert the correct results @@ -4286,7 +4281,7 @@ func TestReconciler_RollingUpgrade_MissingAllocs(t *testing.T) { allocs = append(allocs, alloc) } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnDestructive, false, job.ID, job, nil, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnDestructive, false, job.ID, job, nil, allocs, nil, "") r := reconciler.Compute() d := structs.NewDeployment(job) @@ -4338,7 +4333,7 @@ func TestReconciler_Batch_Rerun(t *testing.T) { job2 := job.Copy() job2.CreateIndex++ - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnIgnore, true, job2.ID, job2, nil, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnIgnore, true, job2.ID, job2, nil, allocs, nil, "") r := reconciler.Compute() // Assert the correct results @@ -4399,7 +4394,7 @@ func TestReconciler_FailedDeployment_DontReschedule(t *testing.T) { StartedAt: now.Add(-1 * time.Hour), FinishedAt: now.Add(-10 * time.Second)}} - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnDestructive, false, job.ID, job, d, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnDestructive, false, job.ID, job, d, allocs, nil, "") r := reconciler.Compute() // Assert that no rescheduled placements were created @@ -4454,7 +4449,7 @@ func TestReconciler_DeploymentWithFailedAllocs_DontReschedule(t *testing.T) { allocs[i].DesiredTransition.Reschedule = helper.BoolToPtr(true) } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnDestructive, false, job.ID, job, d, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnDestructive, false, job.ID, job, d, allocs, nil, "") r := reconciler.Compute() // Assert that no rescheduled placements were created @@ -4537,7 +4532,7 @@ func TestReconciler_FailedDeployment_AutoRevert_CancelCanaries(t *testing.T) { allocs = append(allocs, new) } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnIgnore, false, job.ID, jobv2, d, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnIgnore, false, job.ID, jobv2, d, allocs, nil, "") r := reconciler.Compute() updates := []*structs.DeploymentStatusUpdate{ @@ -4599,7 +4594,7 @@ func TestReconciler_SuccessfulDeploymentWithFailedAllocs_Reschedule(t *testing.T allocs = append(allocs, alloc) } - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnDestructive, false, job.ID, job, d, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnDestructive, false, job.ID, job, d, allocs, nil, "") r := reconciler.Compute() // Assert that rescheduled placements were created @@ -4661,7 +4656,7 @@ func TestReconciler_ForceReschedule_Service(t *testing.T) { // Mark DesiredTransition ForceReschedule allocs[0].DesiredTransition = structs.DesiredTransition{ForceReschedule: helper.BoolToPtr(true)} - reconciler := NewAllocReconciler(testLogger(), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, nil, "") + reconciler := NewAllocReconciler(testlog.Logger(t), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, nil, "") r := reconciler.Compute() // Verify that no follow up evals were created diff --git a/scheduler/util_test.go b/scheduler/util_test.go index 345691a5f..3ce672ca7 100644 --- a/scheduler/util_test.go +++ b/scheduler/util_test.go @@ -2,12 +2,11 @@ package scheduler import ( "fmt" - "log" - "os" "reflect" "testing" "github.com/hashicorp/nomad/helper" + "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/helper/uuid" "github.com/hashicorp/nomad/nomad/mock" "github.com/hashicorp/nomad/nomad/state" @@ -623,7 +622,7 @@ func TestEvictAndPlace_LimitEqualToAllocs(t *testing.T) { func TestSetStatus(t *testing.T) { h := NewHarness(t) - logger := log.New(os.Stderr, "", log.LstdFlags) + logger := testlog.Logger(t) eval := mock.Eval() status := "a" desc := "b" @@ -1080,7 +1079,7 @@ func TestDesiredUpdates(t *testing.T) { } func TestUtil_AdjustQueuedAllocations(t *testing.T) { - logger := log.New(os.Stderr, "", log.LstdFlags) + logger := testlog.Logger(t) alloc1 := mock.Alloc() alloc2 := mock.Alloc() alloc2.CreateIndex = 4