Skip to content

Commit

Permalink
tests: fix backup tests (#1154)
Browse files Browse the repository at this point in the history
tests: wait for the backup to complete before finishing it
tests: only trigger internal backup (from main to temp tables) when version is larger or equal to 3.26
  • Loading branch information
kewde authored Apr 28, 2019
1 parent 9a0c292 commit 4f5b996
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions test/backup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,22 +151,24 @@ describe('backup', function() {
});
});

(sqlite3.VERSION_NUMBER < 3007011 ? it.skip : it) ('can backup from temp to main', function(done) {
(sqlite3.VERSION_NUMBER < 3026000 ? it.skip : it) ('can backup from temp to main', function(done) {
db.exec("CREATE TEMP TABLE space (txt TEXT)", function(err) {
if (err) throw err;
db.exec("INSERT INTO space(txt) VALUES('monkey')", function(err) {
if (err) throw err;
var backup = db.backup('test/tmp/backup.db', 'temp', 'main', true, function(err) {
if (err) throw err;
backup.step(-1);
backup.finish(function(err) {
backup.step(-1, function(err) {
if (err) throw err;
var db2 = new sqlite3.Database('test/tmp/backup.db', function(err) {
backup.finish(function(err) {
if (err) throw err;
db2.get("SELECT * FROM space", function(err, row) {
var db2 = new sqlite3.Database('test/tmp/backup.db', function(err) {
if (err) throw err;
assert.equal(row.txt, 'monkey');
db2.close(done);
db2.get("SELECT * FROM space", function(err, row) {
if (err) throw err;
assert.equal(row.txt, 'monkey');
db2.close(done);
});
});
});
});
Expand All @@ -175,13 +177,15 @@ describe('backup', function() {
});
});

(sqlite3.VERSION_NUMBER < 3007011 ? it.skip : it) ('can backup from main to temp', function(done) {
(sqlite3.VERSION_NUMBER < 3026000 ? it.skip : it) ('can backup from main to temp', function(done) {
var backup = db.backup('test/support/prepare.db', 'main', 'temp', false, function(err) {
if (err) throw err;
backup.step(-1);
backup.finish(function(err) {
backup.step(-1, function(err) {
if (err) throw err;
assertRowsMatchDb(db, 'temp.foo', db, 'main.foo', done);
backup.finish(function(err) {
if (err) throw err;
assertRowsMatchDb(db, 'temp.foo', db, 'main.foo', done);
});
});
});
});
Expand Down

0 comments on commit 4f5b996

Please sign in to comment.