Right now listening sockets initialization, management and usage is split between App, AppState and Admin modules: they are created in AppState.init and remembered in AppState but used only in App and Admin. It has several negative consequences: - sockets are initialized even if not needed (eg. command line invocations like dump-config or dump-schema) - it is impossible to start listening on a socket after initial schema cache load because it requires AppState This change decouples listen socket management from AppState. Sockets are created only when needed (ie. not in command line tools invocation) and passed to admin application and to Warp by the App module.
55 lines
1.8 KiB
Haskell
55 lines
1.8 KiB
Haskell
module Main where
|
|
|
|
import qualified Hasql.Pool as P
|
|
import qualified Hasql.Pool.Config as P
|
|
import qualified Hasql.Transaction.Sessions as HT
|
|
|
|
import Data.Function (id)
|
|
|
|
import PostgREST.App (postgrest)
|
|
import qualified PostgREST.AppState as AppState
|
|
import PostgREST.Config (AppConfig (..))
|
|
import PostgREST.Config.Database (queryPgVersion)
|
|
import qualified PostgREST.Logger as Logger
|
|
import qualified PostgREST.Metrics as Metrics
|
|
import PostgREST.SchemaCache (querySchemaCache)
|
|
|
|
import qualified Observation.JwtCache
|
|
|
|
import ObsHelper
|
|
import Protolude hiding (toList, toS)
|
|
import Test.Hspec
|
|
|
|
main :: IO ()
|
|
main = do
|
|
pool <- P.acquire $ P.settings
|
|
[ P.size 3
|
|
, P.acquisitionTimeout 10
|
|
, P.agingTimeout 60
|
|
, P.idlenessTimeout 60
|
|
, P.staticConnectionSettings (toUtf8 $ configDbUri testCfg)
|
|
]
|
|
|
|
actualPgVersion <- either (panic . show) id <$> P.use pool (queryPgVersion False)
|
|
|
|
-- cached schema cache so most tests run fast
|
|
baseSchemaCache <- loadSCache pool testCfg
|
|
loggerState <- Logger.init
|
|
metricsState <- Metrics.init (configDbPoolSize testCfg)
|
|
|
|
let
|
|
initApp sCache st config = do
|
|
appState <- AppState.initWithPool pool config loggerState metricsState (Metrics.observationMetrics metricsState)
|
|
AppState.putPgVersion appState actualPgVersion
|
|
AppState.putSchemaCache appState (Just sCache)
|
|
return (st, postgrest (configLogLevel config) appState (pure ()))
|
|
|
|
-- Run all test modules
|
|
hspec $ do
|
|
before (initApp baseSchemaCache metricsState testCfgJwtCache) $
|
|
describe "Observation.JwtCacheObs" Observation.JwtCache.spec
|
|
|
|
where
|
|
loadSCache pool conf =
|
|
either (panic.show) id <$> P.use pool (HT.transaction HT.ReadCommitted HT.Read $ querySchemaCache conf)
|