question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can I close a dynamoose instance?

See original GitHub issue

Summary:

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:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
fishcharliecommented, Sep 24, 2019

@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.

0reactions
fishcharliecommented, Jan 24, 2020

Closing due to no activity

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I close a dynamoose instance? · Issue #635 - GitHub
When closing the dynalite server, the dynamoose instance should also close. OR a dynamoose.close() function or similar is needed.
Read more >
Model | Dynamoose
The schema parameter can either be an object OR a Schema instance. If you pass in an object for ... You can use...
Read more >
Logo - Dynamoose
The dynamoose.aws object is used to set AWS level settings for Dynamoose. This includes things like setting a custom DDB instance, setting the...
Read more >
Table | Dynamoose
The Table object represents a single table in DynamoDB. It takes in both a name and array of models and has methods to...
Read more >
Query - Dynamoose
Dynamoose provides the ability to query a model by using the Model.query function. This function acts as a builder to construct your query...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found