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

Proof of concept of using TestStepInputOutput that hides using channels behind interface. #144

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rihter007
Copy link
Contributor

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

…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>
@rihter007 rihter007 requested a review from mimir-d August 24, 2022 22:49
}

type targetInput struct {
tgt target.Target
Copy link
Member

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

Copy link
Contributor Author

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?

Copy link
Contributor Author

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()
Copy link
Member

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.

Copy link
Member

@xaionaro xaionaro Aug 26, 2022

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) {
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch!

Copy link
Contributor Author

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).

@mimir-d
Copy link
Member

mimir-d commented Aug 26, 2022

i had a look over the code, but i need more time to think of the implications since this would be breaking api.

@rihter007 rihter007 requested a review from mimir-d August 29, 2022 23:55
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.

None yet

3 participants