Skip to content

Commit 2691d9e

Browse files
authored
Wait for components to start in workdir management test (#10961)
* Wait for components to start in workdir management test * Set log level to debug in test * Improve error reporting in command runtime * Fix assertion
1 parent d311e13 commit 2691d9e

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

pkg/component/runtime/command.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ func (c *commandRuntime) start(comm Communicator) error {
375375
}
376376

377377
if err := c.monitor.Prepare(c.current.ID); err != nil {
378-
return err
378+
return fmt.Errorf("failed to prepare component monitoring resources: %w", err)
379379
}
380380
args := c.monitor.EnrichArgs(c.current.ID, c.getSpecBinaryName(), cmdSpec.Args)
381381

@@ -391,7 +391,7 @@ func (c *commandRuntime) start(comm Communicator) error {
391391
process.WithEnv(env),
392392
process.WithCmdOptions(attachOutErr(c.logStd, c.logErr), dirPath(workDir)))
393393
if err != nil {
394-
return err
394+
return fmt.Errorf("failed to start process: %w", err)
395395
}
396396

397397
c.proc = proc
@@ -430,7 +430,11 @@ func (c *commandRuntime) stop(ctx context.Context) error {
430430
}(c.proc, cmdSpec.Timeouts.Stop)
431431

432432
c.log.Debugf("gracefully stopping pid %d", c.proc.PID)
433-
return c.proc.Stop()
433+
434+
if stopErr := c.proc.Stop(); stopErr != nil {
435+
return fmt.Errorf("failed to stop process %s: %w", c.proc.Cmd.String(), stopErr)
436+
}
437+
return nil
434438
}
435439

436440
func (c *commandRuntime) startWatcher(info *process.Info, comm Communicator) {

testing/integration/ess/beat_receivers_test.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ func TestComponentWorkDir(t *testing.T) {
927927
type configOptions struct {
928928
RuntimeExperimental string
929929
}
930-
configTemplate := `agent.logging.level: info
930+
configTemplate := `agent.logging.level: debug
931931
agent.logging.to_stderr: true
932932
agent.logging.to_files: false
933933
inputs:
@@ -978,13 +978,14 @@ agent.monitoring.enabled: false
978978
var componentID, componentWorkDir string
979979
var workDirCreated time.Time
980980

981-
// wait for component to appear in status
981+
// wait for component to appear in status and be healthy
982982
require.EventuallyWithT(t, func(collect *assert.CollectT) {
983983
var statusErr error
984984
status, statusErr := fixture.ExecStatus(ctx)
985985
require.NoError(collect, statusErr)
986986
require.Equal(collect, 1, len(status.Components))
987987
componentStatus := status.Components[0]
988+
assert.Equal(collect, cproto.State_HEALTHY, cproto.State(componentStatus.State))
988989
componentID = componentStatus.ID
989990
}, 2*time.Minute, 5*time.Second)
990991

@@ -1001,13 +1002,17 @@ agent.monitoring.enabled: false
10011002
err = fixture.Configure(ctx, receiverConfig)
10021003
require.NoError(t, err)
10031004

1005+
// wait for component to appear in status and be healthy or degraded
10041006
require.EventuallyWithT(t, func(collect *assert.CollectT) {
10051007
var statusErr error
10061008
status, statusErr := fixture.ExecStatus(ctx)
10071009
require.NoError(collect, statusErr)
10081010
require.Equal(collect, 1, len(status.Components))
10091011
componentStatus := status.Components[0]
1010-
assert.Equal(collect, "beats-receiver", componentStatus.VersionInfo.Name)
1012+
require.Equal(collect, "beats-receiver", componentStatus.VersionInfo.Name)
1013+
componentState := cproto.State(componentStatus.State)
1014+
assert.Truef(collect, componentState == cproto.State_HEALTHY || componentState == cproto.State_DEGRADED,
1015+
"component state should be HEALTHY or DEGRADED, got %s", componentState.String())
10111016
}, 2*time.Minute, 5*time.Second)
10121017

10131018
// the component working directory should still exist

0 commit comments

Comments
 (0)