Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add open/close for sharedcache memory database
  • Loading branch information
gms1 committed Dec 9, 2018
commit 5f3a351cc15784f1cef9ac502a51db0913f84e5a
37 changes: 36 additions & 1 deletion test/open_close.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('open/close', function() {

var db;
it('should open the database', function(done) {
db = new sqlite3.Database('test/tmp/test_create_shared.db',sqlite3.OPEN_SHAREDCACHE, done);
db = new sqlite3.Database('file:./test/tmp/test_create_shared.db', sqlite3.OPEN_URI | sqlite3.OPEN_SHAREDCACHE | sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE, done);
});

it('should close the database', function(done) {
Expand All @@ -54,6 +54,41 @@ describe('open/close', function() {
});
});


describe('open and close shared memory database', function() {

var db1;
var db2;

it('should open the first database', function(done) {
db1 = new sqlite3.Database('file:./test/tmp/test_memory.db?mode=memory', sqlite3.OPEN_URI | sqlite3.OPEN_SHAREDCACHE | sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE, done);
});

it('should open the second database', function(done) {
db2 = new sqlite3.Database('file:./test/tmp/test_memory.db?mode=memory', sqlite3.OPEN_URI | sqlite3.OPEN_SHAREDCACHE | sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE, done);
});

it('first database should set the user_version', function(done) {
db1.exec('PRAGMA user_version=42', done);
});

it('second database should get the user_version', function(done) {
db2.get('PRAGMA user_version', function(err, row) {
if (err) throw err;
assert.equal(row.user_version, 42);
done();
});
});

it('should close the first database', function(done) {
db1.close(done);
});

it('should close the second database', function(done) {
db2.close(done);
});
});

it('should not be unable to open an inaccessible database', function(done) {
// NOTE: test assumes that the user is not allowed to create new files
// in /usr/bin.
Expand Down