@@ -6,6 +6,7 @@ defmodule Que.Test.Job do
66 alias Que.Test.Meta.TestWorker
77 alias Que.Test.Meta.SuccessWorker
88 alias Que.Test.Meta.FailureWorker
9+ alias Que.Test.Meta.SetupAndTeardownWorker
910
1011
1112 test "#new builds a new Job struct with defaults" do
@@ -56,14 +57,56 @@ defmodule Que.Test.Job do
5657 refute job . pid == nil
5758 refute job . ref == nil
5859
59- Helpers . wait
60+ Helpers . wait_for_children
6061 end )
6162
6263 assert capture =~ ~r/ Starting/
6364 assert capture =~ ~r/ perform: nil/
6465 end
6566
6667
68+ test "#perform triggers the worker's on_setup and on_teardown callbacks on success" do
69+ capture = Helpers . capture_log ( fn ->
70+ job =
71+ SetupAndTeardownWorker
72+ |> Job . new
73+ |> Job . perform
74+ |> Job . handle_success
75+
76+ assert job . status == :completed
77+ assert job . pid == nil
78+ assert job . ref == nil
79+
80+ Helpers . wait_for_children
81+ end )
82+
83+ assert capture =~ ~r/ Completed/
84+ assert capture =~ ~r/ on_setup: %Que.Job/
85+ assert capture =~ ~r/ on_teardown: %Que.Job/
86+ end
87+
88+
89+ test "#perform triggers the worker's on_setup and on_teardown callbacks on failure" do
90+ capture = Helpers . capture_log ( fn ->
91+ job =
92+ SetupAndTeardownWorker
93+ |> Job . new
94+ |> Job . perform
95+ |> Job . handle_failure ( "some error" )
96+
97+ assert job . status == :failed
98+ assert job . pid == nil
99+ assert job . ref == nil
100+
101+ Helpers . wait_for_children
102+ end )
103+
104+ assert capture =~ ~r/ Failed/
105+ assert capture =~ ~r/ on_setup: %Que.Job/
106+ assert capture =~ ~r/ on_teardown: %Que.Job/
107+ end
108+
109+
67110 test "#handle_success works as expected" do
68111 capture = Helpers . capture_log ( fn ->
69112 job =
@@ -75,7 +118,7 @@ defmodule Que.Test.Job do
75118 assert job . pid == nil
76119 assert job . ref == nil
77120
78- Helpers . wait
121+ Helpers . wait_for_children
79122 end )
80123
81124 assert capture =~ ~r/ Completed/
@@ -94,7 +137,7 @@ defmodule Que.Test.Job do
94137 assert job . pid == nil
95138 assert job . ref == nil
96139
97- Helpers . wait
140+ Helpers . wait_for_children
98141 end )
99142
100143 assert capture =~ ~r/ Failed/
0 commit comments