Add BlockValidationCounter config to disable it in test env.

pull/1170/head
Amanda Sposito 6 years ago
parent 845b399281
commit 7eef405a36
  1. 4
      apps/explorer/config/config.exs
  2. 6
      apps/explorer/config/test.exs
  3. 29
      apps/explorer/lib/explorer/counters/block_validation_counter.ex

@ -17,8 +17,6 @@ config :explorer, Explorer.Integrations.EctoLogger, query_time_ms_threshold: 2_0
config :explorer, Explorer.ExchangeRates, enabled: true config :explorer, Explorer.ExchangeRates, enabled: true
config :explorer, Explorer.Counters.BlockValidationCounter, enabled: true
config :explorer, Explorer.Market.History.Cataloger, enabled: true config :explorer, Explorer.Market.History.Cataloger, enabled: true
config :explorer, Explorer.Repo, config :explorer, Explorer.Repo,
@ -32,6 +30,8 @@ config :explorer, Explorer.Tracer,
config :explorer, Explorer.Counters.TokenTransferCounter, enabled: true config :explorer, Explorer.Counters.TokenTransferCounter, enabled: true
config :explorer, Explorer.Counters.BlockValidationCounter, enabled: true, enable_consolidation: true
config :explorer, Explorer.Counters.TokenHoldersCounter, enabled: true, enable_consolidation: true config :explorer, Explorer.Counters.TokenHoldersCounter, enabled: true, enable_consolidation: true
config :explorer, Explorer.Counters.AddessesWithBalanceCounter, enabled: true, enable_consolidation: true config :explorer, Explorer.Counters.AddessesWithBalanceCounter, enabled: true, enable_consolidation: true

@ -3,8 +3,6 @@ use Mix.Config
# Lower hashing rounds for faster tests # Lower hashing rounds for faster tests
config :bcrypt_elixir, log_rounds: 4 config :bcrypt_elixir, log_rounds: 4
config :explorer, Explorer.Counters.TokenHoldersCounter, enabled: true, enable_consolidation: false
# Configure your database # Configure your database
config :explorer, Explorer.Repo, config :explorer, Explorer.Repo,
adapter: Ecto.Adapters.Postgres, adapter: Ecto.Adapters.Postgres,
@ -21,6 +19,10 @@ config :explorer, Explorer.Market.History.Cataloger, enabled: false
config :explorer, Explorer.Tracer, disabled?: false config :explorer, Explorer.Tracer, disabled?: false
config :explorer, Explorer.Counters.BlockValidationCounter, enabled: true, enable_consolidation: false
config :explorer, Explorer.Counters.TokenHoldersCounter, enabled: true, enable_consolidation: false
config :explorer, Explorer.Counters.AddessesWithBalanceCounter, enabled: true, enable_consolidation: false config :explorer, Explorer.Counters.AddessesWithBalanceCounter, enabled: true, enable_consolidation: false
config :logger, :explorer, config :logger, :explorer,

@ -15,6 +15,14 @@ defmodule Explorer.Counters.BlockValidationCounter do
@table @table
end end
# It is undesirable to automatically start the consolidation in all environments.
# Consider the test environment: if the consolidation initiates but does not
# finish before a test ends, that test will fail. This way, hundreds of
# tests were failing before disabling the consolidation and the scheduler in
# the test env.
config = Application.get_env(:explorer, Explorer.Counters.BlockValidationCounter)
@enable_consolidation Keyword.get(config, :enable_consolidation)
@doc """ @doc """
Creates a process to continually monitor the validation counts. Creates a process to continually monitor the validation counts.
""" """
@ -28,7 +36,9 @@ defmodule Explorer.Counters.BlockValidationCounter do
def init(args) do def init(args) do
create_table() create_table()
Task.start_link(&consolidate_blocks/0) if enable_consolidation?() do
Task.start_link(&consolidate_blocks/0)
end
Chain.subscribe_to_events(:blocks) Chain.subscribe_to_events(:blocks)
@ -40,8 +50,7 @@ defmodule Explorer.Counters.BlockValidationCounter do
:set, :set,
:named_table, :named_table,
:public, :public,
read_concurrency: true, read_concurrency: true
write_concurrency: true
] ]
:ets.new(table_name(), opts) :ets.new(table_name(), opts)
@ -91,4 +100,18 @@ defmodule Explorer.Counters.BlockValidationCounter do
:ets.update_counter(table_name(), string_addr, number, default) :ets.update_counter(table_name(), string_addr, number, default)
end end
@doc """
Returns a boolean that indicates whether consolidation is enabled
In order to choose whether or not to enable the scheduler and the initial
consolidation, change the following Explorer config:
`config :explorer, Explorer.Counters.BlockValidationCounter, enable_consolidation: true`
to:
`config :explorer, Explorer.Counters.BlockValidationCounter, enable_consolidation: false`
"""
def enable_consolidation?, do: @enable_consolidation
end end

Loading…
Cancel
Save