JohanObrink / rethink-migrate

A migration tool for rethink db
MIT License
47 stars 24 forks source link

migrateUp and migrateDown do not close their connections when finished #44

Open jrnail23 opened 6 years ago

jrnail23 commented 6 years ago

I'm using the migrate module directly (instead of the CLI) in jest test setups and teardowns (up on setup, down on teardown), and jest was hanging after the down migrations ran. I noticed that migrateUp and migrateDown never close their connections after executing. After adding the following finally blocks to each usage, jest stopped hanging, and its process was able to exit cleanly:

.finally(function () {
  return connection.close();
});

I'm pretty sure finally isn't supported everywhere yet, but the same can be accomplished via including the same in both a then and a catch. EDIT: actually, it's using the promises returned by rethink, which are bluebird promises (and thus, support finally).

jrnail23 commented 6 years ago

@vinicius0026: I saw your issue introducing rethinkdb-migrate after I posted this issue. I couldn't immediately tell whether yours suffers from this same issue, but it's probably worth checking! 😄

vinicius0026 commented 6 years ago

Hey @jrnail23, sure you can take a look at rethinkdb-migrate. Make sure to check our tests scripts, where we do just what you suggested here and close the connection.