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

Improve BaseTestSuite #56

Merged
merged 1 commit into from
Dec 17, 2021
Merged

Conversation

rihter007
Copy link
Contributor

Move global variable ctx into suite
Use BaseTestSuite in TestRunner tests

@rihter007 rihter007 force-pushed the refactor/improve_runner_base_test_suite branch from d3c90a0 to cb45196 Compare December 15, 2021 19:43
type BaseTestSuite struct {
suite.Suite

pluginRegistry *pluginregistry.PluginRegistry
internalStorage *MemoryStorageEngine
Ctx xcontext.Context
Copy link
Member

Choose a reason for hiding this comment

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

there's very clear guidelines on not keeping contexts in structs

Do not store Contexts inside a struct type; instead, pass a Context explicitly to each function that needs it. The Context should be the first parameter, typically named ctx:

instead this should be created (and cancelled) on a per test basis

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree with this guidelines in general, but this is a TestSuite which is some sort of global environment for each test.
It is handy because:

  • I use context during TestSetup() (which can't be passed from the test itself, so I will have two context in the test)
  • Tests do not get simple, but yet redundant logic of context initialisation with logs support + cancelling it (I agree that it is short, but still it is code duplication).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ha-ha, noticed that the first point is affected by NewPluginRegistry that doesn't follow that guideline

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed I can get rid of context in MemoryStorageEngine

Copy link
Member

Choose a reason for hiding this comment

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

this usage here s.PluginRegistry = pluginregistry.NewPluginRegistry(s.Ctx) should not exist to begin with. What's being used there in terms of semantics is a logger, not a cancellation context. I'll accept the review as is right now, but please post an issue to get that fixed and then remove the context from the struct

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Opened a new issue: #59

@rihter007 rihter007 force-pushed the refactor/improve_runner_base_test_suite branch from cb45196 to 37fde4b Compare December 16, 2021 11:58
Use BaseTestSuite in TestRunner tests

Signed-off-by: Ilya <[email protected]>
@rihter007 rihter007 force-pushed the refactor/improve_runner_base_test_suite branch from 37fde4b to 09ece8d Compare December 16, 2021 21:14
@rihter007 rihter007 merged commit 8fabbd2 into main Dec 17, 2021
@rihter007 rihter007 deleted the refactor/improve_runner_base_test_suite branch December 17, 2021 12:58
@rihter007
Copy link
Contributor Author

Wtf, I have a strong feeling that I removed ctx from BaseSuite...
Will make a new PR

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.

2 participants