Skip to content

Commit bc5f585

Browse files
committed
verify non-trivial batches of inserts
1 parent 3f2c609 commit bc5f585

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

test/23.statement.iterate.js

+32
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const Database = require('../.');
44
describe('Statement#iterate()', function () {
55
beforeEach(function () {
66
this.db = new Database(util.next());
7+
this.db.pragma("journal_mode = WAL");
78
this.db.prepare('CREATE TABLE entries (a TEXT, b INTEGER, c REAL, d BLOB, e TEXT)').run();
89
this.db.prepare("INSERT INTO entries WITH RECURSIVE temp(a, b, c, d, e) AS (SELECT 'foo', 1, 3.14, x'dddddddd', NULL UNION ALL SELECT a, b + 1, c, d, e FROM temp LIMIT 10) SELECT * FROM temp").run();
910
});
@@ -245,4 +246,35 @@ describe('Statement#iterate()', function () {
245246
this.db.prepare(SQL1).iterate('foo', 1, new (function(){})(), Buffer.alloc(4).fill(0xdd), null)
246247
).to.throw(TypeError);
247248
});
249+
250+
it("should read and write non-trivial numbers of rows", function () {
251+
this.timeout(5000);
252+
const runUntil = Date.now() + 1000
253+
let i = 0;
254+
const r = .141592654
255+
this.db.prepare('CREATE TABLE t (id INTEGER, b TEXT, c REAL)').run();
256+
const stmt = this.db.prepare("INSERT INTO t VALUES (?, ?, ?)");
257+
while(Date.now() < runUntil) {
258+
// Batched transactions of 100 inserts:
259+
this.db.transaction(() => {
260+
for(const start = i; i < start + 100 ; i++) {
261+
expect(stmt.run([i, String(i), i + r])).to.deep.equal({
262+
changes: 1,
263+
lastInsertRowid: i + 1
264+
});
265+
}
266+
})();
267+
}
268+
expect(i).to.be.gte(1000); // < expect ~50K and 200K on reasonable machines
269+
const stmt1 = this.db.prepare("SELECT * FROM t ORDER BY id DESC");
270+
for (const data of stmt1.iterate()) {
271+
i--
272+
expect(data).to.deep.equal({
273+
id: i,
274+
b: String(i),
275+
c: i + r
276+
})
277+
}
278+
expect(i).to.equal(0)
279+
});
248280
});

0 commit comments

Comments
 (0)