Leon4gr45 commited on
Commit
b40d7a2
·
verified ·
1 Parent(s): da80c1b

Delete test/plausible/rate_limit_test.exs with huggingface_hub

Browse files
Files changed (1) hide show
  1. test/plausible/rate_limit_test.exs +0 -87
test/plausible/rate_limit_test.exs DELETED
@@ -1,87 +0,0 @@
1
- defmodule Plausible.RateLimitTest do
2
- use ExUnit.Case, async: true
3
- alias Plausible.RateLimit
4
- use Plausible.TestUtils
5
-
6
- @table __MODULE__
7
-
8
- defp key, do: "key:#{System.unique_integer([:positive])}"
9
-
10
- @tag :slow
11
- test "garbage collection" do
12
- start_supervised!({RateLimit, clean_period: _100_ms = 100, table: @table})
13
-
14
- key = key()
15
- scale = _50_ms = 50
16
- limit = 10
17
-
18
- for _ <- 1..3 do
19
- assert {:allow, 1} = RateLimit.check_rate(@table, key, scale, limit)
20
- assert [{{^key, _bucket}, counter, expires_at}] = :ets.tab2list(@table)
21
- assert :atomics.get(counter, 1) == 1
22
-
23
- assert expires_at >= System.system_time(:millisecond)
24
- assert expires_at <= System.system_time(:millisecond) + 50
25
-
26
- Plausible.TestUtils.eventually(fn ->
27
- {:ets.tab2list(@table) == [], :done}
28
- end)
29
- end
30
- end
31
-
32
- describe "check_rate/3" do
33
- setup do
34
- start_supervised!({RateLimit, clean_period: :timer.minutes(1), table: @table})
35
- :ok
36
- end
37
-
38
- test "increments" do
39
- key = key()
40
- scale = :timer.seconds(10)
41
- limit = 10
42
-
43
- assert {:allow, 1} = RateLimit.check_rate(@table, key, scale, limit)
44
- assert {:allow, 2} = RateLimit.check_rate(@table, key, scale, limit)
45
- assert {:allow, 3} = RateLimit.check_rate(@table, key, scale, limit)
46
- end
47
-
48
- test "resets" do
49
- key = key()
50
- scale = 10
51
- limit = 10
52
-
53
- assert {:allow, 1} = RateLimit.check_rate(@table, key, scale, limit)
54
- :timer.sleep(scale * 2 + 1)
55
- assert {:allow, 1} = RateLimit.check_rate(@table, key, scale, limit)
56
- end
57
-
58
- test "denies" do
59
- key = key()
60
- scale = :timer.seconds(10)
61
- limit = 3
62
-
63
- assert {:allow, 1} = RateLimit.check_rate(@table, key, scale, limit)
64
- assert {:allow, 2} = RateLimit.check_rate(@table, key, scale, limit)
65
- assert {:allow, 3} = RateLimit.check_rate(@table, key, scale, limit)
66
- assert {:deny, 3} = RateLimit.check_rate(@table, key, scale, limit)
67
- end
68
-
69
- test "denies any concurrent iterations over the limit" do
70
- key = key()
71
- scale = :timer.seconds(10)
72
- limit = 3
73
-
74
- assert eventually(fn ->
75
- results =
76
- 1..4
77
- |> Enum.map(fn _ ->
78
- Task.async(fn -> RateLimit.check_rate(@table, key, scale, limit) end)
79
- end)
80
- |> Task.await_many()
81
- |> Enum.sort()
82
-
83
- {[{:allow, 1}, {:allow, 2}, {:allow, 3}, {:deny, 3}] == results, results}
84
- end)
85
- end
86
- end
87
- end