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

Reusable containers #169

Closed
a-urth opened this issue Mar 26, 2020 · 8 comments
Closed

Reusable containers #169

a-urth opened this issue Mar 26, 2020 · 8 comments
Labels
feature New functionality or new behaviors on the existing one

Comments

@a-urth
Copy link

a-urth commented Mar 26, 2020

Hi everyone. I've came across problem running multiple instances of the same container among couple of different tests. And in case its something resource heavy like elasticsearch it takes time to spawn, those so it kinda makes sense to reuse them if one of the containers is already running.

I found that such functionality was implemented into java version of the projects and quickly looking through documentation I haven't found anything similar here.

So is there any functionality to reuse containers or are there any plans to implement it?

testcontainers/testcontainers-java#1781

@gianarb gianarb added the feature New functionality or new behaviors on the existing one label Mar 27, 2020
@gianarb
Copy link
Member

gianarb commented Mar 27, 2020

Hello! Thank you for opening this issue. We do not have a feature like that. But it is for sure implementable and something that we can do!

@cprepos
Copy link

cprepos commented Mar 27, 2020

@a-urth You can set up a container as a global var in the test, and use TestMain to start your containers before tests begin. They will be available to all tests.

var container testcontainers.Container

//TestMain controls main for the tests and allows for setup and shutdown of tests
func TestMain(m *testing.M) {
	//Catching all panics to once again make sure that shutDown is successfully run
	defer func() {
		if r := recover(); r != nil {
			shutDown()
			fmt.Println("Panic")
		}
	}()
	setup()
	code := m.Run()
	shutDown()
	os.Exit(code)
}

func setup(){
//start container here and it will be available to all tests
}
func shutDown(){
//Shut down containers
}

@krisctl
Copy link

krisctl commented May 22, 2020

Above is a decent solution if you are looking to reuse containers within one run of tests, across all tests but it is not at parity with Java's reusable containers implementation since that spans across JVM shutdowns as well.

@fbiville
Copy link
Contributor

fbiville commented Jul 6, 2020

Please correct me if I'm wrong, but that still limits reuse per package, or?
Is there a single global TestMain or one per package?

@mdelapenya
Copy link
Member

Relates #439

@deepakyadav
Copy link

Seems to be implemented in #464
Can we get a release?

@mdelapenya
Copy link
Member

Can we get a release?

Hopefully the release will be made soon, I need to step back for a few days on vacations, and after that will work a great release. Sorry for the inconvenience

In the meantime, do you think you can add a replace entry in your go.mod file pointing to the main branch?

@mdelapenya
Copy link
Member

Closing as #464 is merged, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionality or new behaviors on the existing one
Projects
None yet
Development

No branches or pull requests

7 participants