@@ -189,6 +189,63 @@ public void evaluate() throws Throwable {
189
189
});
190
190
}
191
191
192
+ @ Test
193
+ public void lockOrderLabelQuantityFreedResources () {
194
+ story .addStep (new Statement () {
195
+ @ Override
196
+ public void evaluate () throws Throwable {
197
+ LockableResourcesManager .get ().createResourceWithLabel ("resource1" , "label1" );
198
+ LockableResourcesManager .get ().createResourceWithLabel ("resource2" , "label1" );
199
+ LockableResourcesManager .get ().createResourceWithLabel ("resource3" , "label1" );
200
+ WorkflowJob p = story .j .jenkins .createProject (WorkflowJob .class , "p" );
201
+ p .setDefinition (new CpsFlowDefinition (
202
+ "lock(label: 'label1') {\n " +
203
+ " semaphore 'wait-inside'\n " +
204
+ "}\n " +
205
+ "echo 'Finish'"
206
+ ));
207
+ WorkflowRun b1 = p .scheduleBuild2 (0 ).waitForStart ();
208
+ SemaphoreStep .waitForStart ("wait-inside/1" , b1 );
209
+
210
+ WorkflowJob p2 = story .j .jenkins .createProject (WorkflowJob .class , "p2" );
211
+ p2 .setDefinition (new CpsFlowDefinition (
212
+ "lock(label: 'label1', quantity: 2) {\n " +
213
+ " semaphore 'wait-inside-quantity2'\n " +
214
+ "}\n " +
215
+ "echo 'Finish'"
216
+ ));
217
+ WorkflowRun b2 = p2 .scheduleBuild2 (0 ).waitForStart ();
218
+ // Ensure that b2 reaches the lock before b3
219
+ story .j .waitForMessage ("[Label: label1, Quantity: 2] is locked, waiting..." , b2 );
220
+ story .j .waitForMessage ("Found 0 available resource(s). Waiting for correct amount: 2." , b2 );
221
+
222
+ WorkflowJob p3 = story .j .jenkins .createProject (WorkflowJob .class , "p3" );
223
+ p3 .setDefinition (new CpsFlowDefinition (
224
+ "lock(label: 'label1', quantity: 1) {\n " +
225
+ " semaphore 'wait-inside-quantity1'\n " +
226
+ "}\n " +
227
+ "echo 'Finish'"
228
+ ));
229
+ WorkflowRun b3 = p3 .scheduleBuild2 (0 ).waitForStart ();
230
+ story .j .waitForMessage ("[Label: label1, Quantity: 1] is locked, waiting..." , b3 );
231
+ story .j .waitForMessage ("Found 0 available resource(s). Waiting for correct amount: 1." , b3 );
232
+
233
+ // Unlock Label: label1
234
+ SemaphoreStep .success ("wait-inside/1" , null );
235
+ story .j .waitForMessage ("Lock released on resource [Label: label1]" , b1 );
236
+
237
+ // Both get their lock
238
+ story .j .waitForMessage ("Lock acquired on [Label: label1, Quantity: 2]" , b2 );
239
+ story .j .waitForMessage ("Lock acquired on [Label: label1, Quantity: 1]" , b3 );
240
+
241
+ SemaphoreStep .success ("wait-inside-quantity2/1" , null );
242
+ SemaphoreStep .success ("wait-inside-quantity1/1" , null );
243
+ story .j .waitForMessage ("Finish" , b2 );
244
+ story .j .waitForMessage ("Finish" , b3 );
245
+ }
246
+ });
247
+ }
248
+
192
249
@ Test
193
250
public void lockOrder () {
194
251
story .addStep (new Statement () {
0 commit comments