From ec7e9da734590622d180cb72dfc34ba3ab6bcfea Mon Sep 17 00:00:00 2001 From: Floatingghost Date: Fri, 26 Apr 2024 19:05:12 +0100 Subject: [PATCH] Correct ttl syntax for new cachex --- lib/pleroma/http/backoff.ex | 2 +- test/pleroma/http/backoff_test.exs | 9 +++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/pleroma/http/backoff.ex b/lib/pleroma/http/backoff.ex index cba6c0c17..5fb37205e 100644 --- a/lib/pleroma/http/backoff.ex +++ b/lib/pleroma/http/backoff.ex @@ -49,7 +49,7 @@ def get(url, headers \\ [], options \\ []) do timestamp = next_backoff_timestamp(env) ttl = Timex.diff(timestamp, DateTime.utc_now(), :seconds) # we will cache the host for 5 minutes - @cachex.put(@backoff_cache, host, true, ttl) + @cachex.put(@backoff_cache, host, true, ttl: ttl) {:error, :ratelimit} _ -> diff --git a/test/pleroma/http/backoff_test.exs b/test/pleroma/http/backoff_test.exs index b50a4c458..62419eb5c 100644 --- a/test/pleroma/http/backoff_test.exs +++ b/test/pleroma/http/backoff_test.exs @@ -17,8 +17,7 @@ test "should return {:ok, env} when not rate limited" do test "should return {:error, env} when rate limited" do # Shove a value into the cache to simulate a rate limit Cachex.put(@backoff_cache, "akkoma.dev", true) - assert {:error, env} = Backoff.get("https://akkoma.dev/api/v1/instance") - assert env.status == 429 + assert {:error, :ratelimit} = Backoff.get("https://akkoma.dev/api/v1/instance") end test "should insert a value into the cache when rate limited" do @@ -27,8 +26,7 @@ test "should insert a value into the cache when rate limited" do {:ok, %Tesla.Env{status: 429, body: "Rate limited"}} end) - assert {:error, env} = Backoff.get("https://ratelimited.dev/api/v1/instance") - assert env.status == 429 + assert {:error, :ratelimit} = Backoff.get("https://ratelimited.dev/api/v1/instance") assert {:ok, true} = Cachex.get(@backoff_cache, "ratelimited.dev") end @@ -46,8 +44,7 @@ test "should parse the value of x-ratelimit-reset, if present" do }} end) - assert {:error, env} = Backoff.get("https://ratelimited.dev/api/v1/instance") - assert env.status == 429 + assert {:error, :ratelimit} = Backoff.get("https://ratelimited.dev/api/v1/instance") assert {:ok, true} = Cachex.get(@backoff_cache, "ratelimited.dev") end end