Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TestManager_FakeShipper flakiness. #2483

Merged
merged 4 commits into from
Apr 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 40 additions & 6 deletions pkg/component/runtime/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2307,8 +2307,6 @@ func TestManager_FakeShipper(t *testing.T) {
5. Send `send_event` action to the component fake input (GRPC client); returns once sent.
6. Wait for `record_event` action to return from the shipper input (GRPC server).
*/
t.Skip("Flaky test: https://github.com/elastic/elastic-agent/issues/2301")

testPaths(t)

ctx, cancel := context.WithCancel(context.Background())
Expand Down Expand Up @@ -2412,14 +2410,21 @@ func TestManager_FakeShipper(t *testing.T) {
defer subCancel()
subErrCh := make(chan error)
go func() {
shipperOn := false
shipperInputOn := false
shipperOutputOn := false
compConnected := false
eventSent := false

sendEvent := func() (bool, error) {
if !shipperOn || !compConnected {
if !shipperInputOn || !shipperOutputOn || !compConnected {
// wait until connected
return false, nil
}
if eventSent {
// other path already sent event
return false, nil
}
eventSent = true

// send an event between component and the fake shipper
eventID, err := uuid.NewV4()
Expand Down Expand Up @@ -2471,7 +2476,7 @@ func TestManager_FakeShipper(t *testing.T) {
if unit.State == client.UnitStateFailed {
subErrCh <- fmt.Errorf("unit failed: %s", unit.Message)
} else if unit.State == client.UnitStateHealthy {
shipperOn = true
shipperInputOn = true
ok, err := sendEvent()
if ok {
if err != nil {
Expand All @@ -2493,7 +2498,36 @@ func TestManager_FakeShipper(t *testing.T) {
subErrCh <- fmt.Errorf("unit reported unexpected state: %v", unit.State)
}
} else {
subErrCh <- errors.New("unit missing: fake-input")
subErrCh <- errors.New("input unit missing: fake-default")
}
unit, ok = state.Units[ComponentUnitKey{UnitType: client.UnitTypeOutput, UnitID: "fake-default"}]
if ok {
if unit.State == client.UnitStateFailed {
subErrCh <- fmt.Errorf("unit failed: %s", unit.Message)
} else if unit.State == client.UnitStateHealthy {
shipperOutputOn = true
ok, err := sendEvent()
if ok {
if err != nil {
subErrCh <- err
} else {
// successful; turn it all off
err := m.Update([]component.Component{})
if err != nil {
subErrCh <- err
}
}
}
} else if unit.State == client.UnitStateStopped {
subErrCh <- nil
} else if unit.State == client.UnitStateStarting {
// acceptable
} else {
// unknown state that should not have occurred
subErrCh <- fmt.Errorf("unit reported unexpected state: %v", unit.State)
}
} else {
subErrCh <- errors.New("output unit missing: fake-default")
}
}
case state := <-compSub.Ch():
Expand Down