Skip to content

TestRunner: Remove step stopping loop in RunMonitor#126

Merged
rihter007 merged 1 commit intomainfrom
refactor/remove_step_stopping_loop
Aug 16, 2022
Merged

TestRunner: Remove step stopping loop in RunMonitor#126
rihter007 merged 1 commit intomainfrom
refactor/remove_step_stopping_loop

Conversation

@rihter007
Copy link
Copy Markdown
Contributor

@rihter007 rihter007 commented Aug 9, 2022

Fixes #62

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

Merging #126 (c5974e6) into main (29d7b6d) will decrease coverage by 0.10%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #126      +/-   ##
==========================================
- Coverage   63.92%   63.81%   -0.11%     
==========================================
  Files         164      164              
  Lines       10321    10304      -17     
==========================================
- Hits         6598     6576      -22     
- Misses       3007     3013       +6     
+ Partials      716      715       -1     
Flag Coverage Δ
e2e 49.75% <100.00%> (-0.01%) ⬇️
integration 55.14% <100.00%> (-0.16%) ⬇️
unittests 49.37% <100.00%> (-0.35%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/runner/test_runner.go 91.75% <100.00%> (+0.84%) ⬆️
pkg/runner/step_state.go 89.79% <0.00%> (-4.09%) ⬇️
pkg/runner/step_runner.go 89.23% <0.00%> (-1.16%) ⬇️
pkg/jobmanager/jobmanager.go 76.92% <0.00%> (-1.10%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@rihter007 rihter007 requested a review from mimir-d August 10, 2022 08:01
@rihter007
Copy link
Copy Markdown
Contributor Author

Only one place where conditional variable is used is left will remove it next

Comment thread pkg/runner/test_runner.go Outdated
targets map[string]*targetState // Target state lookup map
steps []*stepState // The pipeline, in order of execution
targets map[string]*targetState // Target state lookup map
stepsTargetsCount []int32 // Holds counter of the amount of targets that will use this step
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like step related data, why doesnt this go into stepState?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently stepState doesn't contain information about the counters.
Let me think if putting them there will make the code look better

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

len(steps) == len(stepsTargetsCount), and theyre indexed by the target index, so it looks to me like it could be joined

Comment thread pkg/runner/test_runner.go Outdated

for _, tgs := range tr.targets {
for i := 0; i < tgs.CurStep; i++ {
tr.stepsTargetsCount[i]--
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some comments regading the logic here would be nice; it took me some reading to understand how this is supposed to work

Comment thread pkg/runner/test_runner.go Outdated

for _, tgs := range tr.targets {
for i := 0; i < tgs.CurStep; i++ {
tr.stepsTargetsCount[i]--
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how would this work with the future "inject new target from plugin" feature? i suppose there would need to be some api to increment the expected target count per following steps (from the one that injects)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please tell me more about that feature?

If steps will generate targets I guess we will not close input channels for steps at all or reinitialise.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway currently the only thing that loop in runMonitor does is just watching if all targets went through the step + watch for errors. Better to keep explicit ref count and watch for errors in another place.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's prob enough to provide an api to inject targets from a step (and since this one step is running, following must be running or not started). this api would also increment expected targets counts for the following steps, so the close of in chan should not be affected.

Comment thread pkg/runner/test_runner.go Outdated
for i := lastDecremented + 1; i < len(tr.stepsTargetsCount); i++ {
if atomic.AddInt32(&tr.stepsTargetsCount[i], -1) == 0 {
ctx.Infof("Stop step: %d", i)
tr.steps[i].Stop()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you extract this? i dont like the coupling between a function that is run per target (handler) and manipulating test runner state (which is technically a parent for this code here; tr shouldnt even be a pointer receiver here but go doesnt have immutability concepts...).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note, i understand that the monitorCond had the risk of deadlocking if it wasnt signaled in the right places, but it did have some separation of concerns that youre missing here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But targetHandler already manipulates tr.steps[i] when it Runs it or injects target.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that should prob go thru some func api as well. im ok with leaving this as a todo

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created an issue: #131

@rihter007 rihter007 force-pushed the refactor/remove_step_stopping_loop branch from c5974e6 to ad10ec4 Compare August 15, 2022 20:19
@rihter007 rihter007 requested a review from mimir-d August 15, 2022 20:20
…red in stepsTargetsCount

Signed-off-by: Ilya <rihter007@inbox.ru>
@rihter007 rihter007 force-pushed the refactor/remove_step_stopping_loop branch from ad10ec4 to e9a9bd1 Compare August 15, 2022 20:21
@rihter007 rihter007 merged commit fe65fea into main Aug 16, 2022
@rihter007 rihter007 deleted the refactor/remove_step_stopping_loop branch August 16, 2022 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactoring: Move stoping StetRunner from TestRunner.runMonitor function

3 participants