From 5a70a6e881cda555472e88ff7ee4e0f6f319be81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 22 Apr 2025 17:36:13 +0200 Subject: [PATCH 1/2] Quote identifier names --- lib/strategy.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/strategy.ex b/lib/strategy.ex index bff79e5..7bc467b 100644 --- a/lib/strategy.ex +++ b/lib/strategy.ex @@ -78,7 +78,7 @@ defmodule LibclusterPostgres.Strategy do def handle_info(:heartbeat, state) do Process.cancel_timer(state.meta.heartbeat_ref) - Postgrex.query(state.meta.conn, "NOTIFY #{state.config[:channel_name]}, '#{node()}'", []) + Postgrex.query(state.meta.conn, "NOTIFY \"#{state.config[:channel_name]}\", '#{node()}'", []) ref = heartbeat(state.config[:heartbeat_interval]) {:noreply, put_in(state.meta.heartbeat_ref, ref)} end From 4a35941f570aeb87eac3cc8d5c5b102b455e0e70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 22 Apr 2025 17:39:32 +0200 Subject: [PATCH 2/2] Test --- test/strategy_test.exs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/strategy_test.exs b/test/strategy_test.exs index c9f317c..9041a1f 100644 --- a/test/strategy_test.exs +++ b/test/strategy_test.exs @@ -26,6 +26,20 @@ defmodule LibclusterPostgres.StrategyTest do assert_receive {:notification, _, _, ^channel_name, ^node}, 1000 end + @quoted_config Keyword.put(@config, :channel_name, "123_oops") + test "sends psql notification with cluster information to a channel that requires quoting" do + verify_conn_notification = start_supervised!({Notifications, @quoted_config}) + Notifications.listen(verify_conn_notification, @quoted_config[:channel_name]) + + topologies = [postgres: [strategy: LibclusterPostgres.Strategy, config: @quoted_config]] + start_supervised!({Cluster.Supervisor, [topologies]}) + + channel_name = @quoted_config[:channel_name] + node = "#{node()}" + + assert_receive {:notification, _, _, ^channel_name, ^node}, 1000 + end + describe "connect via cookie" do @cookie_config Keyword.put(@config, :channel_name, "my_random__123_long_cookie") @cookie :"my-random-#123-long-cookie"