-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsocket.js
71 lines (62 loc) · 1.68 KB
/
socket.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
const test = require('ava');
const Socket = require('../src/socket');
const defaultConfig = {
database: 'think_db'
};
test.serial('release', async t => {
const socket = Socket.getInstance(defaultConfig);
const pool = await socket.pool;
t.is(!!pool, true);
const connection = await socket.getConnection();
t.is(!!connection, true);
await socket.release(connection);
});
test.serial('close', async t => {
const socket = Socket.getInstance(defaultConfig);
const pool = await socket.pool;
t.is(!!pool, true);
const connection = await socket.getConnection();
t.is(!!connection, true);
const ret = await socket.close(connection);
});
test.serial('default value of pool size is 5', async t => {
const socket = Socket.getInstance(defaultConfig);
const pool = await socket.pool;
t.is(pool.max, 5);
});
const connectionLimitConfig = {
database: 'think_db',
connectionLimit: 10,
options: {
maxPoolSize: 15,
poolSize: 20
}
};
test.serial('pool size is config.connectionLimitConfig', async t => {
const socket = Socket.getInstance(connectionLimitConfig);
const pool = await socket.pool;
t.is(pool.max, 10);
});
const maxPoolSizeConfig = {
database: 'think_db',
options: {
maxPoolSize: 15
}
};
test.serial('pool size is config.options.maxPoolSize', async t => {
const socket = Socket.getInstance(maxPoolSizeConfig);
const pool = await socket.pool;
t.is(pool.max, 15);
});
const poolSizeConfig = {
database: 'think_db',
options: {
maxPoolSize: 15,
poolSize: 20
}
};
test.serial('pool size is config.options.poolSize', async t => {
const socket = Socket.getInstance(poolSizeConfig);
const pool = await socket.pool;
t.is(pool.max, 20);
});