Running jobs ============ This chapter contains tests that verify that WEBAPP schedules jobs, accepts job output, and lets the admin kill running jobs. Run a job successfully ---------------------- To start with, with an empty run-queue, nothing should be scheduled. SCENARIO run a job GIVEN a new git repository in CONFGIT AND an empty lorry-controller.conf in CONFGIT AND lorry-controller.conf in CONFGIT adds lorries *.lorry using prefix upstream AND WEBAPP uses CONFGIT as its configuration directory AND a running WEBAPP WHEN admin makes request GET /1.0/give-me-job THEN response has job_id set to null WHEN admin makes request GET /1.0/list-running-jobs THEN response has running_jobs set to [] Add a Lorry spec to the run-queue, and request a job. We should get that job now. GIVEN Lorry file CONFGIT/foo.lorry with {"foo":{"type":"git","url":"git://foo"}} WHEN admin makes request GET /1.0/read-configuration AND admin makes request GET /1.0/give-me-job THEN response has job_id set to 1 AND response has path set to "upstream/foo" WHEN admin makes request GET /1.0/lorry/upstream/foo THEN response has running_job set to 1 Requesting another job should now again return null. WHEN admin makes request GET /1.0/give-me-job THEN response has job_id set to null Inform WEBAPP the job is finished. WHEN MINION makes request POST /1.0/job-update with job_id=1&exit=0 THEN response has kill_job set to false WHEN admin makes request GET /1.0/lorry/upstream/foo THEN response has running_job set to null Cleanup. FINALLY WEBAPP terminates Stop job in the middle ---------------------- We need to be able to stop jobs while they're running as well. We start by setting up everything so that a job is running, the same way we did for the successful job scenario. SCENARIO stop a job while it's running GIVEN a new git repository in CONFGIT AND an empty lorry-controller.conf in CONFGIT AND lorry-controller.conf in CONFGIT adds lorries *.lorry using prefix upstream AND WEBAPP uses CONFGIT as its configuration directory AND a running WEBAPP AND Lorry file CONFGIT/foo.lorry with {"foo":{"type":"git","url":"git://foo"}} WHEN admin makes request GET /1.0/read-configuration AND admin makes request GET /1.0/give-me-job THEN response has job_id set to 1 AND response has path set to "upstream/foo" Admin will now ask WEBAPP to kill the job. This changes sets a field in the STATEDB only. WHEN admin makes request POST /1.0/stop-job with job_id=1 AND admin makes request GET /1.0/lorry/upstream/foo THEN response has kill_job set to true Now, when MINION updates the job, WEBAPP will tell it to kill it. MINION will do so, and then update the job again. WHEN MINION makes request POST /1.0/job-update with job_id=1&exit=no THEN response has kill_job set to true WHEN MINION makes request POST /1.0/job-update with job_id=1&exit=1 Admin will now see that the job has, indeed, been killed. WHEN admin makes request GET /1.0/lorry/upstream/foo THEN response has running_job set to null WHEN admin makes request GET /1.0/list-running-jobs THEN response has running_jobs set to [] Cleanup. FINALLY WEBAPP terminates