ByteCode.News
Submit RSS Atom Podcast Sign in

Back to the channels

#java

  1. dreamreal https://bytecode.news/posts/2026/10/testcontainers-and-reuse
  2. javabot dreamreal's title: "Testcontainers and Reuse | ByteCode.News"
  3. dreamreal https://news.ycombinator.com/item?id=49977000 upvotes appreciated, I'm trying to get this to the front page of HN so I can see how the front end endures
  4. nevet Testcontainers and Reuse | Hacker News
  5. javabot dreamreal's title: "Testcontainers and Reuse | Hacker News"
  6. dreamreal (I did not post this to HN)
  7. Para dreamreal: neat, i'm gonna steal that
  8. dreamreal Para: :)
  9. dreamreal It's definitely nicer - my builds for nevet lost five literal minutes on deployments
  10. deebo i've been kinda battling the opposite of that in spring boot, if you use jdbc:tc:postgresql as the spring boot jdbc url, context caching still reuses the same underlying container for new contexts
  11. deebo so all tests have to make sure they can run with possibly garbage data left by other tests not running transactionally (intentional or not)
  12. dreamreal Hmm, I wonder how that's propagating: on my machine, every module was getting its own container and choking docker out
  13. dreamreal moving to unique scoped *databases* cleared everything up
  14. deebo at this point i've forgotten what the issue was, each new context in the cache had its own hikaripool to the same db, but somehow new containers were not started
  15. dreamreal That's the problem *I* had! New containers were taking too long to initialize
  16. dreamreal so now: one container, so it initializes ONCE, and new dbs can be created and destroyed instantly because connecting to postgres doesn't have to wait on docker
  17. deebo maybe the container is created on Class.forName() or something so it's only done once per jvm, never looked into how jdbc testcontainers work
  18. Para I have this in my personal project https://gist.github.com/esuomi/1a7a5b847f0b5943a63b35b91a226c1f
  19. nevet PostgreSQLExtension.java
  20. Para Feel free to steal if there's anything worth stealing.
  21. dreamreal deebo: if you don't explicitly turn on reuse, it starts a container for every JVM
  22. dreamreal but turning on reuse isn't enough, you also need to differentiate schemas if they differ
  23. deebo yeah we don't fork tests from gradle and any multimodules are trivial, mostly for sharing domain classes etc so basically single jvm for tests
  24. dreamreal *nod*
  25. deebo yeah the driver has one container per url, i remember testing adding like ?cachebust=${time} or something and it made it work, but broke something else