Skip to content

Fixing data pollution between tests #4804

Description

@Youans

Hi there thanks for such a great lib

We have been using H2 for our test suite and we are planning to migrate to TestContainer only problem is that we have some test cases especially the ones that involving @Async blocks within that when executed it pollutes the database records so we used to backup the database in a @BeforeEach and then restore it back in an @AfterEach

Doing so in H2 was pretty easy and fast using SCRIPT TO scriptPath in @BeforeEach and DROP ALL OBJECTS, RUNSCRIPT FROM scriptPath in @AfterEach

I was trying to do the same idea some stuff like
@BeforeEach > postgreSQLContainer.execInContainer("pg_dump", "-U" , "test" , "-w" , "-Fc","-d", "test", "-f", "/tmp/backup");

@AfterEach > postgreSQLContainer.execInContainer("pg_restore","-U", "test", "-w","--clean", "--dbname=test", "/tmp/backup");

but was left facing locking problems and eliminating these locks will terminate the test context

I also tried separate container per test but it takes alot of time

Any idea how to overcome such a problem

Note, This is not a bug in test container but it might be a feature request

Activity

  1. changed the title [-]Fixing data pollution[/-] [+]Fixing data pollution between tests[/+] on Dec 28, 2021
  2. locked and limited conversation to collaborators on Jan 3, 2022
  3. converted this issue into a discussion #4845 on Jan 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions