Skip to content

Commit

Permalink
print coordinator logs on failure
Browse files Browse the repository at this point in the history
  • Loading branch information
AndersonQ committed Mar 13, 2024
1 parent 0c4481f commit f82f292
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/elastic/elastic-agent/pkg/component"
"github.com/elastic/elastic-agent/pkg/component/runtime"
agentclient "github.com/elastic/elastic-agent/pkg/control/v2/client"
"github.com/elastic/elastic-agent/pkg/core/logger"
"github.com/elastic/elastic-agent/pkg/utils/broadcaster"
)

Expand Down Expand Up @@ -331,10 +332,19 @@ func TestCoordinatorReportsInvalidPolicy(t *testing.T) {
// does let's report a failure instead of timing out the test runner.
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
logger := logp.NewLogger("testing")

log, obs := logger.NewTesting("")
defer func() {
if t.Failed() {
t.Log("test failed, coordinator logs below:")
for _, l := range obs.TakeAll() {
t.Log(l)
}
}
}()

upgradeMgr, err := upgrade.NewUpgrader(
logger,
log,
&artifact.Config{},
&info.AgentInfo{},
)
Expand All @@ -346,7 +356,7 @@ func TestCoordinatorReportsInvalidPolicy(t *testing.T) {
configChan := make(chan ConfigChange, 1)
varsChan := make(chan []*transpiler.Vars, 1)
coord := &Coordinator{
logger: logger,
logger: log,
state: State{
CoordinatorState: agentclient.Healthy,
CoordinatorMessage: "Running",
Expand Down

0 comments on commit f82f292

Please sign in to comment.