-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Warn on RunTask failures #93
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
'use strict' | ||
|
||
const { mockClient } = require('aws-sdk-client-mock'); | ||
const { ECS, DescribeTaskDefinitionCommand, RunTaskCommand } = require("@aws-sdk/client-ecs"); | ||
const { CloudWatchLogs, GetLogEventsCommand } = require("@aws-sdk/client-cloudwatch-logs"); | ||
const expect = require('expect.js'); | ||
const { promisify } = require('node:util'); | ||
const index = promisify(require('../index')); | ||
|
||
describe('index', function () { | ||
let cwlMock; | ||
let ecsMock; | ||
beforeEach(() => { | ||
cwlMock = mockClient(CloudWatchLogs); | ||
ecsMock = mockClient(ECS); | ||
}); | ||
|
||
it('should do the thing', async function () { | ||
const options = { | ||
taskDefinitionArn: 'task-definition.arn', | ||
containerName: 'meow' | ||
}; | ||
|
||
ecsMock.on(DescribeTaskDefinitionCommand).callsFake(async params => { | ||
expect(params.taskDefinition).to.eql(options.taskDefinitionArn) | ||
|
||
return { | ||
taskDefinition: { | ||
taskDefinitionArn: options.taskDefinitionArn, | ||
containerDefinitions: [{ | ||
name: options.containerName, | ||
logConfiguration: { | ||
logDriver: 'awslogs', | ||
options: { 'awslogs-group': '', 'awslogs-stream-prefix': '' }, | ||
} | ||
}], | ||
} | ||
} | ||
}); | ||
|
||
// thread the randon EOF through to kill the stream | ||
let eofSet; | ||
const eof = new Promise(r => { | ||
eofSet = r; | ||
}) | ||
ecsMock.on(RunTaskCommand).callsFake(async params => { | ||
expect(params.taskDefinition).to.eql(options.taskDefinitionArn) | ||
|
||
// Grab the `xxx` from ..."TASK FINISHED: $(echo -n xxx | base64),"... | ||
eofSet(params.overrides.containerOverrides[0].command[2].split(' ')[9]) | ||
|
||
return { | ||
tasks: [{ | ||
taskArn: '' | ||
}] | ||
} | ||
}); | ||
|
||
cwlMock.on(GetLogEventsCommand).callsFake(async _params => { | ||
return { | ||
events: [{ | ||
timestamp: 1477346285562, | ||
message: Buffer.from(await eof).toString('base64'), | ||
}] | ||
}; | ||
}); | ||
|
||
// if this returns without crashing we're gucci | ||
return index(options); | ||
}); | ||
|
||
|
||
it('should warn us when a task fails to launch', async function () { | ||
const options = { | ||
taskDefinitionArn: 'task-definition.arn', | ||
containerName: 'meow' | ||
}; | ||
|
||
ecsMock.on(DescribeTaskDefinitionCommand).callsFake(async params => { | ||
expect(params.taskDefinition).to.eql(options.taskDefinitionArn) | ||
|
||
return { | ||
taskDefinition: { | ||
taskDefinitionArn: options.taskDefinitionArn, | ||
containerDefinitions: [{ | ||
name: options.containerName, | ||
logConfiguration: { | ||
logDriver: 'awslogs', | ||
options: { 'awslogs-group': '', 'awslogs-stream-prefix': '' }, | ||
} | ||
}], | ||
} | ||
} | ||
}); | ||
|
||
const reason = 'ECS is haunted' | ||
ecsMock.on(RunTaskCommand).callsFake(async params => { | ||
expect(params.taskDefinition).to.eql(options.taskDefinitionArn) | ||
|
||
return { | ||
failures: [{ reason }] | ||
} | ||
}); | ||
|
||
try { | ||
await index(options); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It didn't work ¯_(ツ)_/¯ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think mocha and expect.js might be kind dead projects. Something that annoyed my the whole time in working on this is that errors were always "test timed out" and apparently that's just mocha being terrible with promises. |
||
expect().fail("App should have thrown an error about ECS returning errors") | ||
} catch (err) { | ||
expect(err.cause[0].reason).to.eql(reason) | ||
} | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really get what this does
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add a comment, but yeah this is ugliest bit of this. This is the only place we can grab the random value the log stuff uses to detect the end of the task run.