Skip to content
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

Modify execution of multiple events to synchronous processing #313

Merged
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
13 changes: 6 additions & 7 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
var path = require('path')
var aws = require('aws-sdk')
var exec = require('child_process').exec
var execSync = require('child_process').execSync
var execFile = require('child_process').execFile
var fs = require('fs-extra')
var packageJson = require(path.join(__dirname, '..', 'package.json'))
Expand Down Expand Up @@ -112,6 +113,7 @@ so you can easily test run multiple events.
if (index >= 0) return index
return _argv.indexOf('--eventFile')
})()
_argv[0] = 'node' // For Windows support

// In order to reproduce the logic of callbackWaitsForEmptyEventLoop,
// we are going to execute `node-lambda run`.
Expand All @@ -126,16 +128,13 @@ so you can easily test run multiple events.
}

fs.writeFileSync(tmpEventFile, JSON.stringify(event))
exec(command(), {
const stdout = execSync(command(), {
maxBuffer: maxBufferSize,
env: process.env
}, (err, stdout, stderr) => {
console.log('>>> Event:', event, '<<<')
if (err) console.error(err)
console.log(stdout)
console.log(stderr)
fs.unlinkSync(tmpEventFile)
})
console.log('>>> Event:', event, '<<<')
console.log(stdout.toString())
fs.unlinkSync(tmpEventFile)
})
}

Expand Down
5 changes: 3 additions & 2 deletions test/node-lambda.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,11 @@ describe('bin/node-lambda', () => {
no: 3
}]

it('`node-lambda run` exitCode is `0`', (done) => {
it('`node-lambda run` exitCode is `0`', function (done) {
this.timeout(10000) // give it time to multiple executions
_generateEventFile(eventObj)
_testMain({
stdoutRegExp: / no: [123] .+ no: [123] .+ no: [123] .+Success:/,
stdoutRegExp: / no: 1 .+ no: 2 .+ no: 3 .+Success:/,
exitCode: 0
}, done)
})
Expand Down