this repo has no description
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

Check reads in CoordinatorReadWrite workload

garrison 40740912 93583742

+32 -6
+32 -6
lib/workloads/coordinator_read_write.ex
··· 12 12 13 13 alias Hobbes.Servers.Coordinator 14 14 import Hobbes.Utils 15 + import ExUnit.Assertions, only: [assert: 1] 15 16 16 17 defmodule State do 17 18 @enforce_keys [ ··· 62 63 end 63 64 64 65 defp tick(%State{} = state) do 65 - with {:ok, state} <- do_writes(state) 66 + with {:ok, state} <- do_reads(state), 67 + {:ok, state} <- do_writes(state) 66 68 do 67 69 %State{} = state 68 70 else ··· 71 73 end 72 74 end 73 75 76 + defp do_reads(%State{write_count: 0} = state), do: {:ok, state} 77 + 78 + defp do_reads(%State{} = state) do 79 + count = Enum.random(1..10) 80 + expected_pairs = 81 + Enum.take_random(1..state.write_count, count) 82 + |> Enum.map(fn i -> {key_for(state, i), value_for(state, i)} end) 83 + 84 + keys = Enum.map(expected_pairs, &elem(&1, 0)) 85 + 86 + case Coordinator.read(state.current_coordinator, keys) do 87 + {:ok, pairs} -> 88 + assert length(pairs) == length(expected_pairs) 89 + 90 + pairs_map = Map.new(pairs) 91 + Enum.each(expected_pairs, fn {k, v} -> 92 + assert Map.fetch!(pairs_map, k) == v 93 + end) 94 + 95 + {:ok, state} 96 + 97 + {:error, _err} = error -> error 98 + end 99 + end 100 + 74 101 defp do_writes(%State{} = state) do 75 - id = state.id 76 102 count = Enum.random(1..3) 77 103 si = state.write_count 78 104 ei = state.write_count + count 79 105 80 106 pairs = Enum.map(si..ei, fn i -> 81 - { 82 - "key #{id} #{i}", 83 - "value #{id} #{i}", 84 - } 107 + {key_for(state, i), value_for(state, i)} 85 108 end) 86 109 87 110 case Coordinator.write(state.current_coordinator, pairs) do ··· 89 112 {:error, _err} = error -> error 90 113 end 91 114 end 115 + 116 + defp key_for(%State{id: id}, i), do: "key #{id} #{i}" 117 + defp value_for(%State{id: id}, i), do: "value #{id} #{i}" 92 118 93 119 defp inc(%State{} = state, stat) do 94 120 %{state | stats: inc_stat(state.stats, stat)}