Skip to content
Snippets Groups Projects
Commit 1106acba authored by Jean-Paul Calderone's avatar Jean-Paul Calderone
Browse files

Speed up the recently added "database is busy" SQLite3 test

It was passing but only after ~57 seconds because the busy_timeout setting in
the test definition was being applied to a different connection than was being
used by the implementation.

With this change we hook into the connection function and apply the shorter
busy_timeout after the normal setup work is done but before handing the
connection off to application code.
parent b2e1b3b9
Branches
No related tags found
1 merge request!69Paid vouchers metrics
......@@ -205,16 +205,24 @@ sqlite3DatabaseVoucherPaymentTests =
sqlite3Tests =
testGroup "SQLite3-specific voucher"
[ testCase "database is busy" $ do
getDB <- makeDatabase
db <- getDB
case db of
aDatabase <- makeDatabase
normalConnection <- aDatabase
case normalConnection of
(SQLiteDB connect) -> do
-- Acquire a write lock before letting the application code run
-- so that the application code is denied the write lock.
normalConn <- connect
fastBusyConn <- fastBusyConnection connect
Sqlite.withExclusiveTransaction normalConn $ do
result <- redeemVoucher fastBusyConn voucher fingerprint
assertEqual "Redeeming voucher while database busy" result $ Left DatabaseUnavailable
]
where
fastBusyConnection
:: IO Sqlite.Connection
-> IO VoucherDatabaseState
fastBusyConnection connect = do
conn <- connect
-- Tweak the timeout down so the test completes quickly
Sqlite.execute_ conn "PRAGMA busy_timeout = 0"
-- Acquire a write lock before letting the application code run so that
-- the application code is denied the write lock.
Sqlite.withExclusiveTransaction conn $ do
result <- redeemVoucher db voucher fingerprint
assertEqual "Redeeming voucher while database busy" result $ Left DatabaseUnavailable
]
return . SQLiteDB . return $ conn
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment