[tests] fix pgmq docker image

Also, fixes to getting conn info from env vars (for tests)
parent 46ed4e1e
Pipeline #6412 failed with stages
in 15 minutes and 4 seconds
......@@ -22,7 +22,7 @@ pgmq-integration-tests:
stage: integration-tests
image: haskell:9.4.7-slim
services:
- name: quay.io/tembo/pg16-pgmq:latest
- name: docker.io/cgenie/pgmq:16-1.3.3.1
alias: pgmq
variables:
# Configure postgres service (https://hub.docker.com/_/postgres/)
......
......@@ -11,7 +11,7 @@ There is a binary in [./bin/simple-test/Main.hs](./bin/simple-test/Main.hs), it
First, let's decide which container to use:
```shell
export PGMQ_CONTAINER=quay.io/tembo/pg-16.pgmq:latest
export PGMQ_CONTAINER=docker.io/cgenie/pgmq:16-1.3.3.1
```
However with the above, some tests might fail because some functions
throw errors when a table is not there (e.g. `pgmq.drop_queue`).
......
......@@ -14,10 +14,10 @@ where
import Async.Worker.Broker.PGMQ (BrokerInitParams(..), PGMQBroker)
import Async.Worker.Broker.Types qualified as BT
import Control.Exception (bracket)
import Database.PostgreSQL.Simple qualified as PSQL
import Data.Aeson (ToJSON(..), FromJSON(..), withText)
import Data.Text qualified as T
import Test.Hspec
import Test.Integration.PGMQ.Simple (getEnvConnectInfo)
data TestEnv b =
......@@ -38,11 +38,10 @@ instance FromJSON Message where
pure $ Message { text = T.unpack text }
pgmqBrokerInitParams :: BT.BrokerInitParams PGMQBroker Message
pgmqBrokerInitParams =
PGMQBrokerInitParams $
PSQL.defaultConnectInfo { PSQL.connectUser = "postgres"
, PSQL.connectDatabase = "postgres" }
pgmqBrokerInitParams :: IO (BT.BrokerInitParams PGMQBroker Message)
pgmqBrokerInitParams = do
connectInfo <- getEnvConnectInfo
pure $ PGMQBrokerInitParams connectInfo
withBroker :: (BT.HasBroker b Message)
......
module Test.Integration.PGMQ.Simple
( pgmqSimpleTests )
( pgmqSimpleTests
, getEnvConnectInfo )
where
import Async.Worker.Broker qualified as B
......@@ -23,17 +24,21 @@ data TestEnv =
testQueue :: B.Queue
testQueue = "test"
setUpConn :: IO TestEnv
setUpConn = do
getEnvConnectInfo :: IO PSQL.ConnectInfo
getEnvConnectInfo = do
pgUser <- lookupEnv "POSTGRES_USER"
pgDb <- lookupEnv "POSTGRES_DB"
pgPass <- lookupEnv "POSTGRES_PASSWORD"
pgHost <- lookupEnv "POSTGRES_HOST"
-- https://hackage.haskell.org/package/postgresql-simple-0.7.0.0/docs/Database-PostgreSQL-Simple.html#t:ConnectInfo
let connInfo = PSQL.defaultConnectInfo { PSQL.connectUser = fromMaybe "postgres" pgUser
, PSQL.connectDatabase = fromMaybe "postgres" pgDb
, PSQL.connectHost = fromMaybe "localhost" pgHost
, PSQL.connectPassword = fromMaybe "postgres" pgPass }
pure $ PSQL.defaultConnectInfo { PSQL.connectUser = fromMaybe "postgres" pgUser
, PSQL.connectDatabase = fromMaybe "postgres" pgDb
, PSQL.connectHost = fromMaybe "localhost" pgHost
, PSQL.connectPassword = fromMaybe "postgres" pgPass }
setUpConn :: IO TestEnv
setUpConn = do
connInfo <- getEnvConnectInfo
conn <- PSQL.connect connInfo
return $ TestEnv { conn, queue = testQueue }
......
......@@ -21,8 +21,8 @@ import Control.Concurrent.STM (atomically)
import Control.Concurrent.STM.TVar
import Control.Exception (bracket, Exception, throwIO)
import Data.Aeson (ToJSON(..), FromJSON(..), object, (.=), (.:), withObject)
import Database.PostgreSQL.Simple qualified as PSQL
import Test.Hspec
import Test.Integration.PGMQ.Simple (getEnvConnectInfo)
data TestEnv b =
......@@ -153,8 +153,7 @@ second :: Int
second = 1000000
pgmqWorkerBrokerInitParams :: BT.BrokerInitParams PGMQBroker (Job Message)
pgmqWorkerBrokerInitParams =
PGMQBrokerInitParams $
PSQL.defaultConnectInfo { PSQL.connectUser = "postgres"
, PSQL.connectDatabase = "postgres" }
pgmqWorkerBrokerInitParams :: IO (BT.BrokerInitParams PGMQBroker (Job Message))
pgmqWorkerBrokerInitParams = do
connectInfo <- getEnvConnectInfo
pure $ PGMQBrokerInitParams connectInfo
......@@ -10,8 +10,10 @@ import Test.Tasty.Hspec
main :: IO ()
main = do
brokerSpec <- testSpec "brokerTests" (brokerTests pgmqBrokerInitParams)
workerSpec <- testSpec "workerTests" (workerTests pgmqWorkerBrokerInitParams)
pgmqBInitParams <- pgmqBrokerInitParams
brokerSpec <- testSpec "brokerTests" (brokerTests pgmqBInitParams)
pgmqWBInitParams <- pgmqWorkerBrokerInitParams
workerSpec <- testSpec "workerTests" (workerTests pgmqWBInitParams)
pgmqSimpleSpec <- testSpec "pgmqSimpleTests" pgmqSimpleTests
defaultMain $ testGroup "integration tests"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment