Skip to content

WithReuse method doesn't work with Localstack module #1143

@Yopadd

Description

@Yopadd

Expected Behaviour
If I use .withReuse with LocalstackContainer then testcontainer reuse the current stopped or running localstack container.

Actual Behaviour
A new container are create for each executions

Steps to Reproduce

const container1 = await new LocalstackContainer('localstack/localstack:4.8')
  .withExposedPorts({ container: 4566, host: 4566 })
  .withAutoRemove(false)
  .withReuse()
  .start()

await container1.stop();

const container2 = await new LocalstackContainer('localstack/localstack:4.8')
  .withExposedPorts({ container: 4566, host: 4566 })
  .withAutoRemove(false)
  .withReuse()
  .start()

expect(container1.getId()).toBe(container2.getId()); // Ids not equals

Actually I looked the root cause and I think I found why. It's because Localstack module set an env var before create the container :

this.withEnvironment({
      LAMBDA_DOCKER_FLAGS: `${this.environment["LAMBDA_DOCKER_FLAGS"] ?? ""} -l ${LABEL_TESTCONTAINERS_SESSION_ID}=${reaper.sessionId}`,
});

Unfortunately this env var is not consistent and the reuse strategy use labels to choose if container could be reuse or not.

I haven't one solution to fix this because I don't known if this env var is necessary to run localstack. If it's required then it could be great to add a note in the doc for this point or maybe you will propose a technical solution to fix this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    triageInvestigation required

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions