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, tracer: Explorer.Tracer,
otp_app: :explorer 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 # Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above. # of this file so it overrides the configuration defined above.
import_config "#{Mix.env()}.exs" import_config "#{Mix.env()}.exs"

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

Loading…
Cancel
Save