Skip to content

Commit 9b625cb

Browse files
committed
added checkpoint tests
1 parent ecb8e49 commit 9b625cb

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

test/40.database.checkpoint.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,39 @@
11
var expect = require('chai').expect;
2+
var fs = require('fs');
23
var Database = require('../.');
4+
var db;
5+
6+
before(function (done) {
7+
db = new Database('temp/' + require('path').basename(__filename).split('.')[0] + '.db');
8+
db.on('open', function () {
9+
db.pragma('journal_mode = WAL');
10+
db.prepare('CREATE TABLE entries (a TEXT, b INTEGER)').run();
11+
done();
12+
});
13+
});
314

415
describe('Database#checkpoint()', function () {
5-
16+
describe('before a checkpoint', function () {
17+
it('every insert should increase the size of the WAL file', function () {
18+
var size1, size2;
19+
for (var i=0; i<10; ++i) {
20+
size1 = fs.statSync(db.name + '-wal').size;
21+
db.prepare('INSERT INTO entries VALUES (?, ?)').run('bar', 999);
22+
size2 = fs.statSync(db.name + '-wal').size;
23+
expect(size2).to.be.above(size1);
24+
}
25+
});
26+
});
27+
describe('after a checkpoint', function () {
28+
it('inserts should NOT increase the size of the WAL file', function () {
29+
expect(db.checkpoint()).to.equal(1);
30+
var size1, size2;
31+
for (var i=0; i<10; ++i) {
32+
size1 = fs.statSync(db.name + '-wal').size;
33+
db.prepare('INSERT INTO entries VALUES (?, ?)').run('bar', 999);
34+
size2 = fs.statSync(db.name + '-wal').size;
35+
expect(size2).to.be.equal(size1);
36+
}
37+
});
38+
});
639
});

0 commit comments

Comments
 (0)