Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(e2e): Add a new E2E test for sync service configuration #1319

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions e2e/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ DOCKER_REGISTRY = europe-docker.pkg.dev/vaxine/vaxine-io

# using a realistic password for the proxy to prevent accidentally working tests
# with some default "password"
export PG_PROXY_PASSWORD?=49_G1JYY0BXWldjnA2EFxhWl
export PG_PROXY_PORT?=65432
PG_PROXY_PASSWORD?=49_G1JYY0BXWldjnA2EFxhWl
PG_PROXY_PORT?=65432

export UID=$(shell id -u)
export GID=$(shell id -g)
Expand Down Expand Up @@ -66,11 +66,25 @@ log_dev_env:
docker compose -f ${DOCKER_COMPOSE_FILE} logs --no-color --follow pg_1

start_electric_%:
docker compose -f ${DOCKER_COMPOSE_FILE} up --no-color --no-log-prefix electric_$*
PG_PROXY_PASSWORD=${PG_PROXY_PASSWORD} PG_PROXY_PORT=${PG_PROXY_PORT} docker compose -f ${DOCKER_COMPOSE_FILE} up --no-color --no-log-prefix --abort-on-container-exit electric_$*

stop_electric_%:
docker compose -f ${DOCKER_COMPOSE_FILE} stop electric_$*

run_electric_%:
docker run --rm \
-e AUTH_MODE \
-e AUTH_JWT_ALG \
-e AUTH_JWT_KEY \
-e DATABASE_URL \
-e ELECTRIC_TELEMETRY=disabled \
-e ELECTRIC_WRITE_TO_PG_MODE \
-e LOG_LEVEL \
-e LOGICAL_PUBLISHER_HOST \
-e PG_PROXY_PASSWORD \
--name e2e_test_electric_$* \
${ELECTRIC_IMAGE}

stop_dev_env:
if [ -n "`docker ps --filter name=elixir_client --format '{{.Names}}'`" ]; then \
docker ps --filter name=elixir_client --format '{{.Names}}' | xargs docker kill; \
Expand Down
1 change: 1 addition & 0 deletions e2e/services_templates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ services:
ELECTRIC_FEATURES:
init: true
stop_signal: SIGINT # use SIGINT as the more speedy alternative to SIGTERM
restart: "no"

sysbench:
image: "${SYSBENCH_IMAGE}"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
[doc Validate Electric's error reporting when it encounters configuration problems]
[include _shared.luxinc]

[macro match_error_prologue]
??CONFIGURATION ERROR
??The following required configuration options have invalid or missing values:
[endmacro]

[macro match_error_epilogue]
??Please review the official configuration reference at
??https://electric-sql.com/docs/api/service
??••• Shutting down •••
[endmacro]

[newshell electric]
[timeout 4]

[invoke run_electric 1]
[invoke match_error_prologue]
??* AUTH_JWT_ALG not set
??* DATABASE_URL not set
??* LOGICAL_PUBLISHER_HOST not set
??* PG_PROXY_PASSWORD not set
[invoke match_error_epilogue]

[invoke run_electric_with_env 1 "AUTH_MODE=foo DATABASE_URL=http://"]
[invoke match_error_prologue]
??* AUTH_MODE has invalid value: "foo". Must be one of ["secure", "insecure"]
??* DATABASE_URL has invalid URL scheme: "http"
[invoke match_error_epilogue]

[invoke run_electric_with_env 1 "AUTH_JWT_ALG=unknown"]
[invoke match_error_prologue]
??* AUTH_JWT_ALG has invalid value: "unknown". Must be one of [\
"HS256", "HS384", "HS512", "RS256", "RS384", "RS512", "ES256", "ES384", "ES512"]
[invoke match_error_epilogue]

[invoke run_electric_with_env 1 "AUTH_JWT_ALG=HS256 AUTH_JWT_KEY=foo"]
[invoke match_error_prologue]
??* AUTH_JWT_KEY has to be at least 32 bytes long for HS256
[invoke match_error_epilogue]

[shell electric]
[invoke run_electric_with_env 1 "DATABASE_URL=postgresql://user:pass@invalid/db AUTH_MODE=insecure ELECTRIC_WRITE_TO_PG_MODE=direct_writes PG_PROXY_PASSWORD=foo"]
??INITIALISATION ERROR

??Failed to resolve the database domain name to an IP address.

??Double-check the value of DATABASE_URL and make sure to set
??DATABASE_USE_IPV6=true if your database is only reachable using IPv6.
??••• Shutting down •••

# [newshell electric_2]
# [invoke run_electric 2]
# ??Successfully initialized Postgres connector "postgres_1"

# [shell electric]
# [invoke run_electric 1]
# -

# ??Failed to establish replication connection to Postgres:
# ?? #{msg}
# ??
# ??Another instance of Electric appears to be connected to this database.
# ??Refer to https://github.com/electric-sql/electric/issues/971 for additional info.

# [cleanup]
# [invoke teardown]
8 changes: 8 additions & 0 deletions e2e/tests/_shared.luxinc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@
[invoke ok]
[endmacro]

[macro run_electric n]
!make run_electric_${n}
[endmacro]

[macro run_electric_with_env n env_str]
!${env_str} make run_electric_${n}
[endmacro]

[macro teardown]
[progress stop development environment]
!make stop_dev_env
Expand Down
19 changes: 18 additions & 1 deletion e2e/tests/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,24 @@ services:
file: ../services_templates.yaml
service: electric
environment:
DATABASE_URL: postgresql://postgres:password@pg_1:5432/electric
DATABASE_URL: "${DATABASE_URL:-postgresql://postgres:password@pg_1:5432/electric}"
DATABASE_REQUIRE_SSL: false
ELECTRIC_WRITE_TO_PG_MODE: "${ELECTRIC_WRITE_TO_PG_MODE:-logical_replication}"
LOGICAL_PUBLISHER_HOST: electric_1
PG_PROXY_LOG_LEVEL: info
ports:
- "5133:5133"
# proxy access
- "65432:65432"
depends_on:
- pg_1

electric_2:
extends:
file: ../services_templates.yaml
service: electric
environment:
DATABASE_URL: "${DATABASE_URL:-postgresql://postgres:password@pg_1:5432/electric}"
DATABASE_REQUIRE_SSL: false
ELECTRIC_WRITE_TO_PG_MODE: "${ELECTRIC_WRITE_TO_PG_MODE:-logical_replication}"
LOGICAL_PUBLISHER_HOST: electric_1
Expand Down
Loading