chore(postgres): not loading the libpq library by default & better user feedback (#2028)

* removing implicit dependency with libpq if postgres is not being used.
* We only run the postgres tests when explicitly willing to, i.e. make
POSTGRES=1 test. The reason is that the postgres tests expect a
database instance to be running locally.
This commit is contained in:
Ivan Folgueira Bande 2023-09-13 12:45:55 +02:00 committed by GitHub
parent 563b2b20a5
commit e8602021b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 24 deletions

View File

@ -117,7 +117,7 @@ jobs:
sudo docker run --rm -d -e POSTGRES_PASSWORD=test123 -p 5432:5432 postgres:9.6-alpine
fi
make V=1 LOG_LEVEL=DEBUG QUICK_AND_DIRTY_COMPILER=1 test testwakunode2
make V=1 LOG_LEVEL=DEBUG QUICK_AND_DIRTY_COMPILER=1 POSTGRES=1 test testwakunode2
build-docker-image:
needs: changes

View File

@ -106,6 +106,10 @@ ifneq ($(USE_LIBBACKTRACE), 0)
deps: | libbacktrace
endif
ifeq ($(POSTGRES), 1)
NIM_PARAMS := $(NIM_PARAMS) -d:postgres -d:nimDebugDlOpen
endif
clean: | clean-libbacktrace
@ -218,7 +222,7 @@ docs: | build deps
#####################
# -d:insecure - Necessary to enable Prometheus HTTP endpoint for metrics
# -d:chronicles_colors:none - Necessary to disable colors in logs for Docker
DOCKER_IMAGE_NIMFLAGS ?= -d:chronicles_colors:none -d:insecure
DOCKER_IMAGE_NIMFLAGS ?= -d:chronicles_colors:none -d:insecure -d:postgres
DOCKER_IMAGE_NIMFLAGS := $(DOCKER_IMAGE_NIMFLAGS) $(HEAPTRACK_PARAMS)
# build a docker image for the fleet

View File

@ -21,9 +21,10 @@ import
./waku_archive/test_waku_archive
const os* {.strdefine.} = ""
when os == "Linux":
when os == "Linux" and
# GitHub only supports container actions on Linux
# and we need to start a postgress database in a docker container
defined(postgres):
import
./waku_archive/test_driver_postgres_query,
./waku_archive/test_driver_postgres

View File

@ -14,10 +14,6 @@ import
../common/databases/dburl,
../common/databases/db_sqlite,
./driver,
./driver/queue_driver,
./driver/sqlite_driver,
./driver/sqlite_driver/migrations as archive_driver_sqlite_migrations,
./driver/postgres_driver/postgres_driver,
./retention_policy,
./retention_policy/retention_policy_capacity,
./retention_policy/retention_policy_time,

View File

@ -14,13 +14,15 @@ import
../../common/databases/db_sqlite,
./sqlite_driver,
./sqlite_driver/migrations as archive_driver_sqlite_migrations,
./queue_driver,
./postgres_driver
./queue_driver
export
sqlite_driver,
queue_driver,
postgres_driver
queue_driver
when defined(postgres):
import ./postgres_driver ## This import adds dependency with an external libpq library
export postgres_driver
proc new*(T: type ArchiveDriver,
url: string,
@ -78,6 +80,7 @@ proc new*(T: type ArchiveDriver,
return ok(res.get())
of "postgres":
when defined(postgres):
const MaxNumConns = 5 #TODO: we may need to set that from app args (maybe?)
let res = PostgresDriver.new(url, MaxNumConns, onErrAction)
if res.isErr():
@ -95,6 +98,9 @@ proc new*(T: type ArchiveDriver,
return ok(driver)
else:
return err("Postgres has been configured but not been compiled. Check compiler definitions.")
else:
debug "setting up in-memory waku archive driver"
let driver = QueueDriver.new() # Defaults to a capacity of 25.000 messages