This is an automated email from the ASF dual-hosted git repository.

pjfanning pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pekko-connectors.git


The following commit(s) were added to refs/heads/main by this push:
     new c20bff707 Slick: keep H2 test database open and relax test patience 
(#1978)
c20bff707 is described below

commit c20bff707871e0703da71ef92a2c395c9247f268
Author: PJ Fanning <[email protected]>
AuthorDate: Thu Oct 1 21:32:36 2026 +0100

    Slick: keep H2 test database open and relax test patience (#1978)
    
    * Slick: keep H2 test database open and relax test patience
    
    Motivation:
    SlickWithTryResultSpec "insert 40 records into a table with try (no
    parallelism)" timed out after 3 seconds with nothing logged, while the
    same 40 inserts took 569ms in the previous test and every later test
    finished in under a second. The slick-h2 test config disables the
    connection pool and uses a file-based H2 database, so every db.run opens
    a new connection, and by default H2 closes the database file when the
    last connection closes and reopens it on the next one. That per-statement
    file churn is the likely source of the stall on slow CI disks.
    
    Modification:
    - Add a test-only override after the #config-h2 doc snippet that appends
      DB_CLOSE_DELAY=-1 to the H2 URL, keeping the database open between
      connections. The documented config is unchanged.
    - Raise the ScalaFutures patience in SlickSpec and SlickWithTryResultSpec
      from 3 to 10 seconds.
    
    Result:
    The H2 database is no longer closed and reopened between statements, and
    an occasional slow statement no longer fails the specs.
    
    Tests:
    - sbt slick/Test/scalafmt slick/test: Passed: Total 47, Failed 0
    - Resolved slick-h2.db.properties.url ends with ;DB_CLOSE_DELAY=-1
    
    References:
    None - flaky run 
https://github.com/apache/pekko-connectors/actions/runs/36731431219/job/109941785162?pr=1976
    
    * Slick: fork tests so the open H2 database does not leak across 
cross-builds
    
    Motivation:
    With DB_CLOSE_DELAY=-1 the H2 test database stays open until the JVM
    exits. slick tests were not forked, so `sbt +slick/test` ran the Scala
    2.13 and Scala 3 passes in the same sbt JVM, and the Scala 3 pass failed
    with "Database may be already in use" (OverlappingFileLockException)
    because the 2.13 pass still held the file lock.
    
    Modification:
    Set Test / fork := true for the slick project.
    
    Result:
    Each Scala version's tests run in their own JVM, which releases the H2
    file lock on exit.
    
    Tests:
    - sbt +slick/test: Passed: Total 47, Failed 0 on Scala 2.13.18 and 3.3.8
    
    References:
    None - follow-up to the previous commit on this branch
---
 build.sbt                                                       | 5 ++++-
 slick/src/test/resources/application.conf                       | 6 ++++++
 slick/src/test/scala/docs/scaladsl/SlickSpec.scala              | 2 +-
 slick/src/test/scala/docs/scaladsl/SlickWithTryResultSpec.scala | 2 +-
 4 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/build.sbt b/build.sbt
index 4010367d5..c57e5e564 100644
--- a/build.sbt
+++ b/build.sbt
@@ -384,7 +384,10 @@ lazy val springWeb = pekkoConnectorProject(
 
 lazy val simpleCodecs = pekkoConnectorProject("simple-codecs", "simplecodecs")
 
-lazy val slick = pekkoConnectorProject("slick", "slick", Dependencies.Slick)
+lazy val slick = pekkoConnectorProject("slick", "slick", Dependencies.Slick,
+  // the H2 test database stays open (DB_CLOSE_DELAY=-1) until the JVM exits,
+  // so each Scala version of a cross-build needs its own JVM
+  Test / fork := true)
 
 lazy val eventbridge = pekkoConnectorProject("aws-event-bridge", 
"aws.eventbridge",
   Dependencies.Eventbridge)
diff --git a/slick/src/test/resources/application.conf 
b/slick/src/test/resources/application.conf
index 39536f7f0..dab53a687 100644
--- a/slick/src/test/resources/application.conf
+++ b/slick/src/test/resources/application.conf
@@ -25,6 +25,12 @@ slick-h2 {
 }
 #config-h2
 
+# Test-only: keep the H2 database open between connections. With the
+# connection pool disabled, every statement opens a new connection, and
+# by default H2 closes (and later reopens) the database file whenever the
+# last connection closes, which can stall tests on slow CI disks.
+slick-h2.db.properties.url = ${slick-h2.db.properties.url}";DB_CLOSE_DELAY=-1"
+
 # This is an example DB2 database configuration that can be
 # used to run the unit tests against DB2.
 # It assumes a local DB2 database running on port 50000.
diff --git a/slick/src/test/scala/docs/scaladsl/SlickSpec.scala 
b/slick/src/test/scala/docs/scaladsl/SlickSpec.scala
index e448d3a7f..bf695a100 100644
--- a/slick/src/test/scala/docs/scaladsl/SlickSpec.scala
+++ b/slick/src/test/scala/docs/scaladsl/SlickSpec.scala
@@ -60,7 +60,7 @@ class SlickSpec
   }
 
   implicit val ec: ExecutionContext = system.dispatcher
-  implicit val defaultPatience: PatienceConfig = PatienceConfig(timeout = 
3.seconds, interval = 50.millis)
+  implicit val defaultPatience: PatienceConfig = PatienceConfig(timeout = 
10.seconds, interval = 50.millis)
   implicit val getUserResult: GetResult[User] = GetResult(r => 
User(r.nextInt(), r.nextString()))
 
   val users = (1 to 40).map(i => User(i, s"Name$i")).toSet
diff --git a/slick/src/test/scala/docs/scaladsl/SlickWithTryResultSpec.scala 
b/slick/src/test/scala/docs/scaladsl/SlickWithTryResultSpec.scala
index 05104b205..df910aedd 100644
--- a/slick/src/test/scala/docs/scaladsl/SlickWithTryResultSpec.scala
+++ b/slick/src/test/scala/docs/scaladsl/SlickWithTryResultSpec.scala
@@ -57,7 +57,7 @@ class SlickWithTryResultSpec extends AnyWordSpec
   }
 
   implicit val ec: ExecutionContext = system.dispatcher
-  implicit val defaultPatience: PatienceConfig = PatienceConfig(timeout = 
3.seconds, interval = 50.millis)
+  implicit val defaultPatience: PatienceConfig = PatienceConfig(timeout = 
10.seconds, interval = 50.millis)
   implicit val getUserResult: GetResult[User] = GetResult(r => 
User(r.nextInt(), r.nextString()))
 
   val users = (1 to 40).map(i => User(i, s"Name$i")).toSet


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to