-
Notifications
You must be signed in to change notification settings - Fork 359
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix query cancellation with cancelable
- Loading branch information
1 parent
d1f84e6
commit 90c645c
Showing
29 changed files
with
326 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
modules/core/src/test/scala/doobie/util/QueryCancellationSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) 2013-2020 Rob Norris and Contributors | ||
// This software is licensed under the MIT License (MIT). | ||
// For more information see LICENSE or https://opensource.org/licenses/MIT | ||
|
||
package doobie.util | ||
|
||
import cats.effect.IO | ||
import doobie.Transactor | ||
import doobie.* | ||
import doobie.implicits.* | ||
import cats.syntax.all.* | ||
|
||
import scala.concurrent.duration.DurationInt | ||
|
||
class QueryCancellationSuite extends munit.FunSuite { | ||
import cats.effect.unsafe.implicits.global | ||
|
||
val xa = Transactor.fromDriverManager[IO]( | ||
driver = "org.h2.Driver", | ||
url = "jdbc:h2:mem:queryspec;DB_CLOSE_DELAY=-1", | ||
user = "sa", | ||
password = "", | ||
logHandler = None | ||
) | ||
|
||
test("Query cancel") { | ||
val scenario = WeakAsync.liftIO[ConnectionIO].use { elevator => | ||
for { | ||
_ <- sql"CREATE TABLE IF NOT EXISTS example_table ( id INT)".update.run.transact(xa) | ||
_ <- sql"TRUNCATE TABLE example_table".update.run.transact(xa) | ||
_ <- sql"INSERT INTO example_table (id) VALUES (1)".update.run.transact(xa) | ||
_ <- { | ||
sql"select * from example_table for update".query[Int].unique >> elevator.liftIO(IO.never) | ||
}.transact(xa).start | ||
|
||
insertWithLockFiber <- { | ||
for { | ||
_ <- IO.sleep(100.milli) | ||
insertFiber <- sql"UPDATE example_table SET id = 2".update.run.transact(xa).start | ||
_ <- IO.sleep(100.milli) | ||
_ <- insertFiber.cancel | ||
} yield () | ||
}.start | ||
|
||
_ <- IO.race(insertWithLockFiber.join, IO.sleep(5.seconds) >> IO(fail("Cancellation is blocked"))) | ||
result <- sql"SELECT * FROM example_table".query[Int].to[List].transact(xa) | ||
} yield assertEquals(result, List(1)) | ||
} | ||
scenario.unsafeRunSync() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.