-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor TestEnrollAndLog to use the agent status for health check
* Instead of relying in the absence of error logs, now it uses the agent and components status to ensure all is running as expected. The final state is what maters as there are transients, recoverable errors that might happens and are no reason for the test to fail. * Rename the test and its file to better reflect what it's testing * Remove testify.Suite as it wan't really used. * add integration tag * create testing/tools/check package and move ConnectedToFleet to it
- Loading branch information
Showing
3 changed files
with
82 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package check | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/elastic/elastic-agent/pkg/control/v2/cproto" | ||
integrationtest "github.com/elastic/elastic-agent/pkg/testing" | ||
) | ||
|
||
// ConnectedToFleet checks if the agent defined in the fixture is connected to | ||
// Fleet Server. It uses assert.Eventually and if it fails the last error will | ||
// be printed. It returns if the agent is connected to Fleet Server or not. | ||
func ConnectedToFleet(t *testing.T, fixture *integrationtest.Fixture) bool { | ||
t.Helper() | ||
|
||
var err error | ||
var agentStatus integrationtest.AgentStatusOutput | ||
assertFn := func() bool { | ||
agentStatus, err = fixture.ExecStatus(context.Background()) | ||
return agentStatus.FleetState == int(cproto.State_HEALTHY) | ||
} | ||
|
||
connected := assert.Eventually(t, assertFn, 5*time.Minute, 5*time.Second, | ||
"want fleet state %s, got %s. agent status: %v", | ||
cproto.State_HEALTHY, cproto.State(agentStatus.FleetState), agentStatus) | ||
|
||
if !connected && err != nil { | ||
t.Logf("agent isn't connected to fleet-server: last error from agent status command: %v", | ||
err) | ||
} | ||
|
||
return connected | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters