Skip to content

Commit f546667

Browse files
committed
test: Add reproducer of 4622 (negative connection count)
1 parent e41d033 commit f546667

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

test/observability/Observation/ToxiSpec.hs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ import Control.Monad.Trans.Control (liftBaseDiscard)
88
import Network.Wai (Application)
99
import ObsHelper
1010
import qualified PostgREST.AppState as AppState
11+
import PostgREST.Metrics (MetricsState (poolAvailable))
12+
import qualified PostgREST.Metrics as Metric
13+
import Prometheus (getGauge)
1114
import Protolude hiding (get)
1215
import Test.Hspec (SpecWith, describe, it)
16+
import Test.Hspec.Expectations
1317
import Test.Hspec.Wai
1418
import 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

Comments
 (0)