graphql-engine/server/tests-hspec/Harness/Constants.hs
Philip Lykke Carlsen 12c3eddef7 Amendments to the hspec testsuite
This PR proposes some changes to the hspec testsuite:

* It amends the framework to make it easier to test from the ghci REPL
* It introduces a new module `Fixture`, distinguished from `Context` by:
   * using a new concept of `SetupAction`s which bundle setup and teardown actions into one abstraction, making test system state setup more concise, modularized and safe (because the fixture know knows about the ordering of setup actions and can do partial rollbacks)
   * somewhat opinionated, elides the `Options` of `Context`, preferring instead that tests that care about stringification of json numbers manage that themselves.

(Note that this PR builds on #4390, so contains some spurious commits which will become irrelevant once that PR is merged)

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4630
GitOrigin-RevId: 619c8d985aed0aa42de31d6f16891d0782f4b4b5
2022-06-08 16:36:50 +00:00

283 lines
8.0 KiB
Haskell

{-# LANGUAGE DisambiguateRecordFields #-}
-- | Constant configurations used throughout the test suite.
module Harness.Constants
( postgresPassword,
postgresUser,
postgresDb,
postgresHost,
postgresPort,
postgresqlConnectionString,
postgresLivenessCheckAttempts,
postgresLivenessCheckIntervalSeconds,
postgresLivenessCheckIntervalMicroseconds,
mysqlLivenessCheckAttempts,
mysqlLivenessCheckIntervalSeconds,
mysqlLivenessCheckIntervalMicroseconds,
mysqlPassword,
mysqlUser,
mysqlDb,
mysqlHost,
mysqlPort,
mysqlConnectInfo,
sqlserverLivenessCheckAttempts,
sqlserverLivenessCheckIntervalSeconds,
sqlserverLivenessCheckIntervalMicroseconds,
sqlserverConnectInfo,
sqlserverDb,
bigqueryServiceKeyVar,
bigqueryProjectIdVar,
bigqueryDataset,
httpHealthCheckAttempts,
httpHealthCheckIntervalSeconds,
httpHealthCheckIntervalMicroseconds,
citusConnectionString,
citusDb,
serveOptions,
dataConnectorDb,
)
where
-------------------------------------------------------------------------------
import Data.HashSet qualified as Set
import Data.Word (Word16)
import Database.MySQL.Simple qualified as Mysql
import Database.PG.Query qualified as Q
import Hasura.GraphQL.Execute.Subscription.Options qualified as ES
import Hasura.Logging qualified as L
import Hasura.Prelude
import Hasura.RQL.Types.Common (StringifyNumbers (..))
import Hasura.RQL.Types.Function (FunctionPermissionsCtx (FunctionPermissionsInferred))
import Hasura.RQL.Types.RemoteSchema (RemoteSchemaPermsCtx (RemoteSchemaPermsDisabled))
import Hasura.Server.Cors (CorsConfig (CCAllowAll))
import Hasura.Server.Init
( API (CONFIG, DEVELOPER, GRAPHQL, METADATA),
OptionalInterval (..),
ResponseInternalErrorsConfig (..),
ServeOptions (..),
)
import Hasura.Server.Init qualified as Init
import Hasura.Server.Logging (MetadataQueryLoggingMode (MetadataQueryLoggingDisabled))
import Hasura.Server.Types
( EventingMode (EventingEnabled),
ExperimentalFeature (EFStreamingSubscriptions),
MaintenanceMode (MaintenanceModeDisabled),
ReadOnlyMode (ReadOnlyModeDisabled),
)
import Network.WebSockets qualified as WS
-------------------------------------------------------------------------------
-- * Postgres
postgresPassword :: String
postgresPassword = "hasura"
postgresUser :: String
postgresUser = "hasura"
postgresDb :: String
postgresDb = "hasura"
postgresHost :: String
postgresHost = "127.0.0.1"
postgresPort :: Word16
postgresPort = 65002
postgresqlConnectionString :: String
postgresqlConnectionString =
"postgres://"
++ postgresUser
++ ":"
++ postgresPassword
++ "@"
++ postgresHost
++ ":"
++ show postgresPort
++ "/"
++ postgresDb
-- * Citus
citusPassword :: String
citusPassword = "hasura"
citusUser :: String
citusUser = "hasura"
citusDb :: String
citusDb = "hasura"
citusHost :: String
citusHost = "127.0.0.1"
citusPort :: Word16
citusPort = 65004
citusConnectionString :: String
citusConnectionString =
"postgres://"
++ citusUser
++ ":"
++ citusPassword
++ "@"
++ citusHost
++ ":"
++ show citusPort
++ "/"
++ citusDb
-- * DataConnector
dataConnectorDb :: String
dataConnectorDb = "data-connector"
-- * Liveness
postgresLivenessCheckAttempts :: Int
postgresLivenessCheckAttempts = 5
postgresLivenessCheckIntervalSeconds :: Int
postgresLivenessCheckIntervalSeconds = 1
sqlserverLivenessCheckAttempts :: Int
sqlserverLivenessCheckAttempts = 5
sqlserverLivenessCheckIntervalSeconds :: Int
sqlserverLivenessCheckIntervalSeconds = 1
-- | SQL Server has strict password requirements, that's why it's not
-- simply @hasura@ like the others.
sqlserverConnectInfo :: Text
sqlserverConnectInfo = "DRIVER={ODBC Driver 17 for SQL Server};SERVER=127.0.0.1,65003;Uid=hasura;Pwd=Hasura1!;Encrypt=no"
sqlserverDb :: String
sqlserverDb = "hasura"
sqlserverLivenessCheckIntervalMicroseconds :: Int
sqlserverLivenessCheckIntervalMicroseconds = 1000 * 1000 * sqlserverLivenessCheckIntervalSeconds
postgresLivenessCheckIntervalMicroseconds :: Int
postgresLivenessCheckIntervalMicroseconds = 1000 * 1000 * postgresLivenessCheckIntervalSeconds
mysqlLivenessCheckAttempts :: Int
mysqlLivenessCheckAttempts = 5
mysqlLivenessCheckIntervalSeconds :: Int
mysqlLivenessCheckIntervalSeconds = 1
mysqlLivenessCheckIntervalMicroseconds :: Int
mysqlLivenessCheckIntervalMicroseconds = 1000 * 1000 * mysqlLivenessCheckIntervalSeconds
-- * MySQL
mysqlPassword :: String
mysqlPassword = "hasura"
mysqlUser :: String
mysqlUser = "hasura"
mysqlDb :: String
mysqlDb = "hasura"
mysqlHost :: String
mysqlHost = "127.0.0.1"
mysqlPort :: Word16
mysqlPort = 65001
mysqlConnectInfo :: Mysql.ConnectInfo
mysqlConnectInfo =
Mysql.defaultConnectInfo
{ Mysql.connectUser = mysqlUser,
Mysql.connectPassword = mysqlPassword,
Mysql.connectDatabase = mysqlDb,
Mysql.connectHost = mysqlHost,
Mysql.connectPort = mysqlPort
}
bigqueryServiceKeyVar :: String
bigqueryServiceKeyVar = "HASURA_BIGQUERY_SERVICE_KEY"
bigqueryProjectIdVar :: String
bigqueryProjectIdVar = "HASURA_BIGQUERY_PROJECT_ID"
bigqueryDataset :: String
bigqueryDataset = "hasura"
-- * HTTP health checks
httpHealthCheckAttempts :: Int
httpHealthCheckAttempts = 5
httpHealthCheckIntervalSeconds :: Int
httpHealthCheckIntervalSeconds = 1
httpHealthCheckIntervalMicroseconds :: Int
httpHealthCheckIntervalMicroseconds = 1000 * 1000 * httpHealthCheckIntervalSeconds
-- * Server configuration
serveOptions :: ServeOptions L.Hasura
serveOptions =
ServeOptions
{ soPort = 12345, -- The server runner will typically be generating
-- a random port, so this isn't particularly
-- important.
soHost = "0.0.0.0",
soConnParams = Q.defaultConnParams,
soTxIso = Q.Serializable,
soAdminSecret = mempty,
soAuthHook = Nothing,
soJwtSecret = mempty,
soUnAuthRole = Nothing,
soCorsConfig = CCAllowAll,
soEnableConsole = True,
soConsoleAssetsDir = Just "../console/static/dist",
soEnableTelemetry = False,
soStringifyNum = StringifyNumbers,
soDangerousBooleanCollapse = False,
soEnabledAPIs = testSuiteEnabledApis,
soLiveQueryOpts = ES.mkSubscriptionsOptions Nothing Nothing,
soStreamingQueryOpts = ES.mkSubscriptionsOptions Nothing Nothing,
soEnableAllowlist = False,
soEnabledLogTypes = Set.fromList L.userAllowedLogTypes,
soLogLevel = fromMaybe (L.LevelOther "test-suite") engineLogLevel,
soResponseInternalErrorsConfig = InternalErrorsAllRequests,
soEventsHttpPoolSize = Nothing,
soEventsFetchInterval = Nothing,
soAsyncActionsFetchInterval = Skip,
soEnableRemoteSchemaPermissions = RemoteSchemaPermsDisabled,
soConnectionOptions = WS.defaultConnectionOptions,
soWebsocketKeepAlive = Init.defaultKeepAliveDelay,
soInferFunctionPermissions = FunctionPermissionsInferred,
soEnableMaintenanceMode = MaintenanceModeDisabled,
-- MUST be disabled to be able to modify schema.
soSchemaPollInterval = Interval 10,
soExperimentalFeatures = Set.singleton EFStreamingSubscriptions,
soEventsFetchBatchSize = 1,
soDevMode = True,
soGracefulShutdownTimeout = 0, -- Don't wait to shutdown.
soWebsocketConnectionInitTimeout = Init.defaultWSConnectionInitTimeout,
soEventingMode = EventingEnabled,
soReadOnlyMode = ReadOnlyModeDisabled,
soEnableMetadataQueryLogging = MetadataQueryLoggingDisabled,
soDefaultNamingConvention = Nothing
}
-- | What log level should be used by the engine; this is not exported, and
-- only used in 'serveOptions'.
--
-- This should be adjusted locally for debugging purposes; e.g. change it to
-- @Just L.LevelDebug@ to enable all logs.
--
-- See 'L.LogLevel' for an enumeration of available log levels.
engineLogLevel :: Maybe L.LogLevel
engineLogLevel = Nothing
-- These are important for the test suite.
testSuiteEnabledApis :: HashSet API
testSuiteEnabledApis = Set.fromList [METADATA, GRAPHQL, DEVELOPER, CONFIG]