pull/1876/head
saneery 6 years ago
parent 17569c2c83
commit 7aafc8914f
  1. 2
      apps/explorer/config/config.exs
  2. 20
      apps/explorer/test/explorer/chain/block_count_cache_test.exs

@ -82,8 +82,6 @@ config :spandex_ecto, SpandexEcto.EctoLogger,
tracer: Explorer.Tracer,
otp_app: :explorer
config :explorer, Explorer.Chain.BlockCountCache, ttl: System.get_env("BLOCK_COUNT_CACHE_TTL")
# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config "#{Mix.env()}.exs"

@ -4,52 +4,52 @@ defmodule Explorer.Chain.BlockCountCacheTest do
alias Explorer.Chain.BlockCountCache
test "returns default transaction count" do
BlockCountCache.start_link([[], [name: TestCache]])
BlockCountCache.start_link([name: BlockTestCache])
result = BlockCountCache.value(TestCache)
result = BlockCountCache.count(BlockTestCache)
assert is_nil(result)
end
test "updates cache if initial value is zero" do
BlockCountCache.start_link([[], [name: TestCache]])
BlockCountCache.start_link([name: BlockTestCache])
insert(:block, consensus: true)
insert(:block, consensus: true)
insert(:block, consensus: false)
_result = BlockCountCache.value(TestCache)
_result = BlockCountCache.count(BlockTestCache)
Process.sleep(1000)
updated_value = BlockCountCache.value(TestCache)
updated_value = BlockCountCache.count(BlockTestCache)
assert updated_value == 2
end
test "does not update cache if cache period did not pass" do
BlockCountCache.start_link([[], [name: TestCache]])
BlockCountCache.start_link([name: BlockTestCache])
insert(:block, consensus: true)
insert(:block, consensus: true)
insert(:block, consensus: false)
_result = BlockCountCache.value(TestCache)
_result = BlockCountCache.count(BlockTestCache)
Process.sleep(1000)
updated_value = BlockCountCache.value(TestCache)
updated_value = BlockCountCache.count(BlockTestCache)
assert updated_value == 2
insert(:block, consensus: true)
insert(:block, consensus: true)
_updated_value = BlockCountCache.value(TestCache)
_updated_value = BlockCountCache.count(BlockTestCache)
Process.sleep(1000)
updated_value = BlockCountCache.value(TestCache)
updated_value = BlockCountCache.count(BlockTestCache)
assert updated_value == 2
end

Loading…
Cancel
Save