-
-
Notifications
You must be signed in to change notification settings - Fork 503
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
refactor(cockroachdb): to use request driven options #2883
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for testcontainers-go ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
fbfb05c
to
6dc9c5c
Compare
This should be split out into components if we want to go down this route. |
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.
I did an initial pass and the overall feedback is positive. I detected the following possible chunks of separate PRs, please tell me what you think:
- wait.walk for traversing multi strategies
- wait for TLS
- cockroachdb refactor
I think it would be much clearer for the review, but also for the release notes, as consumers would discover the new wait strategies as part of it.
@@ -0,0 +1,8 @@ | |||
SET CLUSTER SETTING kv.range_merge.queue_interval = '50ms'; |
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.
question: are these settings the same for different cockroachdb versions? If we always set them, no matter the chosen version, then it could lead to misconfiguring the container.
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.
Looks like there is one change since this advice was introduced in v21.2.17 (a setting was removed in v21.2.22), so looks like we're good. If this was needed we could look to introduce version conditionals.
o.StoreSize = size | ||
// WithInitScripts adds the given scripts to those automatically run when the container starts. | ||
// These will be ignored if data exists in the `/cockroach/cockroach-data` directory within the container. | ||
func WithInitScripts(scripts ...string) testcontainers.CustomizeRequestOption { |
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.
question: should we use paths or readers, to allow users fetch the files from wherever they want?
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.
Readers provides more flexibility so switching to that would be a good idea. Users that want to read from a file can easily use embed
+ bytes.NewReader
to achieve that.
var _ Strategy = (*TLSStrategy)(nil) | ||
|
||
// TLSStrategy is a strategy for handling TLS. | ||
type TLSStrategy struct { |
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.
docs: we need to add a page for this in the docs (see mkdocs.yml in the root dir, and the wait folder under ./docs/features)
) | ||
|
||
var ( | ||
//go:embed testdata/cert.crt |
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.
question: Have you considered using https://github.com/mdelapenya/tlscert instead?
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.
I saw that, but it was hiding errors e.g. SelfSignedFromRequest returns nil on error, so followed the pattern in the standard library. If that got cleaned up we could change later.
) | ||
|
||
func TestWalk(t *testing.T) { | ||
req := testcontainers.ContainerRequest{ |
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.
suggestion: I think we do not need the req, just the WaitingFor field
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.
You're correct, but I wanted the test to act as an example of its use as well, hence using request.
if err := visit(*root); err != nil { | ||
if errors.Is(err, VisitRemove) { | ||
*root = nil | ||
} | ||
|
||
return err | ||
} | ||
|
||
if s, ok := (*root).(*MultiStrategy); ok { |
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.
question: shouldn't we check first if the root is a multi-strategy, to iterate through the child elements?
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.
I wanted to allow the caller to customise the behaviour. This way round they could return an error or VisitRemove to remove the element without having to traverse it first. Added a comment to this effect.
return nil | ||
}) | ||
require.NoError(t, err) | ||
require.Equal(t, 5, count) |
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.
question: because the root has no logic, apart from being a "container" for the children strategies, should we count 4 here, therefore affecting the processing? I think this is related to my previous question about the root node being a multi.
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.
As we visit the root first to allow it to be customised, the root is also counted.
That's pretty much my thought's too, which is why I've left in draft. |
…list of statements
Co-authored-by: Steven Hartland <stevenmhartland@gmail.com>
Co-authored-by: Steven Hartland <stevenmhartland@gmail.com>
… in defaultOptions
Co-authored-by: Manuel de la Peña <social.mdelapenya@gmail.com>
… to DefaultStatements
Simplify the connection handling in cockroachdb so that ConnectionString can be used without the user doing extra work to handle TLS if enabled. Deprecate TLSConfig which is no longer needed separately. BREAKING_CHANGE: This now returns a registered connection string so is no longer compatible with pgx.ParseConfig, use ConnectionConfig for this use case instead.
Refactor cockroachdb module to to use request driven options, simplifying the flow.
Various fixes and remove the ability to configure certs using the default generated ones instead.
Add the missing data file and remove unused constants.
Extract TLS certificate wait strategy into a dedicated wait type so it can be reused. Implement walk method which can be used to identify wait strategies in a request chain. Use embed to simplify wait test loading of certs.
Remove the now unused customizer.
Fix lint style issue for blank line.
Improve test coverage as per review feedback.
158644d
to
83a7838
Compare
Refactor cockroachdb module to to use request driven options simplifying the flow.
Clean up tests eliminating the use of suite which significantly speeds up test runs.