Skip to content

Commit 024ad8c

Browse files
committed
Fix test case and check for a single process/worker
1 parent c9e2c8f commit 024ad8c

File tree

3 files changed

+10
-21
lines changed

3 files changed

+10
-21
lines changed

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ defmodule Lightning.MixProject do
134134
{:timex, "~> 3.7"},
135135
{:replug, "~> 0.1.0"},
136136
{:phoenix_swoosh, "~> 1.2.1"},
137-
{:hammer_backend_mnesia, "~> 0.6"},
137+
{:hammer_backend_mnesia, "~> 0.6.0"},
138138
{:hammer, "~> 6.0"},
139139
{:dotenvy, "~> 0.8.0"},
140140
{:goth, "~> 1.3"},

mix.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"db_connection": {:hex, :db_connection, "2.7.0", "b99faa9291bb09892c7da373bb82cba59aefa9b36300f6145c5f201c7adf48ec", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "dcf08f31b2701f857dfc787fbad78223d61a32204f217f15e881dd93e4bdd3ff"},
2626
"decimal": {:hex, :decimal, "2.3.0", "3ad6255aa77b4a3c4f818171b12d237500e63525c2fd056699967a3e7ea20f62", [:mix], [], "hexpm", "a4d66355cb29cb47c3cf30e71329e58361cfcb37c34235ef3bf1d7bf3773aeac"},
2727
"deep_merge": {:hex, :deep_merge, "1.0.0", "b4aa1a0d1acac393bdf38b2291af38cb1d4a52806cf7a4906f718e1feb5ee961", [:mix], [], "hexpm", "ce708e5f094b9cd4e8f2be4f00d2f4250c4095be93f8cd6d018c753894885430"},
28+
"delta_crdt": {:hex, :delta_crdt, "0.6.5", "c7bb8c2c7e60f59e46557ab4e0224f67ba22f04c02826e273738f3dcc4767adc", [:mix], [{:merkle_map, "~> 0.2.0", [hex: :merkle_map, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c6ae23a525d30f96494186dd11bf19ed9ae21d9fe2c1f1b217d492a7cc7294ae"},
2829
"dialyxir": {:hex, :dialyxir, "1.4.5", "ca1571ac18e0f88d4ab245f0b60fa31ff1b12cbae2b11bd25d207f865e8ae78a", [:mix], [{:erlex, ">= 0.2.7", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "b0fb08bb8107c750db5c0b324fa2df5ceaa0f9307690ee3c1f6ba5b9eb5d35c3"},
2930
"dotenvy": {:hex, :dotenvy, "0.8.0", "777486ad485668317c56afc53a7cbcd74f43e4e34588ba8e95a73e15a360050e", [:mix], [], "hexpm", "1f535066282388cbd109743d337ac46ff0708195780d4b5778bb83491ab1b654"},
3031
"earmark": {:hex, :earmark, "1.4.47", "7e7596b84fe4ebeb8751e14cbaeaf4d7a0237708f2ce43630cfd9065551f94ca", [:mix], [], "hexpm", "3e96bebea2c2d95f3b346a7ff22285bc68a99fbabdad9b655aa9c6be06c698f8"},
@@ -79,6 +80,7 @@
7980
"makeup_erlang": {:hex, :makeup_erlang, "1.0.1", "c7f58c120b2b5aa5fd80d540a89fdf866ed42f1f3994e4fe189abebeab610839", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "8a89a1eeccc2d798d6ea15496a6e4870b75e014d1af514b1b71fa33134f57814"},
8081
"makeup_html": {:hex, :makeup_html, "0.1.1", "c3d4abd39d5f7e925faca72ada6e9cc5c6f5fa7cd5bc0158315832656cf14d7f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "44f2a61bc5243645dd7fafeaa6cc28793cd22f3c76b861e066168f9a5b2c26a4"},
8182
"meck": {:hex, :meck, "0.9.2", "85ccbab053f1db86c7ca240e9fc718170ee5bda03810a6292b5306bf31bae5f5", [:rebar3], [], "hexpm", "81344f561357dc40a8344afa53767c32669153355b626ea9fcbc8da6b3045826"},
83+
"merkle_map": {:hex, :merkle_map, "0.2.1", "01a88c87a6b9fb594c67c17ebaf047ee55ffa34e74297aa583ed87148006c4c8", [:mix], [], "hexpm", "fed4d143a5c8166eee4fa2b49564f3c4eace9cb252f0a82c1613bba905b2d04d"},
8284
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"},
8385
"mime": {:hex, :mime, "1.6.0", "dabde576a497cef4bbdd60aceee8160e02a6c89250d6c0b29e56c0dfb00db3d2", [:mix], [], "hexpm", "31a1a8613f8321143dde1dafc36006a17d28d02bdfecb9e95a880fa7aabd19a7"},
8486
"mimerl": {:hex, :mimerl, "1.3.0", "d0cd9fc04b9061f82490f6581e0128379830e78535e017f7780f37fea7545726", [:rebar3], [], "hexpm", "a1e15a50d1887217de95f0b9b0793e32853f7c258a5cd227650889b38839fe9d"},

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)