rethinkdbdash icon indicating copy to clipboard operation
rethinkdbdash copied to clipboard

Clean up databases created by tests once tests are done

Open kulbirsaini opened this issue 10 years ago • 5 comments

I ran tests using npm test and look what I have. Now I got to clean them up manually :cry:

Rethinkdbdash Test Databases

kulbirsaini avatar Aug 21 '15 05:08 kulbirsaini

Hum so a long time ago rethinkdb didn't like to have too many databases/tables - even removed. I think 2.1 fixed that but I haven't tried it.

That being said, the assumption is basically to just kill/delete the data directory/restart rethinkdb when developing on rethinkdbdash.

neumino avatar Aug 22 '15 01:08 neumino

At least with 2.1, deleting is fine. After running tests a few times, I had 100+ databases left over for cleanup which I could remove using a simple query. I think all the tests should be updated to automate cleanup once the tests have run.

IMO, it's sort of unfair to assume that I would delete my rethinkdb data directory just because I ran the tests. I wouldn't want to lose out on my development dbs of another project. And this assumption inherits the assumption that I am working on a single project at any given point of time which may not be the case.

kulbirsaini avatar Aug 22 '15 05:08 kulbirsaini

@kulbirsaini I absolutely agree with you, but I think there is just a different expectation from the maintainer's perspective. If you take a look over here you can pull out the concept of the TestFixture for the thinky tests and easily rework the tests such that tables and databases are cleaned up properly after test runs.

mbroadst avatar Oct 08 '15 20:10 mbroadst

@mbroadst I could but if that's not going to be merged I don't think I would.

I use my own package Jamadar to cleanup databases. It's fairly straight forward.

var Jamadar = require('jamadar');
var db = new Jamadar(servers: [
        { host: 'localhost', port: 28015 }
      ]);
db.getDbList()
  .then(function(results) {
    // All db names created by rethinkdbdash are of 32 characters.
    var filtered = results.filter(function(result) {
      return result.length === 32;
    });
    console.log(filtered.length, 'databases to be dropped');
    return db.dropDbsIfExist(filtered);
  })
  .then(function() {
    console.log('done');
  });

kulbirsaini avatar Oct 09 '15 05:10 kulbirsaini

I'm fine with a PR that clean the databases after the test. Not a PR that create one database and one table per test.

neumino avatar Oct 09 '15 06:10 neumino