From a521d0a52ea0c2b8005f082a62bda980e27a775e Mon Sep 17 00:00:00 2001 From: kp-cat <52385411+kp-cat@users.noreply.github.com> Date: Fri, 20 Sep 2024 11:44:11 +0200 Subject: [PATCH 01/27] fix test --- test/config_cat_test.exs | 2 +- test/using_block_test.exs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/config_cat_test.exs b/test/config_cat_test.exs index 9253e826..2894a9ba 100644 --- a/test/config_cat_test.exs +++ b/test/config_cat_test.exs @@ -1,5 +1,5 @@ defmodule ConfigCatTest do - use ConfigCat.ClientCase, async: true + use ConfigCat.ClientCase, async: false import ExUnit.CaptureLog import Jason.Sigil diff --git a/test/using_block_test.exs b/test/using_block_test.exs index ab788d4d..759333a7 100644 --- a/test/using_block_test.exs +++ b/test/using_block_test.exs @@ -2,7 +2,7 @@ defmodule ConfigCat.UsingBlockTest do # Must be async: false to avoid a collision with the integration tests. # Now that we only allow a single ConfigCat instance to use the same SDK key, # one of the async tests would fail due to the existing running instance. - use ExUnit.Case, async: false + use ConfigCat.Case, async: false defmodule CustomModule do @moduledoc false From 43493e6e5b9abdb68d32678c781bf1b6d37acf3b Mon Sep 17 00:00:00 2001 From: kp-cat <52385411+kp-cat@users.noreply.github.com> Date: Fri, 20 Sep 2024 13:35:21 +0200 Subject: [PATCH 02/27] comment out block test --- test/using_block_test.exs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/using_block_test.exs b/test/using_block_test.exs index 759333a7..31e6e1e1 100644 --- a/test/using_block_test.exs +++ b/test/using_block_test.exs @@ -4,17 +4,17 @@ defmodule ConfigCat.UsingBlockTest do # one of the async tests would fail due to the existing running instance. use ConfigCat.Case, async: false - defmodule CustomModule do - @moduledoc false - use ConfigCat, sdk_key: "configcat-sdk-1/PKDVCLf-Hq-h-kCzMp-L7Q/1cGEJXUwYUGZCBOL-E2sOw" - end + # defmodule CustomModule do + # @moduledoc false + # use ConfigCat, sdk_key: "configcat-sdk-1/PKDVCLf-Hq-h-kCzMp-L7Q/1cGEJXUwYUGZCBOL-E2sOw" + # end test "can call API through using block" do - _pid = start_supervised!(CustomModule) + # _pid = start_supervised!(CustomModule) - :ok = CustomModule.force_refresh() + # :ok = CustomModule.force_refresh() - assert CustomModule.get_value("keySampleText", "default value") == - "This text came from ConfigCat" + # assert CustomModule.get_value("keySampleText", "default value") == + # "This text came from ConfigCat" end end From afafa2573546aeec5f3745ab8fffb0e03300eb4f Mon Sep 17 00:00:00 2001 From: kp-cat <52385411+kp-cat@users.noreply.github.com> Date: Fri, 20 Sep 2024 14:10:30 +0200 Subject: [PATCH 03/27] remove commented block --- test/using_block_test.exs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/using_block_test.exs b/test/using_block_test.exs index 31e6e1e1..759333a7 100644 --- a/test/using_block_test.exs +++ b/test/using_block_test.exs @@ -4,17 +4,17 @@ defmodule ConfigCat.UsingBlockTest do # one of the async tests would fail due to the existing running instance. use ConfigCat.Case, async: false - # defmodule CustomModule do - # @moduledoc false - # use ConfigCat, sdk_key: "configcat-sdk-1/PKDVCLf-Hq-h-kCzMp-L7Q/1cGEJXUwYUGZCBOL-E2sOw" - # end + defmodule CustomModule do + @moduledoc false + use ConfigCat, sdk_key: "configcat-sdk-1/PKDVCLf-Hq-h-kCzMp-L7Q/1cGEJXUwYUGZCBOL-E2sOw" + end test "can call API through using block" do - # _pid = start_supervised!(CustomModule) + _pid = start_supervised!(CustomModule) - # :ok = CustomModule.force_refresh() + :ok = CustomModule.force_refresh() - # assert CustomModule.get_value("keySampleText", "default value") == - # "This text came from ConfigCat" + assert CustomModule.get_value("keySampleText", "default value") == + "This text came from ConfigCat" end end From 8bc5f118e5c048787d63aca0200f58553e2f3a29 Mon Sep 17 00:00:00 2001 From: kp-cat <52385411+kp-cat@users.noreply.github.com> Date: Fri, 20 Sep 2024 14:14:57 +0200 Subject: [PATCH 04/27] async: false test comment --- test/config_cat_test.exs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/config_cat_test.exs b/test/config_cat_test.exs index 2894a9ba..4503312e 100644 --- a/test/config_cat_test.exs +++ b/test/config_cat_test.exs @@ -1,4 +1,7 @@ defmodule ConfigCatTest do + # Must be async: false to avoid a collision with other tests. + # Now that we only allow a single ConfigCat instance to use the same SDK key, + # one of the async tests would fail due to the existing running instance. use ConfigCat.ClientCase, async: false import ExUnit.CaptureLog From 6d21c8d2f1490eaefee33376ec554ea1a7f21bad Mon Sep 17 00:00:00 2001 From: kp-cat <52385411+kp-cat@users.noreply.github.com> Date: Fri, 20 Sep 2024 14:29:24 +0200 Subject: [PATCH 05/27] comment out block test --- test/using_block_test.exs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/using_block_test.exs b/test/using_block_test.exs index 759333a7..31e6e1e1 100644 --- a/test/using_block_test.exs +++ b/test/using_block_test.exs @@ -4,17 +4,17 @@ defmodule ConfigCat.UsingBlockTest do # one of the async tests would fail due to the existing running instance. use ConfigCat.Case, async: false - defmodule CustomModule do - @moduledoc false - use ConfigCat, sdk_key: "configcat-sdk-1/PKDVCLf-Hq-h-kCzMp-L7Q/1cGEJXUwYUGZCBOL-E2sOw" - end + # defmodule CustomModule do + # @moduledoc false + # use ConfigCat, sdk_key: "configcat-sdk-1/PKDVCLf-Hq-h-kCzMp-L7Q/1cGEJXUwYUGZCBOL-E2sOw" + # end test "can call API through using block" do - _pid = start_supervised!(CustomModule) + # _pid = start_supervised!(CustomModule) - :ok = CustomModule.force_refresh() + # :ok = CustomModule.force_refresh() - assert CustomModule.get_value("keySampleText", "default value") == - "This text came from ConfigCat" + # assert CustomModule.get_value("keySampleText", "default value") == + # "This text came from ConfigCat" end end From e69992c9f08eb1595b95bf9d46a230a7ccf09448 Mon Sep 17 00:00:00 2001 From: kp-cat <52385411+kp-cat@users.noreply.github.com> Date: Fri, 20 Sep 2024 18:16:08 +0200 Subject: [PATCH 06/27] test trace --- .github/workflows/elixir-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/elixir-ci.yml b/.github/workflows/elixir-ci.yml index b42aac33..bc13dbf5 100644 --- a/.github/workflows/elixir-ci.yml +++ b/.github/workflows/elixir-ci.yml @@ -58,7 +58,7 @@ jobs: run: mix dialyzer - name: Execute tests - run: mix coveralls.json --warnings-as-errors + run: mix coveralls.json --warnings-as-errors --trace - name: Upload coverage report run: bash <(curl -s https://codecov.io/bash) From da24d76d910365627faf5eeb51826e316fd50fec Mon Sep 17 00:00:00 2001 From: kp-cat <52385411+kp-cat@users.noreply.github.com> Date: Fri, 20 Sep 2024 19:13:30 +0200 Subject: [PATCH 07/27] validate sdk integration test turned off --- test/integration_test.exs | 74 +++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/test/integration_test.exs b/test/integration_test.exs index 78b687b1..6801a1ce 100644 --- a/test/integration_test.exs +++ b/test/integration_test.exs @@ -24,38 +24,38 @@ defmodule ConfigCat.IntegrationTest do |> assert_sdk_key_required() end - for {sdk_key, custom_base_url?, valid?} <- [ - {"sdk-key-90123456789012", false, false}, - {"sdk-key-9012345678901/1234567890123456789012", false, false}, - {"sdk-key-90123456789012/123456789012345678901", false, false}, - {"sdk-key-90123456789012/12345678901234567890123", false, false}, - {"sdk-key-901234567890123/1234567890123456789012", false, false}, - {"sdk-key-90123456789012/1234567890123456789012", false, true}, - {"configcat-sdk-1/sdk-key-90123456789012", false, false}, - {"configcat-sdk-1/sdk-key-9012345678901/1234567890123456789012", false, false}, - {"configcat-sdk-1/sdk-key-90123456789012/123456789012345678901", false, false}, - {"configcat-sdk-1/sdk-key-90123456789012/12345678901234567890123", false, false}, - {"configcat-sdk-1/sdk-key-901234567890123/1234567890123456789012", false, false}, - {"configcat-sdk-1/sdk-key-90123456789012/1234567890123456789012", false, true}, - {"configcat-sdk-2/sdk-key-90123456789012/1234567890123456789012", false, false}, - {"configcat-proxy/", false, false}, - {"configcat-proxy/", true, false}, - {"configcat-proxy/sdk-key-90123456789012", false, false}, - {"configcat-proxy/sdk-key-90123456789012", true, true} - ] do - test "validates SDK key format - sdk_key: #{sdk_key} | custom_base_url: #{custom_base_url?}" do - sdk_key = unquote(sdk_key) - custom_base_url? = unquote(custom_base_url?) - valid? = unquote(valid?) - options = if custom_base_url?, do: [base_url: "https://my-configcat-proxy"], else: [] - - if valid? do - assert {:ok, _} = start(sdk_key, options) - else - sdk_key |> start(options) |> assert_sdk_key_invalid(sdk_key) - end - end - end + # for {sdk_key, custom_base_url?, valid?} <- [ + # {"sdk-key-90123456789012", false, false}, + # {"sdk-key-9012345678901/1234567890123456789012", false, false}, + # {"sdk-key-90123456789012/123456789012345678901", false, false}, + # {"sdk-key-90123456789012/12345678901234567890123", false, false}, + # {"sdk-key-901234567890123/1234567890123456789012", false, false}, + # {"sdk-key-90123456789012/1234567890123456789012", false, true}, + # {"configcat-sdk-1/sdk-key-90123456789012", false, false}, + # {"configcat-sdk-1/sdk-key-9012345678901/1234567890123456789012", false, false}, + # {"configcat-sdk-1/sdk-key-90123456789012/123456789012345678901", false, false}, + # {"configcat-sdk-1/sdk-key-90123456789012/12345678901234567890123", false, false}, + # {"configcat-sdk-1/sdk-key-901234567890123/1234567890123456789012", false, false}, + # {"configcat-sdk-1/sdk-key-90123456789012/1234567890123456789012", false, true}, + # {"configcat-sdk-2/sdk-key-90123456789012/1234567890123456789012", false, false}, + # {"configcat-proxy/", false, false}, + # {"configcat-proxy/", true, false}, + # {"configcat-proxy/sdk-key-90123456789012", false, false}, + # {"configcat-proxy/sdk-key-90123456789012", true, true} + # ] do + # test "validates SDK key format - sdk_key: #{sdk_key} | custom_base_url: #{custom_base_url?}" do + # sdk_key = unquote(sdk_key) + # custom_base_url? = unquote(custom_base_url?) + # valid? = unquote(valid?) + # options = if custom_base_url?, do: [base_url: "https://my-configcat-proxy"], else: [] + + # if valid? do + # assert {:ok, _} = start(sdk_key, options) + # else + # sdk_key |> start(options) |> assert_sdk_key_invalid(sdk_key) + # end + # end + # end test "allows older format SDK keys" do assert {:ok, _} = start("1234567890abcdefghijkl/1234567890abcdefghijkl") @@ -167,12 +167,12 @@ defmodule ConfigCat.IntegrationTest do start_config_cat(sdk_key, options) end - defp assert_sdk_key_invalid({:error, result}, sdk_key) do - assert {{:EXIT, {error, _stacktrace}}, _spec} = result + # defp assert_sdk_key_invalid({:error, result}, sdk_key) do + # assert {{:EXIT, {error, _stacktrace}}, _spec} = result - expected_message = "SDK Key `#{sdk_key}` is invalid." - assert %ArgumentError{message: ^expected_message} = error - end + # expected_message = "SDK Key `#{sdk_key}` is invalid." + # assert %ArgumentError{message: ^expected_message} = error + # end defp assert_sdk_key_required({:error, result}) do assert {{:EXIT, {error, _stacktrace}}, _spec} = result From 14fb99d0c6dd98b9b99a7f7938543af8e0660be1 Mon Sep 17 00:00:00 2001 From: kp-cat <52385411+kp-cat@users.noreply.github.com> Date: Fri, 20 Sep 2024 19:24:28 +0200 Subject: [PATCH 08/27] remove trace from github CI --- .github/workflows/elixir-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/elixir-ci.yml b/.github/workflows/elixir-ci.yml index bc13dbf5..b42aac33 100644 --- a/.github/workflows/elixir-ci.yml +++ b/.github/workflows/elixir-ci.yml @@ -58,7 +58,7 @@ jobs: run: mix dialyzer - name: Execute tests - run: mix coveralls.json --warnings-as-errors --trace + run: mix coveralls.json --warnings-as-errors - name: Upload coverage report run: bash <(curl -s https://codecov.io/bash) From 17f99b3ebce13ffa04cd7384c74f16e2deb20d4c Mon Sep 17 00:00:00 2001 From: kp-cat <52385411+kp-cat@users.noreply.github.com> Date: Fri, 20 Sep 2024 19:52:59 +0200 Subject: [PATCH 09/27] block test is back --- test/using_block_test.exs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/using_block_test.exs b/test/using_block_test.exs index 31e6e1e1..759333a7 100644 --- a/test/using_block_test.exs +++ b/test/using_block_test.exs @@ -4,17 +4,17 @@ defmodule ConfigCat.UsingBlockTest do # one of the async tests would fail due to the existing running instance. use ConfigCat.Case, async: false - # defmodule CustomModule do - # @moduledoc false - # use ConfigCat, sdk_key: "configcat-sdk-1/PKDVCLf-Hq-h-kCzMp-L7Q/1cGEJXUwYUGZCBOL-E2sOw" - # end + defmodule CustomModule do + @moduledoc false + use ConfigCat, sdk_key: "configcat-sdk-1/PKDVCLf-Hq-h-kCzMp-L7Q/1cGEJXUwYUGZCBOL-E2sOw" + end test "can call API through using block" do - # _pid = start_supervised!(CustomModule) + _pid = start_supervised!(CustomModule) - # :ok = CustomModule.force_refresh() + :ok = CustomModule.force_refresh() - # assert CustomModule.get_value("keySampleText", "default value") == - # "This text came from ConfigCat" + assert CustomModule.get_value("keySampleText", "default value") == + "This text came from ConfigCat" end end From 18d442d6d6f8b1a658dc888353a968babbee049d Mon Sep 17 00:00:00 2001 From: kp-cat <52385411+kp-cat@users.noreply.github.com> Date: Fri, 20 Sep 2024 20:00:50 +0200 Subject: [PATCH 10/27] - block test + test trace --- .github/workflows/elixir-ci.yml | 2 +- test/using_block_test.exs | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/elixir-ci.yml b/.github/workflows/elixir-ci.yml index b42aac33..bc13dbf5 100644 --- a/.github/workflows/elixir-ci.yml +++ b/.github/workflows/elixir-ci.yml @@ -58,7 +58,7 @@ jobs: run: mix dialyzer - name: Execute tests - run: mix coveralls.json --warnings-as-errors + run: mix coveralls.json --warnings-as-errors --trace - name: Upload coverage report run: bash <(curl -s https://codecov.io/bash) diff --git a/test/using_block_test.exs b/test/using_block_test.exs index 759333a7..31e6e1e1 100644 --- a/test/using_block_test.exs +++ b/test/using_block_test.exs @@ -4,17 +4,17 @@ defmodule ConfigCat.UsingBlockTest do # one of the async tests would fail due to the existing running instance. use ConfigCat.Case, async: false - defmodule CustomModule do - @moduledoc false - use ConfigCat, sdk_key: "configcat-sdk-1/PKDVCLf-Hq-h-kCzMp-L7Q/1cGEJXUwYUGZCBOL-E2sOw" - end + # defmodule CustomModule do + # @moduledoc false + # use ConfigCat, sdk_key: "configcat-sdk-1/PKDVCLf-Hq-h-kCzMp-L7Q/1cGEJXUwYUGZCBOL-E2sOw" + # end test "can call API through using block" do - _pid = start_supervised!(CustomModule) + # _pid = start_supervised!(CustomModule) - :ok = CustomModule.force_refresh() + # :ok = CustomModule.force_refresh() - assert CustomModule.get_value("keySampleText", "default value") == - "This text came from ConfigCat" + # assert CustomModule.get_value("keySampleText", "default value") == + # "This text came from ConfigCat" end end From 94306435863e6be5a40aa30446ff9fe553bc00ca Mon Sep 17 00:00:00 2001 From: kp-cat <52385411+kp-cat@users.noreply.github.com> Date: Mon, 23 Sep 2024 09:21:45 +0200 Subject: [PATCH 11/27] print Registry entry --- lib/config_cat/supervisor.ex | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/config_cat/supervisor.ex b/lib/config_cat/supervisor.ex index 097287bf..2c872475 100644 --- a/lib/config_cat/supervisor.ex +++ b/lib/config_cat/supervisor.ex @@ -61,6 +61,19 @@ defmodule ConfigCat.Supervisor do raise ArgumentError, "SDK Key `#{inspect(sdk_key)}` is invalid." end + defp retrieve_and_print_registry_entries do + # Define a pattern to match all entries in the registry + pattern = [{{{ConfigCat.Registry, :"$1"}, :"$2", :"$3"}, [], [{{:"$1", :"$2", :"$3"}}]}] + + # Select all items from the registry + all_items = Registry.select(ConfigCat.Registry, pattern) + + # Print each item using Enum.each and IO.inspect + Enum.each(all_items, fn item -> + IO.inspect(item) + end) + end + defp ensure_unique_sdk_key(sdk_key) do ConfigCat.Registry |> Registry.select([{{{__MODULE__, :"$1"}, :_, sdk_key}, [], [:"$1"]}]) @@ -75,6 +88,7 @@ defmodule ConfigCat.Supervisor do "You can use the existing instance by passing `client: #{instance_id}` to the ConfigCat API functions. " <> "SDK Key: '#{sdk_key}'." + retrieve_and_print_registry_entries() ConfigCatLogger.warning(message, event_id: 3000) raise ArgumentError, message From 78c48ac07500f7a928f65f04eb647d8686276bf9 Mon Sep 17 00:00:00 2001 From: kp-cat <52385411+kp-cat@users.noreply.github.com> Date: Mon, 23 Sep 2024 09:28:53 +0200 Subject: [PATCH 12/27] add registry items to warning message --- lib/config_cat/supervisor.ex | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/lib/config_cat/supervisor.ex b/lib/config_cat/supervisor.ex index 2c872475..3b76d41d 100644 --- a/lib/config_cat/supervisor.ex +++ b/lib/config_cat/supervisor.ex @@ -61,19 +61,6 @@ defmodule ConfigCat.Supervisor do raise ArgumentError, "SDK Key `#{inspect(sdk_key)}` is invalid." end - defp retrieve_and_print_registry_entries do - # Define a pattern to match all entries in the registry - pattern = [{{{ConfigCat.Registry, :"$1"}, :"$2", :"$3"}, [], [{{:"$1", :"$2", :"$3"}}]}] - - # Select all items from the registry - all_items = Registry.select(ConfigCat.Registry, pattern) - - # Print each item using Enum.each and IO.inspect - Enum.each(all_items, fn item -> - IO.inspect(item) - end) - end - defp ensure_unique_sdk_key(sdk_key) do ConfigCat.Registry |> Registry.select([{{{__MODULE__, :"$1"}, :_, sdk_key}, [], [:"$1"]}]) @@ -82,13 +69,17 @@ defmodule ConfigCat.Supervisor do :ok [instance_id] -> + # Define a pattern to match all entries in the registry + pattern = [{{{ConfigCat.Registry, :"$1"}, :"$2", :"$3"}, [], [{{:"$1", :"$2", :"$3"}}]}] + # Select all items from the registry + registry_items = Registry.select(ConfigCat.Registry, pattern) + message = "There is an existing ConfigCat instance for the specified SDK Key. " <> "No new instance will be created and the specified options are ignored. " <> "You can use the existing instance by passing `client: #{instance_id}` to the ConfigCat API functions. " <> - "SDK Key: '#{sdk_key}'." + "SDK Key: '#{sdk_key}'. Registry: #{registry_items}" - retrieve_and_print_registry_entries() ConfigCatLogger.warning(message, event_id: 3000) raise ArgumentError, message From 9784b110757fbb804a149f37ea8641728b3e1664 Mon Sep 17 00:00:00 2001 From: kp-cat <52385411+kp-cat@users.noreply.github.com> Date: Mon, 23 Sep 2024 13:24:59 +0200 Subject: [PATCH 13/27] message fix --- lib/config_cat/supervisor.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/config_cat/supervisor.ex b/lib/config_cat/supervisor.ex index 3b76d41d..1ef86638 100644 --- a/lib/config_cat/supervisor.ex +++ b/lib/config_cat/supervisor.ex @@ -70,7 +70,7 @@ defmodule ConfigCat.Supervisor do [instance_id] -> # Define a pattern to match all entries in the registry - pattern = [{{{ConfigCat.Registry, :"$1"}, :"$2", :"$3"}, [], [{{:"$1", :"$2", :"$3"}}]}] + pattern = [{{{__MODULE__, :"$1"}, :"$2", :"$3"}, [], [{{:"$1", :"$2", :"$3"}}]}] # Select all items from the registry registry_items = Registry.select(ConfigCat.Registry, pattern) @@ -78,7 +78,7 @@ defmodule ConfigCat.Supervisor do "There is an existing ConfigCat instance for the specified SDK Key. " <> "No new instance will be created and the specified options are ignored. " <> "You can use the existing instance by passing `client: #{instance_id}` to the ConfigCat API functions. " <> - "SDK Key: '#{sdk_key}'. Registry: #{registry_items}" + "SDK Key: '#{sdk_key}'. Registry: #{inspect(registry_items)} ." ConfigCatLogger.warning(message, event_id: 3000) From 0b7fcd6473d04d74284113ee0da53964412af8b0 Mon Sep 17 00:00:00 2001 From: kp-cat <52385411+kp-cat@users.noreply.github.com> Date: Mon, 23 Sep 2024 14:23:45 +0200 Subject: [PATCH 14/27] test finished log --- test/integration_test.exs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/integration_test.exs b/test/integration_test.exs index 6801a1ce..49bcfe3d 100644 --- a/test/integration_test.exs +++ b/test/integration_test.exs @@ -11,6 +11,21 @@ defmodule ConfigCat.IntegrationTest do @sdk_key "configcat-sdk-1/PKDVCLf-Hq-h-kCzMp-L7Q/1cGEJXUwYUGZCBOL-E2sOw" + setup context do + # This will run after every individual test + on_exit(fn -> + IO.puts("Test finished: #{context.test}") + + # Define a pattern to match all entries in the registry + pattern = [{{{__MODULE__, :"$1"}, :"$2", :"$3"}, [], [{{:"$1", :"$2", :"$3"}}]}] + # Select all items from the registry + registry_items = Registry.select(ConfigCat.Registry, pattern) + IO.puts("Registry: #{inspect(registry_items)}") + end) + + :ok + end + describe "SDK key validation" do test "raises error if SDK key is missing" do nil From 361bcaf383f69dc58f09064d9f192994326b396d Mon Sep 17 00:00:00 2001 From: kp-cat <52385411+kp-cat@users.noreply.github.com> Date: Mon, 23 Sep 2024 14:29:24 +0200 Subject: [PATCH 15/27] allow IO.puts --- .credo.exs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.credo.exs b/.credo.exs index be74a8ce..de3ed516 100644 --- a/.credo.exs +++ b/.credo.exs @@ -116,7 +116,7 @@ {Credo.Check.Refactor.Apply, []}, {Credo.Check.Refactor.CyclomaticComplexity, []}, {Credo.Check.Refactor.FunctionArity, []}, - {Credo.Check.Refactor.IoPuts, []}, + {Credo.Check.Refactor.IoPuts, false}, {Credo.Check.Refactor.LongQuoteBlocks, []}, {Credo.Check.Refactor.MatchInCondition, []}, {Credo.Check.Refactor.Nesting, [max_nesting: 3]}, @@ -129,10 +129,10 @@ # {Credo.Check.Warning.ApplicationConfigInModuleAttribute, []}, {Credo.Check.Warning.BoolOperationOnSameValues, []}, - {Credo.Check.Warning.Dbg, []}, + {Credo.Check.Warning.Dbg, false}, {Credo.Check.Warning.ExpensiveEmptyEnumCheck, []}, {Credo.Check.Warning.IExPry, []}, - {Credo.Check.Warning.IoInspect, []}, + {Credo.Check.Warning.IoInspect, false}, {Credo.Check.Warning.OperationOnSameValues, []}, {Credo.Check.Warning.OperationWithConstantResult, []}, {Credo.Check.Warning.RaiseInsideRescue, []}, From 03938e615d47dca4a161967de155ceaa0e367815 Mon Sep 17 00:00:00 2001 From: kp-cat <52385411+kp-cat@users.noreply.github.com> Date: Mon, 23 Sep 2024 17:01:31 +0200 Subject: [PATCH 16/27] print registry --- test/integration_test.exs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/test/integration_test.exs b/test/integration_test.exs index 49bcfe3d..13bd4d2b 100644 --- a/test/integration_test.exs +++ b/test/integration_test.exs @@ -15,12 +15,7 @@ defmodule ConfigCat.IntegrationTest do # This will run after every individual test on_exit(fn -> IO.puts("Test finished: #{context.test}") - - # Define a pattern to match all entries in the registry - pattern = [{{{__MODULE__, :"$1"}, :"$2", :"$3"}, [], [{{:"$1", :"$2", :"$3"}}]}] - # Select all items from the registry - registry_items = Registry.select(ConfigCat.Registry, pattern) - IO.puts("Registry: #{inspect(registry_items)}") + print_registry_contents() end) :ok @@ -94,6 +89,8 @@ defmodule ConfigCat.IntegrationTest do end test "fetches config" do + print_registry_contents() + {:ok, client} = start(@sdk_key) :ok = ConfigCat.force_refresh(client: client) @@ -152,6 +149,8 @@ defmodule ConfigCat.IntegrationTest do @tag capture_log: true test "handles invalid base_url" do + print_registry_contents() + {:ok, client} = start(@sdk_key, base_url: "https://invalidcdn.configcat.com") assert {:error, _message} = ConfigCat.force_refresh(client: client) @@ -159,6 +158,8 @@ defmodule ConfigCat.IntegrationTest do @tag capture_log: true test "handles data_governance: eu_only" do + print_registry_contents() + {:ok, client} = start(@sdk_key, data_governance: :eu_only) assert ConfigCat.get_value("keySampleText", "default value", client: client) == @@ -194,4 +195,12 @@ defmodule ConfigCat.IntegrationTest do assert %ArgumentError{message: "SDK Key is required"} = error end + + defp print_registry_contents do + # Define a pattern to match all entries in the registry + pattern = [{{{__MODULE__, :"$1"}, :"$2", :"$3"}, [], [{{:"$1", :"$2", :"$3"}}]}] + # Select all items from the registry + registry_items = Registry.select(ConfigCat.Registry, pattern) + IO.puts("Registry: #{inspect(registry_items)}") + end end From fff2c504960de07a482e56b41b8e4cfd7059cb34 Mon Sep 17 00:00:00 2001 From: kp-cat <52385411+kp-cat@users.noreply.github.com> Date: Mon, 23 Sep 2024 18:31:03 +0200 Subject: [PATCH 17/27] clear registry before all test --- test/integration_test.exs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/test/integration_test.exs b/test/integration_test.exs index 13bd4d2b..3b7ee649 100644 --- a/test/integration_test.exs +++ b/test/integration_test.exs @@ -11,6 +11,13 @@ defmodule ConfigCat.IntegrationTest do @sdk_key "configcat-sdk-1/PKDVCLf-Hq-h-kCzMp-L7Q/1cGEJXUwYUGZCBOL-E2sOw" + setup_all do + # Restart the Registry before running tests + clear_registry() + + :ok + end + setup context do # This will run after every individual test on_exit(fn -> @@ -201,6 +208,17 @@ defmodule ConfigCat.IntegrationTest do pattern = [{{{__MODULE__, :"$1"}, :"$2", :"$3"}, [], [{{:"$1", :"$2", :"$3"}}]}] # Select all items from the registry registry_items = Registry.select(ConfigCat.Registry, pattern) - IO.puts("Registry: #{inspect(registry_items)}") + IO.puts("print_registry_contents: #{inspect(registry_items)}") + end + + defp clear_registry do + # Define a pattern to match all entries in the registry + pattern = [{{{__MODULE__, :"$1"}, :_, :_}, [], [{{:"$1"}}]}] + # Select all items from the registry + keys = Registry.select(ConfigCat.Registry, pattern) + # Unregister each key + Enum.each(keys, fn key -> + Registry.unregister(ConfigCat.Registry, key) + end) end end From 67ebd2c191134666ec11646d2ea4b2deaacd1bae Mon Sep 17 00:00:00 2001 From: kp-cat <52385411+kp-cat@users.noreply.github.com> Date: Tue, 24 Sep 2024 13:59:14 +0200 Subject: [PATCH 18/27] add extra print_registry_contents --- test/integration_test.exs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/integration_test.exs b/test/integration_test.exs index 3b7ee649..96ebdd96 100644 --- a/test/integration_test.exs +++ b/test/integration_test.exs @@ -85,6 +85,8 @@ defmodule ConfigCat.IntegrationTest do @tag capture_log: true test "raises error when starting another instance with the same SDK key" do + print_registry_contents() + {:ok, _} = start(@sdk_key, name: :original) assert {:error, {{:EXIT, {error, _stacktrace}}, _spec}} = @@ -107,6 +109,8 @@ defmodule ConfigCat.IntegrationTest do end test "maintains previous configuration when config has not changed between refreshes" do + print_registry_contents() + {:ok, client} = start(@sdk_key) :ok = ConfigCat.force_refresh(client: client) @@ -117,6 +121,8 @@ defmodule ConfigCat.IntegrationTest do end test "lazily fetches configuration when using lazy loading" do + print_registry_contents() + {:ok, client} = start( @sdk_key, @@ -129,6 +135,8 @@ defmodule ConfigCat.IntegrationTest do @tag capture_log: true test "does not fetch config when offline mode is set" do + print_registry_contents() + {:ok, client} = start(@sdk_key, offline: true) assert ConfigCat.offline?(client: client) @@ -175,6 +183,8 @@ defmodule ConfigCat.IntegrationTest do @tag capture_log: true test "handles timeout" do + print_registry_contents() + {:ok, client} = start(@sdk_key, connect_timeout_milliseconds: 0, read_timeout_milliseconds: 0) From f85f685f70451b3a9f6475f7f77d860987e7c1ae Mon Sep 17 00:00:00 2001 From: kp-cat <52385411+kp-cat@users.noreply.github.com> Date: Tue, 24 Sep 2024 14:24:56 +0200 Subject: [PATCH 19/27] cleanup --- .credo.exs | 6 +- .github/workflows/elixir-ci.yml | 2 +- lib/config_cat/supervisor.ex | 7 +- test/integration_test.exs | 128 +++++++++++--------------------- test/using_block_test.exs | 16 ++-- 5 files changed, 56 insertions(+), 103 deletions(-) diff --git a/.credo.exs b/.credo.exs index de3ed516..be74a8ce 100644 --- a/.credo.exs +++ b/.credo.exs @@ -116,7 +116,7 @@ {Credo.Check.Refactor.Apply, []}, {Credo.Check.Refactor.CyclomaticComplexity, []}, {Credo.Check.Refactor.FunctionArity, []}, - {Credo.Check.Refactor.IoPuts, false}, + {Credo.Check.Refactor.IoPuts, []}, {Credo.Check.Refactor.LongQuoteBlocks, []}, {Credo.Check.Refactor.MatchInCondition, []}, {Credo.Check.Refactor.Nesting, [max_nesting: 3]}, @@ -129,10 +129,10 @@ # {Credo.Check.Warning.ApplicationConfigInModuleAttribute, []}, {Credo.Check.Warning.BoolOperationOnSameValues, []}, - {Credo.Check.Warning.Dbg, false}, + {Credo.Check.Warning.Dbg, []}, {Credo.Check.Warning.ExpensiveEmptyEnumCheck, []}, {Credo.Check.Warning.IExPry, []}, - {Credo.Check.Warning.IoInspect, false}, + {Credo.Check.Warning.IoInspect, []}, {Credo.Check.Warning.OperationOnSameValues, []}, {Credo.Check.Warning.OperationWithConstantResult, []}, {Credo.Check.Warning.RaiseInsideRescue, []}, diff --git a/.github/workflows/elixir-ci.yml b/.github/workflows/elixir-ci.yml index bc13dbf5..b42aac33 100644 --- a/.github/workflows/elixir-ci.yml +++ b/.github/workflows/elixir-ci.yml @@ -58,7 +58,7 @@ jobs: run: mix dialyzer - name: Execute tests - run: mix coveralls.json --warnings-as-errors --trace + run: mix coveralls.json --warnings-as-errors - name: Upload coverage report run: bash <(curl -s https://codecov.io/bash) diff --git a/lib/config_cat/supervisor.ex b/lib/config_cat/supervisor.ex index 1ef86638..097287bf 100644 --- a/lib/config_cat/supervisor.ex +++ b/lib/config_cat/supervisor.ex @@ -69,16 +69,11 @@ defmodule ConfigCat.Supervisor do :ok [instance_id] -> - # Define a pattern to match all entries in the registry - pattern = [{{{__MODULE__, :"$1"}, :"$2", :"$3"}, [], [{{:"$1", :"$2", :"$3"}}]}] - # Select all items from the registry - registry_items = Registry.select(ConfigCat.Registry, pattern) - message = "There is an existing ConfigCat instance for the specified SDK Key. " <> "No new instance will be created and the specified options are ignored. " <> "You can use the existing instance by passing `client: #{instance_id}` to the ConfigCat API functions. " <> - "SDK Key: '#{sdk_key}'. Registry: #{inspect(registry_items)} ." + "SDK Key: '#{sdk_key}'." ConfigCatLogger.warning(message, event_id: 3000) diff --git a/test/integration_test.exs b/test/integration_test.exs index 96ebdd96..364fd066 100644 --- a/test/integration_test.exs +++ b/test/integration_test.exs @@ -11,22 +11,7 @@ defmodule ConfigCat.IntegrationTest do @sdk_key "configcat-sdk-1/PKDVCLf-Hq-h-kCzMp-L7Q/1cGEJXUwYUGZCBOL-E2sOw" - setup_all do - # Restart the Registry before running tests - clear_registry() - - :ok - end - - setup context do - # This will run after every individual test - on_exit(fn -> - IO.puts("Test finished: #{context.test}") - print_registry_contents() - end) - - :ok - end + setup :clear_registry describe "SDK key validation" do test "raises error if SDK key is missing" do @@ -41,38 +26,38 @@ defmodule ConfigCat.IntegrationTest do |> assert_sdk_key_required() end - # for {sdk_key, custom_base_url?, valid?} <- [ - # {"sdk-key-90123456789012", false, false}, - # {"sdk-key-9012345678901/1234567890123456789012", false, false}, - # {"sdk-key-90123456789012/123456789012345678901", false, false}, - # {"sdk-key-90123456789012/12345678901234567890123", false, false}, - # {"sdk-key-901234567890123/1234567890123456789012", false, false}, - # {"sdk-key-90123456789012/1234567890123456789012", false, true}, - # {"configcat-sdk-1/sdk-key-90123456789012", false, false}, - # {"configcat-sdk-1/sdk-key-9012345678901/1234567890123456789012", false, false}, - # {"configcat-sdk-1/sdk-key-90123456789012/123456789012345678901", false, false}, - # {"configcat-sdk-1/sdk-key-90123456789012/12345678901234567890123", false, false}, - # {"configcat-sdk-1/sdk-key-901234567890123/1234567890123456789012", false, false}, - # {"configcat-sdk-1/sdk-key-90123456789012/1234567890123456789012", false, true}, - # {"configcat-sdk-2/sdk-key-90123456789012/1234567890123456789012", false, false}, - # {"configcat-proxy/", false, false}, - # {"configcat-proxy/", true, false}, - # {"configcat-proxy/sdk-key-90123456789012", false, false}, - # {"configcat-proxy/sdk-key-90123456789012", true, true} - # ] do - # test "validates SDK key format - sdk_key: #{sdk_key} | custom_base_url: #{custom_base_url?}" do - # sdk_key = unquote(sdk_key) - # custom_base_url? = unquote(custom_base_url?) - # valid? = unquote(valid?) - # options = if custom_base_url?, do: [base_url: "https://my-configcat-proxy"], else: [] - - # if valid? do - # assert {:ok, _} = start(sdk_key, options) - # else - # sdk_key |> start(options) |> assert_sdk_key_invalid(sdk_key) - # end - # end - # end + for {sdk_key, custom_base_url?, valid?} <- [ + {"sdk-key-90123456789012", false, false}, + {"sdk-key-9012345678901/1234567890123456789012", false, false}, + {"sdk-key-90123456789012/123456789012345678901", false, false}, + {"sdk-key-90123456789012/12345678901234567890123", false, false}, + {"sdk-key-901234567890123/1234567890123456789012", false, false}, + {"sdk-key-90123456789012/1234567890123456789012", false, true}, + {"configcat-sdk-1/sdk-key-90123456789012", false, false}, + {"configcat-sdk-1/sdk-key-9012345678901/1234567890123456789012", false, false}, + {"configcat-sdk-1/sdk-key-90123456789012/123456789012345678901", false, false}, + {"configcat-sdk-1/sdk-key-90123456789012/12345678901234567890123", false, false}, + {"configcat-sdk-1/sdk-key-901234567890123/1234567890123456789012", false, false}, + {"configcat-sdk-1/sdk-key-90123456789012/1234567890123456789012", false, true}, + {"configcat-sdk-2/sdk-key-90123456789012/1234567890123456789012", false, false}, + {"configcat-proxy/", false, false}, + {"configcat-proxy/", true, false}, + {"configcat-proxy/sdk-key-90123456789012", false, false}, + {"configcat-proxy/sdk-key-90123456789012", true, true} + ] do + test "validates SDK key format - sdk_key: #{sdk_key} | custom_base_url: #{custom_base_url?}" do + sdk_key = unquote(sdk_key) + custom_base_url? = unquote(custom_base_url?) + valid? = unquote(valid?) + options = if custom_base_url?, do: [base_url: "https://my-configcat-proxy"], else: [] + + if valid? do + assert {:ok, _} = start(sdk_key, options) + else + sdk_key |> start(options) |> assert_sdk_key_invalid(sdk_key) + end + end + end test "allows older format SDK keys" do assert {:ok, _} = start("1234567890abcdefghijkl/1234567890abcdefghijkl") @@ -85,8 +70,6 @@ defmodule ConfigCat.IntegrationTest do @tag capture_log: true test "raises error when starting another instance with the same SDK key" do - print_registry_contents() - {:ok, _} = start(@sdk_key, name: :original) assert {:error, {{:EXIT, {error, _stacktrace}}, _spec}} = @@ -98,8 +81,6 @@ defmodule ConfigCat.IntegrationTest do end test "fetches config" do - print_registry_contents() - {:ok, client} = start(@sdk_key) :ok = ConfigCat.force_refresh(client: client) @@ -109,8 +90,6 @@ defmodule ConfigCat.IntegrationTest do end test "maintains previous configuration when config has not changed between refreshes" do - print_registry_contents() - {:ok, client} = start(@sdk_key) :ok = ConfigCat.force_refresh(client: client) @@ -121,8 +100,6 @@ defmodule ConfigCat.IntegrationTest do end test "lazily fetches configuration when using lazy loading" do - print_registry_contents() - {:ok, client} = start( @sdk_key, @@ -135,8 +112,6 @@ defmodule ConfigCat.IntegrationTest do @tag capture_log: true test "does not fetch config when offline mode is set" do - print_registry_contents() - {:ok, client} = start(@sdk_key, offline: true) assert ConfigCat.offline?(client: client) @@ -164,8 +139,6 @@ defmodule ConfigCat.IntegrationTest do @tag capture_log: true test "handles invalid base_url" do - print_registry_contents() - {:ok, client} = start(@sdk_key, base_url: "https://invalidcdn.configcat.com") assert {:error, _message} = ConfigCat.force_refresh(client: client) @@ -173,8 +146,6 @@ defmodule ConfigCat.IntegrationTest do @tag capture_log: true test "handles data_governance: eu_only" do - print_registry_contents() - {:ok, client} = start(@sdk_key, data_governance: :eu_only) assert ConfigCat.get_value("keySampleText", "default value", client: client) == @@ -183,8 +154,6 @@ defmodule ConfigCat.IntegrationTest do @tag capture_log: true test "handles timeout" do - print_registry_contents() - {:ok, client} = start(@sdk_key, connect_timeout_milliseconds: 0, read_timeout_milliseconds: 0) @@ -200,12 +169,12 @@ defmodule ConfigCat.IntegrationTest do start_config_cat(sdk_key, options) end - # defp assert_sdk_key_invalid({:error, result}, sdk_key) do - # assert {{:EXIT, {error, _stacktrace}}, _spec} = result + defp assert_sdk_key_invalid({:error, result}, sdk_key) do + assert {{:EXIT, {error, _stacktrace}}, _spec} = result - # expected_message = "SDK Key `#{sdk_key}` is invalid." - # assert %ArgumentError{message: ^expected_message} = error - # end + expected_message = "SDK Key `#{sdk_key}` is invalid." + assert %ArgumentError{message: ^expected_message} = error + end defp assert_sdk_key_required({:error, result}) do assert {{:EXIT, {error, _stacktrace}}, _spec} = result @@ -213,22 +182,11 @@ defmodule ConfigCat.IntegrationTest do assert %ArgumentError{message: "SDK Key is required"} = error end - defp print_registry_contents do - # Define a pattern to match all entries in the registry - pattern = [{{{__MODULE__, :"$1"}, :"$2", :"$3"}, [], [{{:"$1", :"$2", :"$3"}}]}] - # Select all items from the registry - registry_items = Registry.select(ConfigCat.Registry, pattern) - IO.puts("print_registry_contents: #{inspect(registry_items)}") - end + defp clear_registry(_context) do + ConfigCat.Registry + |> Registry.match({__MODULE__, :_}, :_) + |> Enum.each(fn {key, _} -> Registry.unregister(ConfigCat.Registry, key) end) - defp clear_registry do - # Define a pattern to match all entries in the registry - pattern = [{{{__MODULE__, :"$1"}, :_, :_}, [], [{{:"$1"}}]}] - # Select all items from the registry - keys = Registry.select(ConfigCat.Registry, pattern) - # Unregister each key - Enum.each(keys, fn key -> - Registry.unregister(ConfigCat.Registry, key) - end) + :ok end end diff --git a/test/using_block_test.exs b/test/using_block_test.exs index 31e6e1e1..759333a7 100644 --- a/test/using_block_test.exs +++ b/test/using_block_test.exs @@ -4,17 +4,17 @@ defmodule ConfigCat.UsingBlockTest do # one of the async tests would fail due to the existing running instance. use ConfigCat.Case, async: false - # defmodule CustomModule do - # @moduledoc false - # use ConfigCat, sdk_key: "configcat-sdk-1/PKDVCLf-Hq-h-kCzMp-L7Q/1cGEJXUwYUGZCBOL-E2sOw" - # end + defmodule CustomModule do + @moduledoc false + use ConfigCat, sdk_key: "configcat-sdk-1/PKDVCLf-Hq-h-kCzMp-L7Q/1cGEJXUwYUGZCBOL-E2sOw" + end test "can call API through using block" do - # _pid = start_supervised!(CustomModule) + _pid = start_supervised!(CustomModule) - # :ok = CustomModule.force_refresh() + :ok = CustomModule.force_refresh() - # assert CustomModule.get_value("keySampleText", "default value") == - # "This text came from ConfigCat" + assert CustomModule.get_value("keySampleText", "default value") == + "This text came from ConfigCat" end end From 716f9c383b119cd63d835beab49f27a0cd961886 Mon Sep 17 00:00:00 2001 From: kp-cat <52385411+kp-cat@users.noreply.github.com> Date: Tue, 24 Sep 2024 22:13:48 +0200 Subject: [PATCH 20/27] move block test into integration test --- test/integration_test.exs | 14 ++++++++++++++ test/using_block_test.exs | 20 -------------------- 2 files changed, 14 insertions(+), 20 deletions(-) delete mode 100644 test/using_block_test.exs diff --git a/test/integration_test.exs b/test/integration_test.exs index 364fd066..597a8fde 100644 --- a/test/integration_test.exs +++ b/test/integration_test.exs @@ -161,6 +161,20 @@ defmodule ConfigCat.IntegrationTest do "default value" end + defmodule CustomModule do + @moduledoc false + use ConfigCat, sdk_key: "configcat-sdk-1/PKDVCLf-Hq-h-kCzMp-L7Q/1cGEJXUwYUGZCBOL-E2sOw" + end + + test "can call API through using block" do + _pid = start_supervised!(CustomModule) + + :ok = CustomModule.force_refresh() + + assert CustomModule.get_value("keySampleText", "default value") == + "This text came from ConfigCat" + end + defp start(sdk_key, options \\ []) do sdk_key |> Cache.generate_key() diff --git a/test/using_block_test.exs b/test/using_block_test.exs deleted file mode 100644 index 759333a7..00000000 --- a/test/using_block_test.exs +++ /dev/null @@ -1,20 +0,0 @@ -defmodule ConfigCat.UsingBlockTest do - # Must be async: false to avoid a collision with the integration tests. - # Now that we only allow a single ConfigCat instance to use the same SDK key, - # one of the async tests would fail due to the existing running instance. - use ConfigCat.Case, async: false - - defmodule CustomModule do - @moduledoc false - use ConfigCat, sdk_key: "configcat-sdk-1/PKDVCLf-Hq-h-kCzMp-L7Q/1cGEJXUwYUGZCBOL-E2sOw" - end - - test "can call API through using block" do - _pid = start_supervised!(CustomModule) - - :ok = CustomModule.force_refresh() - - assert CustomModule.get_value("keySampleText", "default value") == - "This text came from ConfigCat" - end -end From 20e1260ce3254c8d58ea281f13369c163e3a193d Mon Sep 17 00:00:00 2001 From: kp-cat <52385411+kp-cat@users.noreply.github.com> Date: Wed, 16 Oct 2024 16:11:43 +0200 Subject: [PATCH 21/27] fix module in integration_test --- test/integration_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration_test.exs b/test/integration_test.exs index 597a8fde..57d45d4e 100644 --- a/test/integration_test.exs +++ b/test/integration_test.exs @@ -198,7 +198,7 @@ defmodule ConfigCat.IntegrationTest do defp clear_registry(_context) do ConfigCat.Registry - |> Registry.match({__MODULE__, :_}, :_) + |> Registry.match({ConfigCat.Supervisor, :_}, :_) |> Enum.each(fn {key, _} -> Registry.unregister(ConfigCat.Registry, key) end) :ok From 283b4211cc9e7ad5b1277952fe3f4ffcad952a46 Mon Sep 17 00:00:00 2001 From: kp-cat <52385411+kp-cat@users.noreply.github.com> Date: Tue, 29 Oct 2024 15:12:51 +0100 Subject: [PATCH 22/27] revert clear_registry + inline using_block_test --- test/integration_test.exs | 24 ------------------------ test/using_block_test.exs | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 24 deletions(-) create mode 100644 test/using_block_test.exs diff --git a/test/integration_test.exs b/test/integration_test.exs index 57d45d4e..78b687b1 100644 --- a/test/integration_test.exs +++ b/test/integration_test.exs @@ -11,8 +11,6 @@ defmodule ConfigCat.IntegrationTest do @sdk_key "configcat-sdk-1/PKDVCLf-Hq-h-kCzMp-L7Q/1cGEJXUwYUGZCBOL-E2sOw" - setup :clear_registry - describe "SDK key validation" do test "raises error if SDK key is missing" do nil @@ -161,20 +159,6 @@ defmodule ConfigCat.IntegrationTest do "default value" end - defmodule CustomModule do - @moduledoc false - use ConfigCat, sdk_key: "configcat-sdk-1/PKDVCLf-Hq-h-kCzMp-L7Q/1cGEJXUwYUGZCBOL-E2sOw" - end - - test "can call API through using block" do - _pid = start_supervised!(CustomModule) - - :ok = CustomModule.force_refresh() - - assert CustomModule.get_value("keySampleText", "default value") == - "This text came from ConfigCat" - end - defp start(sdk_key, options \\ []) do sdk_key |> Cache.generate_key() @@ -195,12 +179,4 @@ defmodule ConfigCat.IntegrationTest do assert %ArgumentError{message: "SDK Key is required"} = error end - - defp clear_registry(_context) do - ConfigCat.Registry - |> Registry.match({ConfigCat.Supervisor, :_}, :_) - |> Enum.each(fn {key, _} -> Registry.unregister(ConfigCat.Registry, key) end) - - :ok - end end diff --git a/test/using_block_test.exs b/test/using_block_test.exs new file mode 100644 index 00000000..ab788d4d --- /dev/null +++ b/test/using_block_test.exs @@ -0,0 +1,20 @@ +defmodule ConfigCat.UsingBlockTest do + # Must be async: false to avoid a collision with the integration tests. + # Now that we only allow a single ConfigCat instance to use the same SDK key, + # one of the async tests would fail due to the existing running instance. + use ExUnit.Case, async: false + + defmodule CustomModule do + @moduledoc false + use ConfigCat, sdk_key: "configcat-sdk-1/PKDVCLf-Hq-h-kCzMp-L7Q/1cGEJXUwYUGZCBOL-E2sOw" + end + + test "can call API through using block" do + _pid = start_supervised!(CustomModule) + + :ok = CustomModule.force_refresh() + + assert CustomModule.get_value("keySampleText", "default value") == + "This text came from ConfigCat" + end +end From d093a1e2c7b8940c015f501b2a19fb25db58318f Mon Sep 17 00:00:00 2001 From: kp-cat <52385411+kp-cat@users.noreply.github.com> Date: Wed, 30 Oct 2024 09:27:42 +0100 Subject: [PATCH 23/27] run CI tests with max-cases 1 --- .github/workflows/elixir-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/elixir-ci.yml b/.github/workflows/elixir-ci.yml index b42aac33..1438306c 100644 --- a/.github/workflows/elixir-ci.yml +++ b/.github/workflows/elixir-ci.yml @@ -58,7 +58,7 @@ jobs: run: mix dialyzer - name: Execute tests - run: mix coveralls.json --warnings-as-errors + run: mix coveralls.json --warnings-as-errors --max-cases 1 - name: Upload coverage report run: bash <(curl -s https://codecov.io/bash) From b7dd1c40ca4b7961d6ed80abfda480575ab50e59 Mon Sep 17 00:00:00 2001 From: kp-cat <52385411+kp-cat@users.noreply.github.com> Date: Wed, 30 Oct 2024 12:48:16 +0100 Subject: [PATCH 24/27] run CI integration tests with max-cases 1 --- .github/workflows/elixir-ci.yml | 4 +++- test/integration_test.exs | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/elixir-ci.yml b/.github/workflows/elixir-ci.yml index 1438306c..191fef07 100644 --- a/.github/workflows/elixir-ci.yml +++ b/.github/workflows/elixir-ci.yml @@ -58,7 +58,9 @@ jobs: run: mix dialyzer - name: Execute tests - run: mix coveralls.json --warnings-as-errors --max-cases 1 + run: | + mix coveralls.json --exclude integration --warnings-as-errors + mix coveralls.json --only integration --warnings-as-errors --max-cases 1 - name: Upload coverage report run: bash <(curl -s https://codecov.io/bash) diff --git a/test/integration_test.exs b/test/integration_test.exs index 78b687b1..9b113489 100644 --- a/test/integration_test.exs +++ b/test/integration_test.exs @@ -9,6 +9,8 @@ defmodule ConfigCat.IntegrationTest do alias ConfigCat.InMemoryCache alias ConfigCat.LocalMapDataSource + @tag :integration + @sdk_key "configcat-sdk-1/PKDVCLf-Hq-h-kCzMp-L7Q/1cGEJXUwYUGZCBOL-E2sOw" describe "SDK key validation" do From 5b7642359a0544ec5829852d2848642df9853a5f Mon Sep 17 00:00:00 2001 From: kp-cat <52385411+kp-cat@users.noreply.github.com> Date: Wed, 30 Oct 2024 13:29:29 +0100 Subject: [PATCH 25/27] CI: merge coverall reports --- .github/workflows/elixir-ci.yml | 4 ++-- test/integration_test.exs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/elixir-ci.yml b/.github/workflows/elixir-ci.yml index 191fef07..fc0e5af5 100644 --- a/.github/workflows/elixir-ci.yml +++ b/.github/workflows/elixir-ci.yml @@ -59,8 +59,8 @@ jobs: - name: Execute tests run: | - mix coveralls.json --exclude integration --warnings-as-errors - mix coveralls.json --only integration --warnings-as-errors --max-cases 1 + mix test --only integration --warnings-as-errors --max-cases 1 --cover --export-coverage integration-coverage + mix coveralls --exclude integration --warnings-as-errors --import-cover cover - name: Upload coverage report run: bash <(curl -s https://codecov.io/bash) diff --git a/test/integration_test.exs b/test/integration_test.exs index 9b113489..44d5d3d3 100644 --- a/test/integration_test.exs +++ b/test/integration_test.exs @@ -9,7 +9,7 @@ defmodule ConfigCat.IntegrationTest do alias ConfigCat.InMemoryCache alias ConfigCat.LocalMapDataSource - @tag :integration + @moduletag :integration @sdk_key "configcat-sdk-1/PKDVCLf-Hq-h-kCzMp-L7Q/1cGEJXUwYUGZCBOL-E2sOw" From 877ed289987c5c89e3b040004a36716e386fda0f Mon Sep 17 00:00:00 2001 From: kp-cat <52385411+kp-cat@users.noreply.github.com> Date: Thu, 31 Oct 2024 09:20:28 +0100 Subject: [PATCH 26/27] remove max-cases 1 --- .github/workflows/elixir-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/elixir-ci.yml b/.github/workflows/elixir-ci.yml index fc0e5af5..ec5f80d1 100644 --- a/.github/workflows/elixir-ci.yml +++ b/.github/workflows/elixir-ci.yml @@ -59,7 +59,7 @@ jobs: - name: Execute tests run: | - mix test --only integration --warnings-as-errors --max-cases 1 --cover --export-coverage integration-coverage + mix test --only integration --warnings-as-errors --cover --export-coverage integration-coverage mix coveralls --exclude integration --warnings-as-errors --import-cover cover - name: Upload coverage report From 1e1716c7b9c603d36098865cd33453b61255bd64 Mon Sep 17 00:00:00 2001 From: kp-cat <52385411+kp-cat@users.noreply.github.com> Date: Fri, 1 Nov 2024 21:43:20 +0100 Subject: [PATCH 27/27] Revert "remove max-cases 1" This reverts commit 877ed289987c5c89e3b040004a36716e386fda0f. --- .github/workflows/elixir-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/elixir-ci.yml b/.github/workflows/elixir-ci.yml index ec5f80d1..fc0e5af5 100644 --- a/.github/workflows/elixir-ci.yml +++ b/.github/workflows/elixir-ci.yml @@ -59,7 +59,7 @@ jobs: - name: Execute tests run: | - mix test --only integration --warnings-as-errors --cover --export-coverage integration-coverage + mix test --only integration --warnings-as-errors --max-cases 1 --cover --export-coverage integration-coverage mix coveralls --exclude integration --warnings-as-errors --import-cover cover - name: Upload coverage report