Repository navigation
Add inspect(), isRunning() and getExitCode() to started containers - #1664
Open
Pushkar236 wants to merge 1 commit into
Open
Pushkar236 wants to merge 1 commit into
Pushkar236 wants to merge 1 commit into
Conversation
The getters on a started container return what was inspected when it started. inspect() returns a fresh InspectResult, which now includes the exit code, and isRunning() and getExitCode() read the current state from it. getExitCode() returns undefined while the container is running. Closes testcontainers#1545
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A started container's getters return what was inspected when it was started or last restarted, so there was no way to ask whether it is still running or how it exited without going through
getContainerRuntimeClient()and Dockerode.StartedTestContainernow has:inspect(): Promise<InspectResult>: a fresh inspect, mapped like the one the lifecycle hooks receive. It doesn't replace the cached result, sogetId(),getMappedPort()and the other getters stay as they were.isRunning(): Promise<boolean>:state.runningfrom a fresh inspect (Docker'sState.Running, so a paused container counts as running, as in Java).getExitCode(): Promise<number | undefined>: the exit code of the main process, orundefinedwhile the container is running or has never run.InspectResult.stategainsexitCode.StartedGenericContainerimplements the three methods andAbstractStartedContainerforwards them, so every module's started container has them. The health status is already onInspectResult(healthCheckStatus).docs/features/containers.mdgets an "Inspecting a container" section.Verification
New
generic-container-inspect.test.ts:inspect()reportsrunning, with its name and labels;isRunning()istrue,getExitCode()isundefined;SIGKILL:inspect()reportsexited,isRunning()isfalse,getExitCode()is137;AbstractStartedContainersubclass.All three fail on
main.npm run check-compiles(the package and all modules),biome ci --error-on-warnings,npm run knip, and the abstract-started, lifecycle and restart tests pass.Not breaking (
minor)This adds members to
StartedTestContainerand a field toInspectResult. Containers built onGenericContainerorAbstractStartedContainerget them automatically. Code that implementsStartedTestContainerfrom scratch or builds anInspectResultby hand would need to add them, but neither is a documented extension point, so I've kept theminorlabel from the issue.Suggested labels:
enhancement,minor.Closes #1545