Skip to content

Commit 2f58f95

Browse files
committed
Fix test case and check for a single process/worker
1 parent e6191a9 commit 2f58f95

File tree

1 file changed

+7
-20
lines changed

1 file changed

+7
-20
lines changed

test/lightning/distributed_rate_limiter_test.exs

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,16 @@ defmodule Lightning.DistributedRateLimiterTest do
4040
assert {:allow, level} = DistributedRateLimiter.check_rate(bucket2)
4141
assert level == initial_capacity - 1
4242

43-
assert {:deny, wait_ms} = DistributedRateLimiter.check_rate(bucket1) |> dbg
43+
assert {:deny, wait_ms} = DistributedRateLimiter.check_rate(bucket1)
4444
assert 500 < wait_ms and wait_ms <= 1_000
4545
end
4646

47-
# Synthetic cluster not working.
48-
# For testing use manual procedure:
47+
# For testing the replication use manual procedure:
4948
# 0. Disable Endpoint server
5049
# 1. Run node1 on one terminal: iex --sname node1@localhost --cookie hordecookie -S mix phx.server
5150
# 2. Run node2 on another terminal: iex --sname node2@localhost --cookie hordecookie -S mix phx.server
5251
# 3. Call Lightning.DistributedRateLimiter.inspect_table() on both iex and they show the same ets table process and node.
53-
@tag skip: true
54-
test "consumes the bucket remotely" do
52+
test "works on top of a single worker of a distributed dynamic supervisor" do
5553
{:ok, peer, _node1, node2} = start_nodes(:node1, :node2, ~c"localhost")
5654

5755
:rpc.call(node2, Application, :ensure_all_started, [:mix])
@@ -65,21 +63,10 @@ defmodule Lightning.DistributedRateLimiterTest do
6563
{Lightning.DistributedSupervisor, :node2@localhost}
6664
] = Horde.Cluster.members(Lightning.DistributedSupervisor)
6765

68-
# initial_capacity = @default_capacity
69-
bucket = "project#{System.unique_integer()}"
70-
71-
dbg(DistributedRateLimiter.check_rate(bucket))
72-
73-
# dbg :rpc.block_call(node1, DistributedRateLimiter, :inspect, [DistributedRateLimiter])
74-
# dbg :rpc.block_call(node2, DistributedRateLimiter, :inspect, [DistributedRateLimiter])
75-
76-
# Enum.each(1..initial_capacity-1, fn i ->
77-
# assert {:allow, level} = :rpc.call(node2, DistributedRateLimiter, :check_rate, [bucket, 1])
78-
# assert level == initial_capacity - i - 1
79-
# end)
80-
81-
# assert {:deny, wait_ms} = DistributedRateLimiter.check_rate(bucket)
82-
# assert 0 < wait_ms and wait_ms < 1_000
66+
assert [{:undefined, _pid, :worker, [Lightning.DistributedRateLimiter]}] =
67+
Horde.DynamicSupervisor.which_children(
68+
Lightning.DistributedSupervisor
69+
)
8370

8471
:peer.stop(peer)
8572
end

0 commit comments

Comments
 (0)