Skip to content

Commit 9b3fd44

Browse files
committed
Remove logging message and update tests
1 parent 489791a commit 9b3fd44

3 files changed

Lines changed: 7 additions & 24 deletions

File tree

lib/google_crawler/search/search_keyword_worker.ex

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ defmodule GoogleCrawler.SearchKeywordWorker do
2727
end
2828

2929
def handle_call({:search, keyword_id}, _from, state) do
30-
IO.puts("Handle call #{keyword_id}")
31-
3230
keyword = Search.get_keyword(keyword_id)
3331
Search.update_keyword(keyword, %{status: :in_progress})
3432

@@ -45,8 +43,6 @@ defmodule GoogleCrawler.SearchKeywordWorker do
4543
end
4644

4745
def handle_info({ref, result}, state) do
48-
IO.puts("Handle info | success")
49-
5046
{keyword, _retry_count} = Map.get(state, ref)
5147

5248
Search.update_keyword(keyword, %{
@@ -62,22 +58,17 @@ defmodule GoogleCrawler.SearchKeywordWorker do
6258
end
6359

6460
def handle_info({:DOWN, ref, :process, _pid, _reason}, state) do
65-
IO.puts("Handle info | failed")
66-
6761
{keyword, retry_count} = Map.get(state, ref)
6862

6963
new_state =
7064
if retry_count < @max_retry_count do
71-
IO.puts("Retry... #{retry_count}")
7265
task = start_task(keyword)
7366

7467
state
7568
|> Map.delete(ref)
7669
|> Map.put(task.ref, {keyword, retry_count + 1})
7770
else
78-
IO.puts("Done with failed...")
7971
Search.update_keyword(keyword, %{status: :failed})
80-
8172
Map.delete(state, ref)
8273
end
8374

test/google_crawler/search/search_keyword_worker_test.exs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ defmodule GoogleCrawler.Search.SearchKeywordWorkerTest do
1414

1515
assert %{^task_ref => {keyword, 0}} = SearchKeywordWorker.get_state()
1616
assert Search.get_keyword(keyword.id).status == :in_progress
17+
18+
:timer.sleep(1000)
19+
assert SearchKeywordWorker.get_state() == %{}
1720
end
1821

1922
test "search/1 updates the keyword result when the task is completed" do

test/google_crawler/search_test.exs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ defmodule GoogleCrawler.SearchTest do
3030

3131
assert {:ok, %Keyword{} = keyword} = Search.create_keyword(keyword_attrs, user)
3232
assert keyword.keyword == "elixir"
33-
assert keyword.status == :created
33+
assert keyword.status == :in_queue
3434
assert keyword.user_id == user.id
3535
end
3636

@@ -45,20 +45,9 @@ defmodule GoogleCrawler.SearchTest do
4545
keyword = KeywordFactory.create()
4646
keyword_attrs = %{keyword: "new", status: :in_progress}
4747

48-
# assert {:ok, %Keyword{} = keyword} = Search.update_keyword(keyword, keyword_attrs)
49-
# assert keyword.keyword == "new"
50-
# assert keyword.status == :in_progress
51-
52-
Search.update_keyword(keyword, %{status: :in_progress})
53-
Search.update_keyword(keyword, %{status: :failed})
54-
Search.update_keyword(keyword, %{status: :in_progress})
55-
Search.update_keyword(keyword, %{status: :failed})
56-
Search.update_keyword(keyword, %{status: :in_progress})
57-
Search.update_keyword(keyword, %{status: :failed})
58-
Search.update_keyword(keyword, %{status: :in_progress})
59-
Search.update_keyword(keyword, %{status: :completed})
60-
61-
IO.inspect(Search.get_keyword(keyword.id))
48+
assert {:ok, %Keyword{} = keyword} = Search.update_keyword(keyword, keyword_attrs)
49+
assert keyword.keyword == "new"
50+
assert keyword.status == :in_progress
6251
end
6352

6453
test "update_keyword/2 with invalid data returns error changeset" do

0 commit comments

Comments
 (0)