elastic4s icon indicating copy to clipboard operation
elastic4s copied to clipboard

Use testcontainers-scala in tests to launch Elasticsearch instance

Open igor-vovk opened this issue 1 year ago • 2 comments

If I understood correctly, running tests locally now requires manually launching elasticsearch instance. Also it is done this way in GitHub Actions build script. This can be improved by using https://github.com/testcontainers/testcontainers-scala that will start elasticsearch container automatically when tests are running.

Article with explanation of the approach: https://www.baeldung.com/scala/testcontainers-scala.

Pros:

  • Fresh instance of Elastic for each test suite, so the leftovers from other suites (for example, the data that was created and not cleaned up) won't intervene
  • No need to configure the env to run tests, just running sbt test will start needed containers

Cons:

  • Instance is started per test suite, which may take too long to start

igor-vovk avatar Jul 18 '24 05:07 igor-vovk

Ideally we would indeed switch to testcontainers-scala, a PR would be very welcome.

It would also be very nice to have the tests that require an elasticsearch instance separate in an integration-test configuration or separate project as is the currently recommended way in sbt (https://eed3si9n.com/sbt-1.9.0).

Philippus avatar Jul 18 '24 06:07 Philippus

An update: I've tried adding testcontainers and it conflicts with ScrollPublisherVerificationTest and BulkIndexingSubscriberWhiteboxTest, that extend TestNGSuiteLike because both new Testcontainer trait and TestNGSuiteLike define runTest method. Didn't have enough time to think how to overcome this yet.

igor-vovk avatar Jul 27 '24 11:07 igor-vovk

Update: it takes awhile for elastic to start, which won't align with how testcontainers work (service starting per test suite), closing the issue

igor-vovk avatar Nov 10 '24 18:11 igor-vovk