module Specs.BySubject.UsageError.AcquisitionTimeoutSpec whereimport Control.Concurrent.Async (race)import Hasql.Poolimport Helpers.Scripts qualified as Scriptsimport Helpers.Sessions qualified as Sessionsimport Test.Hspecimport Preludespec :: SpecWith Scripts.ScopeParamsspec = do it "Gets produced on timeout" \scopeParams -> -- 1ms timeout Scripts.onAutotaggedPool 1 0.001 1_800 1_800 scopeParams \_ pool -> do sleeping <- newEmptyMVar t0 <- getCurrentTime res <- race ( use pool $ liftIO $ do putMVar sleeping () -- 1s threadDelay 1_000_000 ) ( do takeMVar sleeping use pool $ Sessions.selectOne ) t1 <- getCurrentTime res `shouldBe` Right (Left AcquisitionTimeoutUsageError) -- 0.5s diffUTCTime t1 t0 `shouldSatisfy` (< 0.5)