-
-
Notifications
You must be signed in to change notification settings - Fork 206
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
Add CockroachDB module #910
Conversation
✅ Deploy Preview for testcontainers-node ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
97ca670
to
0067938
Compare
f03a7a5
to
766d204
Compare
@cristianrgreco Let me know what, if anything, you need from me here to get this merged. |
@leourbina Sorry for the delay! Just one thing to address, rest LGTM. |
NP! Just addressed the latest comment and added the test. I had to tweak the wait condition to be more robust and ensure that it would work across restarts. Thanks for the thorough review. |
@cristianrgreco ok, I think it should be good now. |
Urgh... ok I think the healthcheck is not as robust as I actually thought. I'll look into it. |
Hey @cristianrgreco I'm running into the following issue: Whenever the container starts for the first time, it will run the init scripts. These need to finish running as they setup the user/db and need to be waited for before running anything against it. The only reliable way that I've figured out to detect this is to wait for the log message as so: this.withExposedPorts(COCKROACH_PORT)
.withCommand(["start-single-node", "--insecure"])
.withWaitStrategy(Wait.forLogMessage(/.*end running init files.*/))
.withStartupTimeout(120_000); This is effectively the same thing that the postgres container is doing here. However, on restarts the init scripts don't run again. I tried fixing it using a healthcheck (as seen on this PR), but I think it is working on my machine as the timing lines up, but based on the test results it is not reliably waiting for the init scripts. As it is currently written the restart issue we're seeing on the Cockroachdb container exists too on the postgres container. I'm not sure if there are other better ways to ensure that the container is ready both on the first start as well as after a restart. Any ideas here? |
@cristianrgreco currently the postgres container does not work across restarts either as it suffers from the same issue I pointed above. Namely, the wait condition does not work across restarts. Any chance we can merge this as is? Or do you think we need to fix both CRDB and Postgres as part of this PR? |
Hi @leourbina, I've raised a PR for fixing the PG container across restarts: #914 For the Cockroach container I see in the testcontainers-java implementation that they're calling an endpoint ending with waitStrategy.withStrategy(
Wait.forHttp("/health").forPort(REST_API_PORT).forStatusCode(200).withStartupTimeout(Duration.ofMinutes(1))
);
if (this.isVersionGreaterThanOrEqualTo221) {
waitStrategy.withStrategy(Wait.forSuccessfulCommand("[ -f ./init_success ] || { exit 1; }"));
} You can also refactor the custom curl command in the healthcheck with |
Calling the I've committed a change similar to the PG container healthcheck. Seems to work locally and it allows us to make the interval more frequent for faster startups. Pipeline is green. At the moment the changes I've made mean that a user cannot override the CockroachDB healthcheck. I've fixed this as well in the PG PR, but will need to merge that first to be able to do the same here. |
Latest changes should be final. @leourbina is there anything more or is this PR good to go? |
Hey @cristianrgreco! Thanks for looking into this 🔥. Those changes sound reasonable. |
Thanks @leourbina for your contribution! |
Thank you @cristianrgreco! |
Adds CockroachDB Support
This is mainly the same as the postgres container, with a few minor details:
--insecure
flag to avoid needing to deal with certs for local testing/connections