Add FakeAdapter to replace reltuple count query during testing

pull/511/head
Stamates 6 years ago
parent 1e43456b0e
commit 36949da03b
  1. 2
      apps/explorer_web/config/test.exs
  2. 5
      apps/explorer_web/lib/explorer_web/controllers/chain_controller.ex
  3. 4
      apps/explorer_web/lib/explorer_web/notifier.ex
  4. 3
      apps/explorer_web/test/explorer_web/features/viewing_chain_test.exs
  5. 8
      apps/explorer_web/test/support/fake_adapter.ex

@ -11,3 +11,5 @@ config :explorer_web, ExplorerWeb.Endpoint,
# Configure wallaby
config :wallaby, screenshot_on_failure: true
config :explorer_web, :fake_adapter, ExplorerWeb.FakeAdapter

@ -7,9 +7,10 @@ defmodule ExplorerWeb.ChainController do
alias Explorer.ExchangeRates.Token
alias Explorer.Market
@address_count_module Application.get_env(:explorer_web, :fake_adapter) || Chain
def show(conn, _params) do
transaction_estimated_count = Chain.transaction_estimated_count()
address_estimated_count = Chain.address_estimated_count()
transactions =
Chain.recent_collated_transactions(
@ -29,7 +30,7 @@ defmodule ExplorerWeb.ChainController do
render(
conn,
"show.html",
address_estimated_count: address_estimated_count,
address_estimated_count: @address_count_module.address_estimated_count(),
average_block_time: Chain.average_block_time(),
blocks: blocks,
exchange_rate: Market.get_exchange_rate(Explorer.coin()) || Token.null(),

@ -8,8 +8,10 @@ defmodule ExplorerWeb.Notifier do
alias Explorer.ExchangeRates.Token
alias ExplorerWeb.Endpoint
@address_count_module Application.get_env(:explorer_web, :fake_adapter) || Chain
def handle_event({:chain_event, :addresses, addresses}) do
Endpoint.broadcast("addresses:new_address", "count", %{count: Chain.address_estimated_count()})
Endpoint.broadcast("addresses:new_address", "count", %{count: @address_count_module.address_estimated_count()})
addresses
|> Stream.reject(fn %Address{fetched_balance: fetched_balance} -> is_nil(fetched_balance) end)

@ -3,7 +3,6 @@ defmodule ExplorerWeb.ViewingChainTest do
use ExplorerWeb.FeatureCase, async: true
alias Explorer.Chain
alias ExplorerWeb.{AddressPage, BlockPage, ChainPage, Notifier, TransactionPage}
setup do
@ -52,7 +51,7 @@ defmodule ExplorerWeb.ViewingChainTest do
end
test "address count live updates", %{session: session} do
count = Chain.address_estimated_count()
count = ExplorerWeb.FakeAdapter.address_estimated_count()
session
|> ChainPage.visit_page()

@ -0,0 +1,8 @@
defmodule ExplorerWeb.FakeAdapter do
alias Explorer.Chain.Address
alias Explorer.Repo
def address_estimated_count() do
Repo.aggregate(Address, :count, :hash)
end
end
Loading…
Cancel
Save