Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions test/createcloudjob.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,22 @@ import { Job } from '../src/job';
const proxyquire = require('proxyquire').noCallThru();
import * as fakeRunlog from "./src/fakeRunLog";
import fakeEcs from "./src/fakeEcs"
import fakeEcsNeverStops from "./src/fakeEcsNeverStops"
import fakeWatchClient from "./src/fakeWatchClient"
import promisify from "../src/promisify"
import * as fakePublisher from "./src/fakePublisher"
const supportedVersions = require("../src/supportedPhpVersions")
const composerVersions = [2]

class fakeCapturingPublisher {
static lastData
constructor (config: {baseUrl}) {}
publish (data: {jobId: number}, callback: Function) {
fakeCapturingPublisher.lastData = data
callback(null, { statusCode: 200 })
}
}

describe('createCloudJob', () => {

beforeEach(done => {
Expand Down Expand Up @@ -96,4 +106,30 @@ describe('createCloudJob', () => {
}
}
})

it('Should report the job as a failure to the backend when waiting for the container to stop times out', async function () {
this.timeout(30000)
fakeCapturingPublisher.lastData = undefined
let { createCloudJob } = proxyquire('../src/createCloudJob', {
'aws-sdk': {
ECS: fakeEcsNeverStops,
CloudWatchLogs: fakeWatchClient
},
'./publisher': { default: fakeCapturingPublisher },
'./RunLog': fakeRunlog,
'await-sleep': () => Promise.resolve()
})
let run = createCloudJob({}, new Job({
slug: 'violinst/example-slug',
job_id: 42
}), 'efef')
await promisify(run.bind(null))
let calls = fakeRunlog.Runlog.getCalls()
should(calls.error.length).equal(1)
should(calls.error[0][0].message).equal('Timed out waiting for the job to stop the container. You can try to requeue the project or try again later')
should(fakeCapturingPublisher.lastData).not.be.undefined()
should(fakeCapturingPublisher.lastData.jobId).equal(42)
should(fakeCapturingPublisher.lastData.set_state).equal('failure')
should(fakeCapturingPublisher.lastData.message.stdout[0]).containEql('Timed out waiting for the job to stop the container')
})
})
43 changes: 43 additions & 0 deletions test/src/fakeEcsNeverStops.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import fakeAwsBase from "./fakeAwsBase"

// Like fakeEcs, but describeTasks never reports the container as STOPPED, so
// createCloudJob's "wait for the task to stop" polling loop never breaks out
// on its own and is forced to hit the timeout branch.
export default class fakeEcsNeverStops extends fakeAwsBase {
protected currentTask

runTask (taskConfig: object) {
this.currentTask = 'runTask'
return this
}

describeTasks (query: object) {
this.currentTask = 'describeTasks'
return this
}

getPromiseOutput() {
if (this.currentTask === 'runTask') {
return {
tasks: [
{
taskArn: 'firstpart/secondpart'
}
]
}
}
if (this.currentTask === 'describeTasks') {
return {
tasks: [
{
containers: [
{
lastStatus: 'RUNNING'
}
]
}
]
}
}
}
}
Loading