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 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"