How can I close a dynamoose instance?
See original GitHub issueSummary:
we are setting up some automated tests with dynalite and dynamoose and are hitting a show-stopper: after the test execution a process keeps running. If we just start/stop the dynalite instance (without any interaction with dynamoose) there are no running processes left. Some process keeps running as soon as there is an interaction with dynamoose.
Code sample:
Schema
// Code here
see below
Model
// Code here
see below
General
// dynamooseHelper.js
const dynamoose = require('dynamoose');
const dynalite = require('dynalite');
dynamoose.AWS.config.update({
accessKeyId: 'AKID',
secretAccessKey: 'SECRET',
region: 'us-east-1'
});
module.exports.getRunningDynaliteInstance = async () => {
if (isRunning) {
throw new Error(`dynalite is running`);
}
const portNumber = getPortNumber();
dynaliteInstance = new dynalite();
await dynaliteInstance.listen(portNumber);
dynamoose.local(`http://localhost:${portNumber}`);
isRunning = true;
return portNumber;
}
module.exports.stopDynaliteInstance = async () => {
if (!isRunning) {
throw new Error(`dynalite is not running`);
}
await dynaliteInstance.close();
isRunning = false;
}
function getCatModel() {
return dynamoose.model('Cat', {id: Number, name: String})
}
module.exports.CreateCat = async (id, name) => {
const Cat = getCatModel();
const cat = new Cat({ id: id, name: name});
await cat.save();
return cat;
};
module.exports.GetCat = async (id) => {
const Cat = getCatModel();
const cat = await Cat.get(666);
return cat;
};
// test/startStopTest.js
const assert = require('chai').assert;
const dynaliteHelper = require('../dynamooseHelper');
describe('start stop bad cat', async () => {
before(async function () {
await dynaliteHelper.getRunningDynaliteInstance();
});
after(async function () {
await dynaliteHelper.stopDynaliteInstance();
})
it('dynalite start stop', () => {
const garfield = dynaliteHelper.CreateCat(666, 'Garfield'); // comment out these lines here
assert(garfield != null, 'garfield no lasagne'); // comment out these lines here
const badCat = dynaliteHelper.GetCat(666); // comment out these lines here
assert(badCat != null, 'bad cat'); // change to assert(true)
})
})
Current output and behavior:
After the test, a process keep running. If you comment the lines above and change the assertion, there is no process running after the test. While still acceptable for a developer PC, we cannot use this for CI and automated testing, if there is a process running after each test.
Expected output and behavior:
When closing the dynalite server, the dynamoose instance should also close. OR a dynamoose.close() function or similar is needed.
Environment:
Operating System: Ubuntu
Operating System Version: 18.04
Node.js version (node -v
): v9.11.2
NPM version: (npm -v
): 6.9.0
Dynamoose version: “dynamoose”: “^1.8.0”
Dynamoose Plugins:
“dynalite”: “^2.3.1” (is this to be considered a dynamoose plugin?)
Dynamoose Plugins:
- Yes, I believe that one or multiple 3rd party Dynamoose plugins are effecting this issue
- No, I believe this issue is independent of any 3rd party Dynamoose plugins I’m using
- Unknown, I’m unsure if Dynamoose plugins are effecting this issue
- [?] I am not using any Dynamoose plugins
Other information (if applicable):
You can download a working test project here. https://www.dropbox.com/s/s5bt9o78908vcwg/dynalite-startStopTest.zip?dl=0 Just run ‘npm run test’ or press F5 in VS Code.
Type (select 1):
- [?] Bug report
- Feature suggestion
- Question
- Other suggestion
- Something not listed here
Other:
- I have read through the Dynamoose documentation before posting this issue
- I have searched through the GitHub issues (including closed issues) and pull requests to ensure this issue has not already been raised before
- I have searched the internet and Stack Overflow to ensure this issue hasn’t been raised or answered before
- I have tested the code provided and am confident it doesn’t work as intended
- I have ensured that all of my plugins that I’m using with Dynamoose are listed above
- I have filled out all fields above
- I am running the latest version of Dynamoose
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
@bhw1994 Yes. After calling
dynamoose.model
by default Dynamoose will attempt to create/verify that the table exists in DynamoDB. You can disable this behavior in the options object. But otherwise this is the default (and expected) behavior.Closing due to no activity