Failing regression tests for #340

pull/411/head
Luke Imhoff 6 years ago
parent a8f33953bf
commit ff11541bde
  1. 3
      apps/indexer/lib/indexer/block_fetcher.ex
  2. 62
      apps/indexer/test/indexer/block_fetcher_test.exs

@ -274,7 +274,8 @@ defmodule Indexer.BlockFetcher do
|> chunk_ranges(blocks_batch_size)
end
defp chunk_ranges(ranges, size) do
@doc false
def chunk_ranges(ranges, size) do
Enum.flat_map(ranges, fn
first..last = range when last - first <= size ->
[range]

@ -829,6 +829,68 @@ defmodule Indexer.BlockFetcherTest do
end
end
describe "chunk_ranges/2" do
test "with first < last in one chunk" do
range = 0..1
size = 2
assert Enum.count(range) <= size
assert BlockFetcher.chunk_ranges([range], size) == [range]
end
test "with first < last with filled last chunk" do
range = 0..1
size = 1
assert Enum.count(range) > size
assert rem(Enum.count(range), size) == 0
assert BlockFetcher.chunk_ranges([range], size) == [0..0, 1..1]
end
test "with first < last with unfilled last chunk" do
range = 0..2
size = 2
assert Enum.count(range) > size
refute rem(Enum.count(range), size) == 0
assert BlockFetcher.chunk_ranges([range], size) == [0..1, 2..2]
end
test "with first == last" do
range = 0..0
size = 1
assert Enum.count(range) == size
assert BlockFetcher.chunk_ranges([range], size) == [range]
end
test "with first > last in one chunk" do
range = 1..0
size = 2
assert Enum.count(range) <= size
assert BlockFetcher.chunk_ranges([range], size) == [range]
end
test "with first > last with filled last chunk" do
range = 1..0
size = 1
assert Enum.count(range) > size
assert rem(Enum.count(range), size) == 0
assert BlockFetcher.chunk_ranges([range], size) == [1..1, 0..0]
end
test "with first > last with unfilled last chunk" do
range = 2..0
size = 2
assert Enum.count(range) > size
refute rem(Enum.count(range), size) == 0
assert BlockFetcher.chunk_ranges([range], size) == [2..1, 0..0]
end
end
defp capture_log_at_level(level, block) do
logger_level_transaction(fn ->
Logger.configure(level: level)

Loading…
Cancel
Save