diff --git a/.github/workflows/test-core.yaml b/.github/workflows/test-core.yaml index 8ed7dc2b4ae..41cf603a6d0 100644 --- a/.github/workflows/test-core.yaml +++ b/.github/workflows/test-core.yaml @@ -27,7 +27,7 @@ env: CONSUL_VERSION: 1.11.3 VAULT_VERSION: 1.9.3 NOMAD_SLOW_TEST: 0 - NOMAD_TEST_LOG_LEVEL: ERROR + NOMAD_TEST_LOG_LEVEL: OFF jobs: checks: runs-on: ubuntu-20.04 diff --git a/GNUmakefile b/GNUmakefile index 39a986bea60..e33b9015a7c 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -300,6 +300,7 @@ test-nomad: dev ## Run Nomad test suites $(if $(ENABLE_RACE),-race) $(if $(VERBOSE),-v) \ -cover \ -timeout=20m \ + -count=1 \ -tags "$(GO_TAGS)" \ $(GOTEST_PKGS) @@ -310,6 +311,7 @@ test-nomad-module: dev ## Run Nomad test suites on a sub-module $(if $(ENABLE_RACE),-race) $(if $(VERBOSE),-v) \ -cover \ -timeout=20m \ + -count=1 \ -tags "$(GO_TAGS)" \ ./... diff --git a/command/agent/keyring_test.go b/command/agent/keyring_test.go index 284a113140c..aa35f476240 100644 --- a/command/agent/keyring_test.go +++ b/command/agent/keyring_test.go @@ -9,6 +9,7 @@ import ( "github.com/hashicorp/go-hclog" "github.com/hashicorp/nomad/ci" + "github.com/hashicorp/nomad/helper/testlog" ) func TestAgent_LoadKeyrings(t *testing.T) { @@ -29,9 +30,10 @@ func TestAgent_LoadKeyrings(t *testing.T) { // Server should auto-load WAN keyring files agent2 := &TestAgent{ - T: t, - Name: t.Name() + "2", - Key: key, + T: t, + Name: t.Name() + "2", + Key: key, + logger: testlog.HCLogger(t), } agent2.Start() defer agent2.Shutdown() diff --git a/command/agent/log_levels.go b/command/agent/log_levels.go index f4455e47f86..8b4e3523650 100644 --- a/command/agent/log_levels.go +++ b/command/agent/log_levels.go @@ -10,7 +10,7 @@ import ( // levels that we use. func LevelFilter() *logutils.LevelFilter { return &logutils.LevelFilter{ - Levels: []logutils.LogLevel{"TRACE", "DEBUG", "INFO", "WARN", "ERROR"}, + Levels: []logutils.LogLevel{"TRACE", "DEBUG", "INFO", "WARN", "ERROR", "OFF"}, MinLevel: "INFO", Writer: ioutil.Discard, } diff --git a/command/agent/testagent.go b/command/agent/testagent.go index b69459c85a0..223303e98bd 100644 --- a/command/agent/testagent.go +++ b/command/agent/testagent.go @@ -2,7 +2,6 @@ package agent import ( "fmt" - "io" "io/ioutil" "math/rand" "net/http" @@ -55,9 +54,8 @@ type TestAgent struct { // when Shutdown() is called. Config *Config - // LogOutput is the sink for the logs. If nil, logs are written - // to os.Stderr. - LogOutput io.Writer + // logger is used for logging + logger hclog.InterceptLogger // DataDir is the data directory which is used when Config.DataDir // is not set. It is created automatically and removed when @@ -102,6 +100,7 @@ func NewTestAgent(t testing.TB, name string, configCallback func(*Config)) *Test Name: name, ConfigCallback: configCallback, Enterprise: EnterpriseTestAgent, + logger: testlog.HCLogger(t), } a.Start() @@ -235,11 +234,6 @@ RETRY: } func (a *TestAgent) start() (*Agent, error) { - if a.LogOutput == nil { - prefix := fmt.Sprintf("%v:%v ", a.Config.BindAddr, a.Config.Ports.RPC) - a.LogOutput = testlog.NewPrefixWriter(a.T, prefix) - } - inm := metrics.NewInmemSink(10*time.Second, time.Minute) metrics.NewGlobal(metrics.DefaultConfig("service-name"), inm) @@ -247,14 +241,7 @@ func (a *TestAgent) start() (*Agent, error) { return nil, fmt.Errorf("unable to set up in memory metrics needed for agent initialization") } - logger := hclog.NewInterceptLogger(&hclog.LoggerOptions{ - Name: "agent", - Level: hclog.LevelFromString(a.Config.LogLevel), - Output: a.LogOutput, - JSONFormat: a.Config.LogJson, - }) - - agent, err := NewAgent(a.Config, logger, a.LogOutput, inm) + agent, err := NewAgent(a.Config, a.logger, testlog.NewWriter(a.T), inm) if err != nil { return nil, err } @@ -349,8 +336,7 @@ func (a *TestAgent) pickRandomPorts(c *Config) { } } -// TestConfig returns a unique default configuration for testing an -// agent. +// TestConfig returns a unique default configuration for testing an agent. func (a *TestAgent) config() *Config { conf := DevConfig(nil) @@ -361,10 +347,9 @@ func (a *TestAgent) config() *Config { // Setup client config conf.ClientConfig = client.DefaultConfig() - logger := testlog.HCLogger(a.T) conf.LogLevel = testlog.HCLoggerTestLevel().String() - conf.NomadConfig.Logger = logger - conf.ClientConfig.Logger = logger + conf.NomadConfig.Logger = a.logger + conf.ClientConfig.Logger = a.logger // Set the name conf.NodeName = a.Name