-
Notifications
You must be signed in to change notification settings - Fork 0
/
pool_test.go
40 lines (27 loc) · 993 Bytes
/
pool_test.go
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
package cpool
import (
"testing"
"github.com/stretchr/testify/assert"
)
var dbName = "mysql"
func TestDefault(t *testing.T) {
con1, errcon1 := Pool.GetConnection(dbName)
assert.NoError(t, errcon1)
assert.Equal(t, 1, len(Pool.InnerPool)) // Pool should contain 1 connection
con2, errcon2 := Pool.GetConnection(dbName)
assert.NoError(t, errcon2)
assert.Equal(t, 2, len(Pool.InnerPool)) // Pool should now contain 2 connections for the same database
// Second connection should return the same as first connection
assert.Equal(t, con1, con2)
_, errquery := con2.Query("select 1")
assert.NoError(t, errquery)
}
func TestCustom(t *testing.T) {
Pool.Init(10, 2, 300)
// Create four connections, this should fill the pool up to maxConnectionsPerDatabase
Pool.GetConnection(dbName)
Pool.GetConnection(dbName)
Pool.GetConnection(dbName)
Pool.GetConnection(dbName)
assert.Equal(t, 2, len(Pool.InnerPool)) // Pool should only contain 2 connections for the same database
}