From 5b8b48efb8bcbfa3effa3a04a5bebd2139ee1cc2 Mon Sep 17 00:00:00 2001 From: define-null Date: Fri, 11 Nov 2022 18:05:31 +0100 Subject: [PATCH] [vax-392] Fix sysbench_ws lux and cowboy listenter shutdown in ExUnit tests (#65) --- config/runtime.exs | 5 +++-- integration_tests/single_dc/electric.exs | 10 ++++++++++ integration_tests/single_dc/electric_b.exs | 10 ++++++++++ integration_tests/single_dc/sysbench_ws.lux | 6 +++++- test/electric/satellite/satellite_ws_test.exs | 17 +++++++++++------ 5 files changed, 39 insertions(+), 9 deletions(-) diff --git a/config/runtime.exs b/config/runtime.exs index ad11dbf4..29128a36 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -72,7 +72,8 @@ if config_env() == :prod do # set to the database.cluster_slug global_cluster_id = System.fetch_env!("GLOBAL_CLUSTER_ID") - config :electric, Electric.Satellite, global_cluster_id: global_cluster_id + config :electric, + global_cluster_id: global_cluster_id # key = :crypto.strong_rand_bytes(32) |> Base.encode64() auth_secret_key = System.fetch_env!("SATELLITE_AUTH_SIGNING_KEY") |> Base.decode64!() @@ -86,6 +87,6 @@ if config_env() == :prod do provider: {Electric.Satellite.Auth.JWT, issuer: "electric-sql.com", - secret_key: auth_secret_key, + secret_key: Base.decode64!("AgT/MeUiP3SKzw5gC6BZKXk4t1ulnUvZy2d/O73R0sQ="), global_cluster_id: global_cluster_id} end diff --git a/integration_tests/single_dc/electric.exs b/integration_tests/single_dc/electric.exs index c8451b34..f069c562 100644 --- a/integration_tests/single_dc/electric.exs +++ b/integration_tests/single_dc/electric.exs @@ -69,3 +69,13 @@ config :electric, Electric.Replication.SQConnectors, vaxine_connection_timeout: 5000 config :logger, backends: [:console], level: :debug + +config :electric, + global_cluster_id: "fake-global-id-for-tests" + +config :electric, Electric.Satellite.Auth, + provider: + {Electric.Satellite.Auth.JWT, + issuer: "dev.electric-sql.com", + secret_key: Base.decode64!("AgT/MeUiP3SKzw5gC6BZKXk4t1ulnUvZy2d/O73R0sQ="), + global_cluster_id: "fake-global-id-for-tests"} diff --git a/integration_tests/single_dc/electric_b.exs b/integration_tests/single_dc/electric_b.exs index 54a55356..81da3f18 100644 --- a/integration_tests/single_dc/electric_b.exs +++ b/integration_tests/single_dc/electric_b.exs @@ -40,3 +40,13 @@ config :electric, Electric.Replication.SQConnectors, vaxine_connection_timeout: 5000 config :logger, backends: [:console], level: :debug + +config :electric, Electric.Satellite, + global_cluster_id: "fake-global-id-for-tests" + +config :electric, Electric.Satellite.Auth, + provider: + {Electric.Satellite.Auth.JWT, + issuer: "dev.electric-sql.com", + secret_key: Base.decode64!("AgT/MeUiP3SKzw5gC6BZKXk4t1ulnUvZy2d/O73R0sQ="), + global_cluster_id: "fake-global-id-for-tests"} diff --git a/integration_tests/single_dc/sysbench_ws.lux b/integration_tests/single_dc/sysbench_ws.lux index 696244e9..7633d1f5 100644 --- a/integration_tests/single_dc/sysbench_ws.lux +++ b/integration_tests/single_dc/sysbench_ws.lux @@ -43,9 +43,13 @@ [shell ws1] [invoke log "Start WS client and start consuming data"] [invoke start_elixir_test] + !provider = {Electric.Satellite.Auth.JWT, issuer: "dev.electric-sql.com", \ + secret_key: Base.decode64!("AgT/MeUiP3SKzw5gC6BZKXk4t1ulnUvZy2d/O73R0sQ="), \ + global_cluster_id: "fake-global-id-for-tests"} + ?$eprompt !Electric.Test.SatelliteWsClient.connect_and_spawn( \ [ \ - {:auth, %{user_id: "5a9a8b1d-263d-4cad-90f8-9190396161d7"}}, \ + {:auth, %{auth_provider: provider, user_id: "5a9a8b1d-263d-4cad-90f8-9190396161d7"}}, \ {:id, "ws1"}, \ {:sub, "0"}, \ {:auto_in_sub, true}, \ diff --git a/test/electric/satellite/satellite_ws_test.exs b/test/electric/satellite/satellite_ws_test.exs index ec8d7555..6986b413 100644 --- a/test/electric/satellite/satellite_ws_test.exs +++ b/test/electric/satellite/satellite_ws_test.exs @@ -66,12 +66,17 @@ defmodule Electric.Satellite.WsServerTest do issuer: "electric-sql.com", secret_key: Base.decode64!("BdvUDsCk5QbwkxI0fpEFmM/LNtFvwPZeMfHxvcOoS7s=")} - start_supervised( - {Electric.Satellite.WsServer, name: :ws_test, port: port, auth_provider: auth_provider}, - restart: :temporary - ) - - on_exit(fn -> SchemaRegistry.clear_replicated_tables(@test_publication) end) + sup_pid = + Electric.Satellite.WsServer.start_link( + name: :ws_test, + port: port, + auth_provider: auth_provider + ) + + on_exit(fn -> + SchemaRegistry.clear_replicated_tables(@test_publication) + :cowboy.stop_listener(:ws_test) + end) {:ok, auth_provider: auth_provider, port: port, global_cluster_id: global_cluster_id} end