Skip to content

Commit

Permalink
Updated tests to match latest master branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziinc committed Nov 2, 2020
1 parent 81b2871 commit 7a81d67
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
10 changes: 5 additions & 5 deletions lib/crawly/engine.ex
Expand Up @@ -163,16 +163,16 @@ defmodule Crawly.Engine do

def handle_call({:start_all_spiders, nil}, _form, state) do
stopped =
list_all_spider_status(state.started_spiders)
|> Enum.filter(fn s -> s.state == :stopped end)
state.known_spiders
|> Enum.filter(fn s -> Map.has_key?(s.started_spiders, s) == false end)

# start all stopped spiders
new_started_spiders =
Enum.reduce(stopped, state.started_spiders, fn spider_status, acc ->
Crawly.EngineSup.start_spider(spider_status.name)
Enum.reduce(stopped, state.started_spiders, fn info, acc ->
Crawly.EngineSup.start_spider(info.name)
|> case do
{:ok, pid} ->
Map.put(acc, spider_status.name, pid)
Map.put(acc, info.name, pid)

_ ->
acc
Expand Down
22 changes: 8 additions & 14 deletions test/engine_test.exs
Expand Up @@ -23,30 +23,24 @@ defmodule EngineTest do
Crawly.Engine.start_spider(TestSpider)

assert started_status =
Crawly.Engine.list_spiders()
Crawly.Engine.list_known_spiders()
|> Enum.find(fn s -> s.name == TestSpider end)

assert started_status.state == :started
assert started_status.status == :started
assert started_status.pid
end

test "start_all_spiders/0 starts all spiders in the engine" do
assert :ok = Crawly.Engine.start_all_spiders()
statuses = Crawly.Engine.list_spiders()
infos = Crawly.Engine.list_known_spiders()

assert Enum.all?(statuses, fn status ->
status.state == :started and not is_nil(status.pid)
assert Enum.all?(infos, fn info ->
info.status == :started and not is_nil(info.pid)
end)

Crawly.Engine.list_known_spiders()
|> Enum.find(fn s -> s.name == TestSpider end)

assert :started = started_status.status
assert started_status.pid

# stop spider
# stop spiders
Crawly.Engine.stop_spider(TestSpider)
spiders = Crawly.Engine.list_known_spiders()
assert Enum.all?(spiders, fn s -> s.status == :stopped end)
infos = Crawly.Engine.list_known_spiders()
assert Enum.all?(infos, fn s -> s.status == :stopped end)
end
end

0 comments on commit 7a81d67

Please sign in to comment.