-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdb.test.ts
34 lines (29 loc) · 843 Bytes
/
db.test.ts
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
import {enwikidb} from "./db";
import {expect} from "chai";
import * as sinon from 'sinon';
const testDb = new enwikidb({
host: '127.0.0.1',
port: 3312,
database: 'my_wiki',
user: 'wikiuser',
password: 'wikipassword',
connectionLimit: 5
});
it('destroy pooled connections on inactivity', async function () {
this.timeout(10000);
let conn1, conn2;
let clock = sinon.useFakeTimers();
conn1 = await testDb.getConnection()
conn1.release();
clock.tick(1000)
conn2 = await testDb.getConnection();
conn2.release();
expect(conn1.threadId).to.eq(conn2.threadId)
conn1 = await testDb.getConnection()
conn1.release();
clock.tick(5100);
conn2 = await testDb.getConnection();
conn2.release();
expect(conn1.threadId).to.not.eq(conn2.threadId)
clock.restore();
});