File size: 1,127 Bytes
c9c49ab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
defmodule Plausible.Cache.AdapterTest do
  use Plausible.DataCase, async: false

  alias Plausible.Cache.Adapter

  describe "adapter - partitioning" do
    test "multiple partitions are routed to", %{test: test} do
      name = :cache_partitions_test

      iterations = 100
      partitions = 4

      patch_env(Adapter, [{name, partitions: partitions}])

      {:ok, _} =
        Supervisor.start_link(
          Adapter.child_specs(name, name, []),
          strategy: :one_for_one,
          name: :"cache_supervisor_#{test}"
        )

      half = div(iterations, 2)
      for i <- 1..half, do: Adapter.put(name, i, i)
      Adapter.put_many(name, for(i <- half..iterations, do: {i, i}))

      assert Adapter.size(name) == iterations

      for i <- 1..iterations, do: assert(Adapter.get(name, i) == i)

      assert name |> Adapter.keys() |> Enum.sort() == Enum.to_list(1..iterations)

      for i <- 1..partitions do
        assert ConCache.size(:"#{name}_#{i}") > 0
        assert ConCache.size(:"#{name}_#{i}") < iterations
      end

      assert ^iterations = Plausible.Cache.Adapter.size(name)
    end
  end
end