@@ -8,8 +8,12 @@ import Control.Monad.Trans.Control (liftBaseDiscard)
88import Network.Wai (Application )
99import ObsHelper
1010import qualified PostgREST.AppState as AppState
11+ import PostgREST.Metrics (MetricsState (poolAvailable ))
12+ import qualified PostgREST.Metrics as Metric
13+ import Prometheus (getGauge )
1114import Protolude hiding (get )
1215import Test.Hspec (SpecWith , describe , it )
16+ import Test.Hspec.Expectations
1317import Test.Hspec.Wai
1418import Toxiproxy (withDisabled )
1519
@@ -32,3 +36,18 @@ spec = describe "Tests using Toxiproxy" $ do
3236 liftBaseDiscard (withDisabled specToxiProxy) $ do
3337 void $ get " /items?id=eq.5"
3438 `shouldRespondWith` 503
39+
40+ it " Must not have negative connection count" $ do
41+ SpecState {specAppState, specToxiProxy, specMetrics= Metric. MetricsState {poolAvailable}} <- getState
42+
43+ -- make sure there are no open connections
44+ liftIO $ AppState. flushPool specAppState
45+
46+ liftBaseDiscard (withDisabled specToxiProxy) $ do
47+ replicateM_ 5 $ get " /authors_only?id=eq.5"
48+ `shouldRespondWith` 503
49+
50+ -- TODO https://github.com/PostgREST/postgrest/issues/4622
51+ -- change to 0 when fixed
52+ -- HSpec does not support xfail which should be used instead
53+ liftIO $ getGauge poolAvailable >>= (`shouldBe` (- 5 :: Int )) . round
0 commit comments