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

fix(cockroachdb): Fixes cockroachdb wait strategy handling #2456

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

bearrito
Copy link
Contributor

@bearrito bearrito commented Mar 30, 2024

What does this PR do?

Fixes wait strategy handling. Previously cockroachdb was overwriting wait strategies.

Why is it important?

Custom wait strategies were not being respected

Related issues

How to test this PR

I added tests.
There looks to be some form of connection logic in the SQL strategy. This has to be merged into the user provided strategy otherwise you will timeout.

@bearrito bearrito requested a review from a team as a code owner March 30, 2024 15:29
Copy link

netlify bot commented Mar 30, 2024

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit 5150d9d
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-go/deploys/661a18608599300008cef4f6
😎 Deploy Preview https://deploy-preview-2456--testcontainers-go.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

modules/cockroachdb/cockroachdb_test.go Show resolved Hide resolved
modules/cockroachdb/cockroachdb_test.go Outdated Show resolved Hide resolved
modules/cockroachdb/cockroachdb.go Outdated Show resolved Hide resolved
mdelapenya
mdelapenya previously approved these changes Apr 2, 2024
Copy link
Collaborator

@mdelapenya mdelapenya left a comment

Choose a reason for hiding this comment

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

LGTM thank you for taking the time to fix this!

@bearrito I added a few minor comments regarding consistency around blank lines as separation for different code blocks, so once they are addressed, this is ready to be merged.

🚀

modules/cockroachdb/cockroachdb_test.go Outdated Show resolved Hide resolved
contextDeadlineExceeded := fmt.Errorf("failed to start container: context deadline exceeded")
nodeStartUpCompleted := "node startup completed"
suite.Run("Expected Failure To Run", func() {

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ditto

Suggested change

modules/cockroachdb/cockroachdb_test.go Outdated Show resolved Hide resolved
modules/cockroachdb/cockroachdb_test.go Outdated Show resolved Hide resolved
suite.Require().NoError(err)
}
})

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change

modules/cockroachdb/cockroachdb_test.go Outdated Show resolved Hide resolved
modules/cockroachdb/cockroachdb_test.go Outdated Show resolved Hide resolved
modules/cockroachdb/cockroachdb_test.go Outdated Show resolved Hide resolved
suite.Require().NoError(err)
}
})

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change

modules/cockroachdb/cockroachdb_test.go Show resolved Hide resolved
Copy link
Collaborator

@mdelapenya mdelapenya left a comment

Choose a reason for hiding this comment

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

LGTM, there are a few non-blocking cosmetic comments here, but I think the PR can be merged if everybody agree.

I'll wait for you @bearrito and @AhmedNSidd for the open discussions, so at the moment they are closed, I'll merge this one.

Thank you both for your patience and for contributing to testcontainers-go!

Copy link

@AhmedNSidd AhmedNSidd left a comment

Choose a reason for hiding this comment

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

Changes look good to me. Please feel free to merge this one in @mdelapenya

My pleasure re: contributing to testcontainers-go :)
Thank you for maintaining this library.

if req.WaitingFor == nil {
req.WaitingFor = defaultStrategy
} else {
req.WaitingFor = wait.ForAll(req.WaitingFor, sqlWait)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we want to exclude the wait.ForHTTP here? IIUC, if there is a waitingFor, we are adding the SQL wait plus the defined one. If there is no waitingFor, we are adding the default wait (http + sql). Is it intended to remove the http one in the case the user provides a waitingFor? I think we should append the user-defined one to the default. Wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you suggesting we do this ?



defaultStrategy := wait.ForSQL( ... elided ...)
	

	if req.WaitingFor == nil {
		req.WaitingFor = wait.ForAll(wait.ForHTTP("/health").WithPort(defaultAdminPort),defaultStrategy)
	} else {
		req.WaitingFor = wait.ForAll(req.WaitingFor, defaultStrategy)
	}

I think you end up with the same thing.

Case 1: No Waiting for defined -> You get HTTP and SQL Waits
Case 2: A Wait is defined -> You get whatever the user passes in and SQL.

If that approach reads better I'm good with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, I can look in the source, but I might as well ask is wait.ForAll linear-ish eg if is FIFO or LIFO or in parallel ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

They are not run in parallel, so FIFO

Copy link
Collaborator

Choose a reason for hiding this comment

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

Case 2: A Wait is defined -> You get whatever the user passes in and SQL.

That's exactly my point: we lose here the original waitFor.HTTP, right? Is this intended?

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's what I originally had, but removed it. I have no problem switching it back.

Two arguments for/against:

  1. If as a user I pass in a wait strategy I would expect that wait strategy to be exclusively used. However, the SQL is different as it has to be awaited for connection functionality.
  2. Alternatively, we should always wait with predetermined strategies until we have a usable container to provide the user. But then why allow the user to override at all?

It almost seems like what would be better would something like

 testcontainers.WithDeadline(time.Millisecond*20))

Where we could just add the deadline to the existing wait strategy (assuming it exists).

WDYT?

@bearrito
Copy link
Contributor Author

@mdelapenya Is this good to go, the last failing test were unrelated

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.

[Bug]: CockroachDB module does not support overriding of wait strategy deadline
3 participants