Skip to content

Fixing data pollution between tests #4804

@Youans

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

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