@@ -41,7 +41,11 @@ defmodule Lightning.RunsTest do
41
41
end
42
42
43
43
describe "claim/1" do
44
- test "claims a run from the queue" do
44
+ setup do
45
+ % { worker_name: "my.worker.name" }
46
+ end
47
+
48
+ test "claims a run from the queue" , % { worker_name: worker_name } do
45
49
% { triggers: [ trigger ] } =
46
50
workflow = insert ( :simple_workflow ) |> with_snapshot ( )
47
51
@@ -51,15 +55,32 @@ defmodule Lightning.RunsTest do
51
55
dataclip: params_with_assocs ( :dataclip )
52
56
)
53
57
54
- assert { :ok , [ claimed ] } = Runs . claim ( )
58
+ assert { :ok , [ claimed ] } = Runs . claim ( worker_name )
55
59
56
60
assert claimed . id == run . id
57
61
assert claimed . state == :claimed
58
62
59
- assert { :ok , [ ] } = Runs . claim ( )
63
+ assert { :ok , [ ] } = Runs . claim ( worker_name )
60
64
end
61
65
62
- test "claims a run from the queue having parallel runs disabled" do
66
+ test "persists worker name when claiming" , % { worker_name: worker_name } do
67
+ % { triggers: [ trigger ] } =
68
+ workflow = insert ( :simple_workflow ) |> with_snapshot ( )
69
+
70
+ { :ok , % { runs: [ run ] } } =
71
+ WorkOrders . create_for ( trigger ,
72
+ workflow: workflow ,
73
+ dataclip: params_with_assocs ( :dataclip )
74
+ )
75
+
76
+ Runs . claim ( worker_name )
77
+
78
+ assert % { worker_name: ^ worker_name } = Repo . get! ( Run , run . id )
79
+ end
80
+
81
+ test "claims a run from the queue having parallel runs disabled" , % {
82
+ worker_name: worker_name
83
+ } do
63
84
project1 = insert ( :project , concurrency: 1 )
64
85
project2 = insert ( :project )
65
86
@@ -82,26 +103,26 @@ defmodule Lightning.RunsTest do
82
103
{ run , % { trigger: trigger , workflow: workflow } }
83
104
end )
84
105
85
- assert { :ok , [ % { id: ^ run1_id , state: :claimed } ] } = Runs . claim ( )
86
- assert { :ok , [ % { id: ^ run2a_id , state: :claimed } ] } = Runs . claim ( )
87
- assert { :ok , [ ] } = Runs . claim ( )
106
+ assert { :ok , [ % { id: ^ run1_id , state: :claimed } ] } = Runs . claim ( worker_name )
107
+ assert { :ok , [ % { id: ^ run2a_id , state: :claimed } ] } = Runs . claim ( worker_name )
108
+ assert { :ok , [ ] } = Runs . claim ( worker_name )
88
109
89
110
{ :ok , % { runs: [ % { id: run2b_id } ] } } =
90
111
WorkOrders . create_for ( trigger2 ,
91
112
workflow: workflow2 ,
92
113
dataclip: params_with_assocs ( :dataclip )
93
114
)
94
115
95
- assert { :ok , [ % { id: ^ run2b_id , state: :claimed } ] } = Runs . claim ( )
116
+ assert { :ok , [ % { id: ^ run2b_id , state: :claimed } ] } = Runs . claim ( worker_name )
96
117
97
118
Repo . get! ( Run , run1_id )
98
119
|> Ecto.Changeset . change ( % { state: :success } )
99
120
|> Repo . update! ( )
100
121
101
- assert { :ok , [ % { id: ^ run3_id , state: :claimed } ] } = Runs . claim ( )
122
+ assert { :ok , [ % { id: ^ run3_id , state: :claimed } ] } = Runs . claim ( worker_name )
102
123
end
103
124
104
- test "claims with demand" do
125
+ test "claims with demand" , % { worker_name: worker_name } do
105
126
% { triggers: [ trigger ] } =
106
127
workflow = insert ( :simple_workflow ) |> with_snapshot ( )
107
128
@@ -117,20 +138,22 @@ defmodule Lightning.RunsTest do
117
138
run
118
139
end )
119
140
120
- assert { :ok , [ claimed_1 , claimed_2 ] } = Runs . claim ( 2 )
141
+ assert { :ok , [ claimed_1 , claimed_2 ] } = Runs . claim ( 2 , worker_name )
121
142
122
143
assert claimed_1 . id == run_1 . id
123
144
assert claimed_1 . state == :claimed
124
145
assert claimed_2 . id == run_2 . id
125
146
assert claimed_2 . state == :claimed
126
147
127
- assert { :ok , [ claimed_3 ] } = Runs . claim ( 2 )
148
+ assert { :ok , [ claimed_3 ] } = Runs . claim ( 2 , worker_name )
128
149
129
150
assert claimed_3 . id == run_3 . id
130
151
assert claimed_3 . state == :claimed
131
152
end
132
153
133
- test "claims with demand for all immediate run" do
154
+ test "claims with demand for all immediate run" , % {
155
+ worker_name: worker_name
156
+ } do
134
157
% { triggers: [ trigger ] } =
135
158
workflow = insert ( :simple_workflow ) |> with_snapshot ( )
136
159
@@ -168,19 +191,19 @@ defmodule Lightning.RunsTest do
168
191
|> then ( fn { :ok , % { run: run } } -> { i , run } end )
169
192
end )
170
193
171
- assert { :ok , [ claimed_1 , claimed_2 ] } = Runs . claim ( 2 )
194
+ assert { :ok , [ claimed_1 , claimed_2 ] } = Runs . claim ( 2 , worker_name )
172
195
173
196
assert claimed_1 . id == runs [ 1 ] . id
174
197
assert claimed_1 . state == :claimed
175
198
assert claimed_2 . id == runs [ 2 ] . id
176
199
assert claimed_2 . state == :claimed
177
200
178
- assert { :ok , [ claimed_3 ] } = Runs . claim ( )
201
+ assert { :ok , [ claimed_3 ] } = Runs . claim ( worker_name )
179
202
180
203
assert claimed_3 . id == runs [ 3 ] . id
181
204
assert claimed_3 . state == :claimed
182
205
183
- assert { :ok , [ claimed_4 , claimed_5 ] } = Runs . claim ( 2 )
206
+ assert { :ok , [ claimed_4 , claimed_5 ] } = Runs . claim ( 2 , worker_name )
184
207
185
208
assert claimed_4 . id in [ runs [ 4 ] . id , second_last_run . id ]
186
209
assert claimed_4 . state == :claimed
@@ -189,7 +212,7 @@ defmodule Lightning.RunsTest do
189
212
assert claimed_5 . id in [ runs [ 4 ] . id , second_last_run . id ]
190
213
assert claimed_5 . state == :claimed
191
214
192
- assert { :ok , [ claimed_6 ] } = Runs . claim ( 2 )
215
+ assert { :ok , [ claimed_6 ] } = Runs . claim ( 2 , worker_name )
193
216
194
217
assert claimed_6 . id == last_run . id
195
218
assert claimed_6 . state == :claimed
0 commit comments