-
Notifications
You must be signed in to change notification settings - Fork 17
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
Proof of concept of using TestStepInputOutput that hides using channels behind interface. #144
base: main
Are you sure you want to change the base?
Conversation
…ls behind interface. Previously each TestStep operated on targets using channels inside TestStepChannels. Which introduced an ability to close output channel as well as it didn't allow to override behaviour when TestStep obtains a new Target. Signed-off-by: Ilya <rihter007@inbox.ru>
} | ||
|
||
type targetInput struct { | ||
tgt target.Target |
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.
it might actually be better to have the copy here, but does subtly change semantics
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.
That is true, but why not to start getting rid of pointers?
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.
But ok, I agree that it is better to do it in a separate PR
ctx.Debugf("paused during target acquisition, acquired %d", len(targets)) | ||
return nil, xcontext.ErrPaused | ||
|
||
cancel() |
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.
from my reading of xcontext.WithCancel, the errs array is used to notify waiters with it, when cancel() is called.
so if the ctx here is already signalled with ErrPaused, it doesnt make sense to notify again with ErrPaused.
maybe im wrong in reading the xcontext code. the point is that prev code returned ErrPaused in this case, and this now returns stepIO.Get() error, which isnt equivalent.
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.
so if the ctx here is already signalled with ErrPaused, it doesnt make sense to notify again with ErrPaused.
Indeed, there is no need to notify about the same thing twice. In xcontext: if something happened at least once, it means it already happened (and this is forever) and repeating a signal won't affect anything. This behavior seems to be consistent with how original cancel signal works in the standard context.
onConsumed func() | ||
} | ||
|
||
func (tsi *testStepInputOutput) Get(ctx xcontext.Context) (*target.Target, error) { |
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.
this api might also allow for those "get some", "get all" semantics that appear in some plugins
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.
Good catch!
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.
type TestStepInputOutput interface {
Get(ctx xcontext.Context) (*target.Target, error)
GetMany(ctx xcontext.Context) ([]target.Target, error)
?
BUT
the main difference is in ctx.
In the first case we wait for either first target or context
In the second case we accumulate targets until they either deplete or context will Done() (for example timeout).
i had a look over the code, but i need more time to think of the implications since this would be breaking api. |
Previously each TestStep operated on targets using channels inside TestStepChannels.
Which introduced an ability to close output channel as well as it didn't allow to override behaviour when TestStep obtains a new Target.
Tests might break. It is just a PoC