-
-
Notifications
You must be signed in to change notification settings - Fork 829
/
Copy pathinterrupt.test.js
80 lines (66 loc) · 2.4 KB
/
interrupt.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
var sqlite3 = require('..');
var assert = require('assert');
describe('interrupt', function() {
it('should interrupt queries', function(done) {
var interrupted = false;
var saved = null;
var db = new sqlite3.Database(':memory:', function() {
db.serialize();
var setup = 'create table t (n int);';
for (var i = 0; i < 8; i += 1) {
setup += 'insert into t values (' + i + ');';
}
db.exec(setup, function(err) {
if (err) {
return done(err);
}
var query = 'select last.n ' +
'from t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t as last';
db.each(query, function(err) {
if (err) {
saved = err;
} else if (!interrupted) {
interrupted = true;
db.interrupt();
}
});
db.close(function() {
if (saved) {
assert.equal(saved.message, 'SQLITE_INTERRUPT: interrupted');
assert.equal(saved.errno, sqlite3.INTERRUPT);
assert.equal(saved.code, 'SQLITE_INTERRUPT');
done();
} else {
done(new Error('Completed query without error, but expected error'));
}
});
});
});
});
it('should throw if interrupt is called before open', function(done) {
var db = new sqlite3.Database(':memory:');
assert.throws(function() {
db.interrupt();
}, (/Database is not open/));
db.close();
done();
});
it('should throw if interrupt is called after close', function(done) {
var db = new sqlite3.Database(':memory:');
db.close(function() {
assert.throws(function() {
db.interrupt();
}, (/Database is not open/));
done();
});
});
it('should throw if interrupt is called during close', function(done) {
var db = new sqlite3.Database(':memory:', function() {
db.close();
assert.throws(function() {
db.interrupt();
}, (/Database is closing/));
done();
});
});
});