-
Notifications
You must be signed in to change notification settings - Fork 154
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
[Flaky Test]: fix TestFakeInputSuite/TestManager_OutputChange #4290
Merged
AndersonQ
merged 13 commits into
elastic:main
from
AndersonQ:4286-flaky-TestFakeInputSuite/TestManager_OutputChange
Feb 22, 2024
Merged
Changes from 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8ee2e02
add debug log an fix flaky test
AndersonQ d37d32b
reafctor Manager.waitForStopped
AndersonQ 703ab45
require start/stop to happen in order, but compare timestamps instead
AndersonQ 64f23a3
fix race condition
AndersonQ 7cd7bfb
better error message
AndersonQ d071cc2
change when timestamp is taken
AndersonQ f06b3da
refactor and try to remove the possible deadlock
AndersonQ d207b4a
use manager logs to determine the order of events
AndersonQ d31a104
Merge branch 'main' into 4286-flaky-TestFakeInputSuite/TestManager_Ou…
AndersonQ 1bd0dc2
restore `waitForStopped` check
AndersonQ 5dfd9a9
Merge branch '4286-flaky-TestFakeInputSuite/TestManager_OutputChange'…
AndersonQ 447878c
fix potential deadlock
AndersonQ 41ed11f
Merge branch 'main' into 4286-flaky-TestFakeInputSuite/TestManager_Ou…
AndersonQ File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -772,24 +772,27 @@ func (m *Manager) update(model component.Model, teardown bool) error { | |
stop = append(stop, existing) | ||
} | ||
m.currentMx.RUnlock() | ||
if len(stop) > 0 { | ||
var stoppedWg sync.WaitGroup | ||
stoppedWg.Add(len(stop)) | ||
for _, existing := range stop { | ||
m.logger.Debugf("Stopping component %q", existing.id) | ||
_ = existing.stop(teardown, model.Signed) | ||
// stop is async, wait for operation to finish, | ||
// otherwise new instance may be started and components | ||
// may fight for resources (e.g ports, files, locks) | ||
go func(state *componentRuntimeState) { | ||
m.waitForStopped(state) | ||
stoppedWg.Done() | ||
}(existing) | ||
} | ||
stoppedWg.Wait() | ||
|
||
var stoppedWg sync.WaitGroup | ||
stoppedWg.Add(len(stop)) | ||
for _, existing := range stop { | ||
m.logger.Debugf("Stopping component %q", existing.id) | ||
_ = existing.stop(teardown, model.Signed) | ||
// stop is async, wait for operation to finish, | ||
// otherwise new instance may be started and components | ||
// may fight for resources (e.g. ports, files, locks) | ||
go func(state *componentRuntimeState) { | ||
err := m.waitForStopped(state) | ||
if err != nil { | ||
m.logger.Errorf("updating components: failed waiting %s stop", | ||
state.id) | ||
} | ||
stoppedWg.Done() | ||
}(existing) | ||
} | ||
stoppedWg.Wait() | ||
|
||
// start all not started | ||
// start new components | ||
for _, comp := range newComponents { | ||
// new component; create its runtime | ||
logger := m.baseLogger.Named(fmt.Sprintf("component.runtime.%s", comp.ID)) | ||
|
@@ -800,6 +803,7 @@ func (m *Manager) update(model component.Model, teardown bool) error { | |
m.currentMx.Lock() | ||
m.current[comp.ID] = state | ||
m.currentMx.Unlock() | ||
m.logger.Debugf("Starting component %q", comp.ID) | ||
if err = state.start(); err != nil { | ||
return fmt.Errorf("failed to start component %s: %w", comp.ID, err) | ||
} | ||
|
@@ -808,10 +812,11 @@ func (m *Manager) update(model component.Model, teardown bool) error { | |
return nil | ||
} | ||
|
||
func (m *Manager) waitForStopped(comp *componentRuntimeState) { | ||
func (m *Manager) waitForStopped(comp *componentRuntimeState) error { | ||
if comp == nil { | ||
return | ||
return nil | ||
} | ||
|
||
currComp := comp.getCurrent() | ||
compID := currComp.ID | ||
timeout := defaultStopTimeout | ||
|
@@ -828,20 +833,12 @@ func (m *Manager) waitForStopped(comp *componentRuntimeState) { | |
latestState := comp.getLatest() | ||
if latestState.State == client.UnitStateStopped { | ||
m.logger.Debugf("component %q stopped.", compID) | ||
return | ||
return nil | ||
} | ||
|
||
m.currentMx.RLock() | ||
if _, exists := m.current[compID]; !exists { | ||
m.currentMx.RUnlock() | ||
return | ||
} | ||
m.currentMx.RUnlock() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @michalpristas do you remember why it'd be needed? It seems unnecessary to me. And if no tests fails, I'd believe it indeed is unnecessary |
||
|
||
select { | ||
case <-timeoutCh: | ||
m.logger.Errorf("timeout exceeded waiting for component %q to stop", compID) | ||
return | ||
return fmt.Errorf("timeout exceeded after %s", timeout) | ||
case <-time.After(stopCheckRetryPeriod): | ||
} | ||
} | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added for completeness as there is a log for stopping components. There makes sense to have for starting and updating components as well