Skip to content

Testcontainers#224

Open
hannosgit wants to merge 21 commits intodbos-inc:mainfrom
hannosgit:testcontainers
Open

Testcontainers#224
hannosgit wants to merge 21 commits intodbos-inc:mainfrom
hannosgit:testcontainers

Conversation

@hannosgit
Copy link
Contributor

Add testcontainers as test dependency for the setup of a Postgresql instance for testing. This allows running the tests on a local machine. The only requirement is Docker.
This PR also moves the setup of the DB connection into a common base class.

@devhawk
Copy link
Collaborator

devhawk commented Nov 19, 2025

FYI, I'm OOF at PASS this week and for Thanksgiving next week. This looks cool, but not sure when I'll have a chance to review.

@devhawk
Copy link
Collaborator

devhawk commented Dec 1, 2025

FYI, this looks good but I haven't made it work w/ my local environment (I'm running docker inside of WSL). Working on fixing this on my end - I can't merge approve this until I can confirm it works for me locally.

@devhawk
Copy link
Collaborator

devhawk commented Dec 1, 2025

Also note, the cli tests were not updated to use testcontainers. I will look at that after I update my environment to work w/ testcontainers.

testImplementation("io.rest-assured:rest-assured:5.4.0")
testImplementation("io.rest-assured:json-path:5.4.0")
testImplementation("io.rest-assured:xml-path:5.4.0")
testImplementation("org.testcontainers:postgresql:1.21.3")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per https://java.testcontainers.org/modules/databases/postgres/, this appears to be an outdated version

Resolved all merge conflicts by keeping testcontainers setup:
- All tests now extend DbSetupTestBase and use testcontainers
- Updated build.gradle.kts to include both testcontainers and maven-artifact dependencies
- Added dataSource field to DbSetupTestBase for tests that need direct database access
- Converted 6 new test files to use DbSetupTestBase:
  * MetricsTest
  * SingleExecutionTest
  * PatchTest
  * PartitionedQueuesTest
  * ForkTest
  * GarbageCollectionTest
@devhawk
Copy link
Collaborator

devhawk commented Jan 12, 2026

FYI, I'm working on some db connection changes. Might make sense to give your updates a day or two

# Conflicts:
#	transact/build.gradle.kts
#	transact/src/test/java/dev/dbos/transact/client/ClientTest.java
#	transact/src/test/java/dev/dbos/transact/config/ConfigTest.java
#	transact/src/test/java/dev/dbos/transact/database/MetricsTest.java
#	transact/src/test/java/dev/dbos/transact/database/SystemDatabaseTest.java
#	transact/src/test/java/dev/dbos/transact/execution/DBOSExecutorTest.java
#	transact/src/test/java/dev/dbos/transact/execution/LifecycleTest.java
#	transact/src/test/java/dev/dbos/transact/execution/RecoveryServiceTest.java
#	transact/src/test/java/dev/dbos/transact/execution/SingleExecutionTest.java
#	transact/src/test/java/dev/dbos/transact/invocation/CustomSchemaTest.java
#	transact/src/test/java/dev/dbos/transact/invocation/DirectInvocationTest.java
#	transact/src/test/java/dev/dbos/transact/invocation/MultiClassInstanceTest.java
#	transact/src/test/java/dev/dbos/transact/invocation/StartWorkflowTest.java
#	transact/src/test/java/dev/dbos/transact/issues/Issue218.java
#	transact/src/test/java/dev/dbos/transact/migrations/BackCompatTest.java
#	transact/src/test/java/dev/dbos/transact/migrations/MigrationManagerTest.java
#	transact/src/test/java/dev/dbos/transact/notifications/EventsTest.java
#	transact/src/test/java/dev/dbos/transact/notifications/NotificationServiceTest.java
#	transact/src/test/java/dev/dbos/transact/queue/PartitionedQueuesTest.java
#	transact/src/test/java/dev/dbos/transact/queue/QueuesTest.java
#	transact/src/test/java/dev/dbos/transact/scheduled/SchedulerServiceTest.java
#	transact/src/test/java/dev/dbos/transact/step/StepsTest.java
#	transact/src/test/java/dev/dbos/transact/workflow/AsyncWorkflowTest.java
#	transact/src/test/java/dev/dbos/transact/workflow/ForkTest.java
#	transact/src/test/java/dev/dbos/transact/workflow/GarbageCollectionTest.java
#	transact/src/test/java/dev/dbos/transact/workflow/QueueChildWorkflowTest.java
#	transact/src/test/java/dev/dbos/transact/workflow/SyncWorkflowTest.java
#	transact/src/test/java/dev/dbos/transact/workflow/TimeoutTest.java
#	transact/src/test/java/dev/dbos/transact/workflow/UnifiedProxyTest.java
#	transact/src/test/java/dev/dbos/transact/workflow/WorkflowMgmtTest.java
@hannosgit
Copy link
Contributor Author

Hey @devhawk,
the PR is now up-to-date again with main. Can you please take another look?
Even if you decide to not go forward with Testcontainers, I think there is a value in this PR as it moves all the code for setting up a DB into a common class. In that case we can replace DbSetupTestBase with hard-coded DB credentials.

@devhawk
Copy link
Collaborator

devhawk commented Mar 9, 2026

Looks good. I'm not typically a fan of inheritance - but in this case it makes sense since it sets up the @BeforeAll and @AfterAll methods.

I am going to hold off on merging this for a day or two. We are considering some restructuring / project refactoring that will likely require test refactoring as well. I'm a big fan of testcontainers, so we're definitely going to leverage your work. I just want to see how the other work stream is going to shape up.

.withDatabaseUrl(postgres.getJdbcUrl())
.withDbUser(postgres.getUsername())
.withDbPassword(postgres.getPassword());
dataSource = SystemDatabase.createDataSource(dbosConfig);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we're always creating the data source but never closing it

protected static void onetimeSetup() throws Exception {
postgres.start();
dbosConfig =
DBOSConfig.defaults("systemdbtest")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: default app name should be something like transact-java-test

@devhawk
Copy link
Collaborator

devhawk commented Mar 10, 2026

FYI, we're moving to a purely instance based API for DBOS (#306), which is going to affect almost every test. I'm going to start working on what that looks like in the tests before deciding if I want to merge this PR first or not. I don't want to make you do extra work, but if I'm making drastic changes to the test suite, there's not much point in merging this PR only to change everything again.

In particular, we may want to move to us a PG container per test instead of per test class, so we can run tests in parallel.

We will get to using test containers and you will be included among our contributors either way. Thanks for your patience on this @hannosgit!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants