1
1
const startSupertestServer = require ( '../util/api-server' ) ;
2
2
const automationRoutes = require ( '../../routes/automation' ) ;
3
3
const {
4
- setupMockAutomationSchedulerServer
4
+ setupMockAutomationSchedulerServer,
5
+ startCollectionJobSimulation
5
6
} = require ( '../util/mock-automation-scheduler-server' ) ;
6
7
const db = require ( '../../models/index' ) ;
7
8
const { query, mutate } = require ( '../util/graphql-test-utilities' ) ;
@@ -197,6 +198,22 @@ const restartCollectionJobByMutation = async (jobId, { transaction }) =>
197
198
{ transaction }
198
199
) ;
199
200
201
+ const retryCanceledCollectionJobByMutation = async ( jobId , { transaction } ) =>
202
+ await mutate (
203
+ `
204
+ mutation {
205
+ collectionJob(id: "${ jobId } ") {
206
+ retryCanceledCollections {
207
+ id
208
+ status
209
+ testStatus {
210
+ status
211
+ }
212
+ }
213
+ }
214
+ } ` ,
215
+ { transaction }
216
+ ) ;
200
217
const cancelCollectionJobByMutation = async ( jobId , { transaction } ) =>
201
218
await mutate (
202
219
`
@@ -237,6 +254,18 @@ describe('Automation controller', () => {
237
254
expect ( storedJob . status ) . toEqual ( 'QUEUED' ) ;
238
255
expect ( storedJob . testPlanRun . testPlanReport . id ) . toEqual ( testPlanReportId ) ;
239
256
expect ( storedJob . testPlanRun . testResults . length ) . toEqual ( 0 ) ;
257
+ const collectionJob = await getCollectionJobById ( {
258
+ id : storedJob . id ,
259
+ transaction
260
+ } ) ;
261
+ const tests =
262
+ collectionJob . testPlanRun . testPlanReport . testPlanVersion . tests . filter (
263
+ test => test . at . key === 'voiceover_macos'
264
+ ) ;
265
+ // check testIds - order doesn't matter, so we sort them
266
+ expect (
267
+ startCollectionJobSimulation . lastCallParams . testIds . sort ( )
268
+ ) . toEqual ( tests . map ( test => test . id ) . sort ( ) ) ;
240
269
} ) ;
241
270
} ) ;
242
271
@@ -260,6 +289,105 @@ describe('Automation controller', () => {
260
289
} ) ;
261
290
} ) ;
262
291
292
+ it ( 'should retry a cancelled job with only remaining tests' , async ( ) => {
293
+ await apiServer . sessionAgentDbCleaner ( async transaction => {
294
+ const { scheduleCollectionJob : job } =
295
+ await scheduleCollectionJobByMutation ( { transaction } ) ;
296
+ const collectionJob = await getCollectionJobById ( {
297
+ id : job . id ,
298
+ transaction
299
+ } ) ;
300
+ const secret = await getJobSecret ( collectionJob . id , { transaction } ) ;
301
+
302
+ // start "RUNNING" the job
303
+ const response1 = await sessionAgent
304
+ . post ( `/api/jobs/${ collectionJob . id } ` )
305
+ . send ( { status : 'RUNNING' } )
306
+ . set ( 'x-automation-secret' , secret )
307
+ . set ( 'x-transaction-id' , transaction . id ) ;
308
+ expect ( response1 . statusCode ) . toBe ( 200 ) ;
309
+
310
+ // simulate a response for a test
311
+ const automatedTestResponse = 'AUTOMATED TEST RESPONSE' ;
312
+ const ats = await AtLoader ( ) . getAll ( { transaction } ) ;
313
+ const browsers = await BrowserLoader ( ) . getAll ( { transaction } ) ;
314
+ const at = ats . find (
315
+ at => at . id === collectionJob . testPlanRun . testPlanReport . at . id
316
+ ) ;
317
+ const browser = browsers . find (
318
+ browser =>
319
+ browser . id === collectionJob . testPlanRun . testPlanReport . browser . id
320
+ ) ;
321
+ const { tests } =
322
+ collectionJob . testPlanRun . testPlanReport . testPlanVersion ;
323
+ const selectedTestIndex = 2 ;
324
+
325
+ const selectedTest = tests [ selectedTestIndex ] ;
326
+ const selectedTestRowNumber = selectedTest . rowNumber ;
327
+
328
+ const numberOfScenarios = selectedTest . scenarios . filter (
329
+ scenario => scenario . atId === at . id
330
+ ) . length ;
331
+ const response2 = await sessionAgent
332
+ . post ( `/api/jobs/${ collectionJob . id } /test/${ selectedTestRowNumber } ` )
333
+ . send ( {
334
+ capabilities : {
335
+ atName : at . name ,
336
+ atVersion : at . atVersions [ 0 ] . name ,
337
+ browserName : browser . name ,
338
+ browserVersion : browser . browserVersions [ 0 ] . name
339
+ } ,
340
+ responses : new Array ( numberOfScenarios ) . fill ( automatedTestResponse )
341
+ } )
342
+ . set ( 'x-automation-secret' , secret )
343
+ . set ( 'x-transaction-id' , transaction . id ) ;
344
+ expect ( response2 . statusCode ) . toBe ( 200 ) ;
345
+ // cancel the job
346
+ const {
347
+ collectionJob : { cancelCollectionJob : cancelledCollectionJob }
348
+ } = await cancelCollectionJobByMutation ( collectionJob . id , {
349
+ transaction
350
+ } ) ;
351
+
352
+ // check canceled status
353
+
354
+ expect ( cancelledCollectionJob . status ) . toEqual ( 'CANCELLED' ) ;
355
+ const { collectionJob : storedCollectionJob } = await getTestCollectionJob (
356
+ collectionJob . id ,
357
+ { transaction }
358
+ ) ;
359
+ expect ( storedCollectionJob . status ) . toEqual ( 'CANCELLED' ) ;
360
+ for ( const test of storedCollectionJob . testStatus ) {
361
+ const expectedStatus =
362
+ test . test . id == selectedTest . id ? 'COMPLETED' : 'CANCELLED' ;
363
+ expect ( test . status ) . toEqual ( expectedStatus ) ;
364
+ }
365
+
366
+ // retry job
367
+ const data = await retryCanceledCollectionJobByMutation (
368
+ collectionJob . id ,
369
+ { transaction }
370
+ ) ;
371
+ expect ( data . collectionJob . retryCanceledCollections . status ) . toBe ( 'QUEUED' ) ;
372
+ const { collectionJob : restartedCollectionJob } =
373
+ await getTestCollectionJob ( collectionJob . id , { transaction } ) ;
374
+ // check restarted status
375
+ expect ( restartedCollectionJob . status ) . toEqual ( 'QUEUED' ) ;
376
+ for ( const test of restartedCollectionJob . testStatus ) {
377
+ const expectedStatus =
378
+ test . test . id == selectedTest . id ? 'COMPLETED' : 'QUEUED' ;
379
+ expect ( test . status ) . toEqual ( expectedStatus ) ;
380
+ }
381
+ const expectedTests = tests . filter (
382
+ test => test . at . key === 'voiceover_macos' && test . id != selectedTest . id
383
+ ) ;
384
+ // check testIds - order doesn't matter, so we sort them
385
+ expect (
386
+ startCollectionJobSimulation . lastCallParams . testIds . sort ( )
387
+ ) . toEqual ( expectedTests . map ( test => test . id ) . sort ( ) ) ;
388
+ } ) ;
389
+ } ) ;
390
+
263
391
it ( 'should gracefully reject request to cancel a job that does not exist' , async ( ) => {
264
392
await dbCleaner ( async transaction => {
265
393
expect . assertions ( 1 ) ; // Make sure an assertion is made
0 commit comments