Tests doesn't seem to terminate
jhnferraris opened this issue · 11 comments
I am a noob in coding Alexa skills and I bump into your test framework. Cool tool btw.
I have a problem here when I try to run my tests. When I execute npm test
it doesn't terminate
I just followed the code in one of your examples as an experiment but I still have the same behavior.
const alexaTest = require('alexa-skill-test-framework');
alexaTest.initialize(
require('../index.js'),
"skill-id",
'user-id');
describe("Alexa skill using Staging configuration", function() {
describe("LaunchRequest", function() {
alexaTest.test([
{
request: alexaTest.getLaunchRequest(),
says: "Welcome!", repromptsNothing: true, shouldEndSession: true
}
]);
});
describe("CountIntent", function() {
const slot = {'companyMetadata': 'employees', 'siteName': 'fort'};
const requestWithSlot = alexaTest.getIntentRequest('CountIntent', slot);
alexaTest.test([
{
request: requestWithSlot,
says: "fort has 61 employees", shouldEndSession: true, repromptsNothing: true
}
]);
});
});
My node version is v9.0.0
package.json is
"dependencies": {
"alexa-sdk": "^1.0.12",
"dotenv": "^4.0.0",
"pg": "^7.4.0"
},
"devDependencies": {
"alexa-skill-test-framework": "^1.1.2",
"chai": "^4.1.2",
"mocha": "^4.0.1"
}
Appreciate the help.
Can you post (parts of) the code? Maybe disable all test and reenable them one by one to find the one that does not terminate.
@hoegertn Apologies. I updated my post
@hoegertn I tried running only the "LaunchIntent" test, still experience the same behavior.
My node version is v9.0.0
package.json is
"dependencies": {
"alexa-sdk": "^1.0.12",
"dotenv": "^4.0.0",
"pg": "^7.4.0"
},
"devDependencies": {
"alexa-skill-test-framework": "^1.1.2",
"chai": "^4.1.2",
"mocha": "^4.0.1"
}
@hoegertn I disabled everything and left the initialize
code. That was where the "stuck" happened
From your dependencies, I see, that you are using Postgres. Do you happen to open a connection pool, that is not closed?
@hoegertn Ah yes. I did not close it since the lambda function won't be able to connect to it again when I tried to asked Alexa to connect to the db again.
You can try to set context.callbackWaitsForEmptyEventLoop = false;
in your handler function.
@hoegertn Before execution? What does it do if you don't mind me asking?
As the first line in your handler function.
It tells Lambda to not block until all things on the event loop are gone.
I am not sure if it helps with your test problem, but it will cause trouble on AWS Lambda if not set.
@hoegertn I tried it and it is still stuck. hmm
So the issue here is because of the postgres Client not getting closed after the tests are finished.
@jhnferraris did you solve this issue? Can we close this one or is it still needed?