From 25f4b5448cac6e6c84f5dbfaedbafe6fd1b1cf9f Mon Sep 17 00:00:00 2001 From: ruslandoga <67764432+ruslandoga@users.noreply.github.com> Date: Thu, 31 Oct 2024 17:30:35 +0700 Subject: [PATCH] add fix --- lib/ch/connection.ex | 2 ++ test/ch/connect_test.exs | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/ch/connection.ex b/lib/ch/connection.ex index 3742f47..e260819 100644 --- a/lib/ch/connection.ex +++ b/lib/ch/connection.ex @@ -50,6 +50,8 @@ defmodule Ch.Connection do {:error, reason} end end + catch + _kind, reason -> {:error, reason} end @impl true diff --git a/test/ch/connect_test.exs b/test/ch/connect_test.exs index ada282d..961aaf6 100644 --- a/test/ch/connect_test.exs +++ b/test/ch/connect_test.exs @@ -1,13 +1,22 @@ defmodule Ch.ConnectTest do - use ExUnit.Case, async: true + use ExUnit.Case + import ExUnit.CaptureLog @tag :slow test "retries to connect even with exceptions" do - {:ok, conn} = - Ch.start_link(database: Ch.Test.database(), transport_opts: [sndbuf: nil]) + # See https://github.com/plausible/ch/issues/208 + bad_transport_opts = [sndbuf: nil] - :timer.sleep(100) + logs = + capture_log(fn -> + {:ok, conn} = + Ch.start_link(database: Ch.Test.database(), transport_opts: bad_transport_opts) - assert Process.alive?(conn) + :timer.sleep(100) + + assert Process.alive?(conn) + end) + + assert logs =~ "failed to connect: ** (ArgumentError) argument error" end end