From 7a81d67707e5f9fab888b3272d37373442889a46 Mon Sep 17 00:00:00 2001 From: TzeYiing Date: Mon, 2 Nov 2020 12:25:01 +0800 Subject: [PATCH] Updated tests to match latest master branch --- lib/crawly/engine.ex | 10 +++++----- test/engine_test.exs | 22 ++++++++-------------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/lib/crawly/engine.ex b/lib/crawly/engine.ex index c77131ca..850b09b0 100644 --- a/lib/crawly/engine.ex +++ b/lib/crawly/engine.ex @@ -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 diff --git a/test/engine_test.exs b/test/engine_test.exs index 41898529..a046aecf 100644 --- a/test/engine_test.exs +++ b/test/engine_test.exs @@ -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