2018-11-21 16:05:25 +05:30
|
|
|
// +build go1.11
|
|
|
|
|
|
|
|
package sql
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPostgresTunables(t *testing.T) {
|
|
|
|
host := os.Getenv(testPostgresEnv)
|
|
|
|
if host == "" {
|
|
|
|
t.Skipf("test environment variable %q not set, skipping", testPostgresEnv)
|
|
|
|
}
|
|
|
|
baseCfg := &Postgres{
|
2019-07-12 19:59:46 +05:30
|
|
|
NetworkDB: NetworkDB{
|
|
|
|
Database: getenv("DEX_POSTGRES_DATABASE", "postgres"),
|
|
|
|
User: getenv("DEX_POSTGRES_USER", "postgres"),
|
|
|
|
Password: getenv("DEX_POSTGRES_PASSWORD", "postgres"),
|
|
|
|
Host: host,
|
|
|
|
},
|
|
|
|
SSL: SSL{
|
|
|
|
Mode: pgSSLDisable, // Postgres container doesn't support SSL.
|
2018-11-21 16:05:25 +05:30
|
|
|
}}
|
|
|
|
|
|
|
|
t.Run("with nothing set, uses defaults", func(t *testing.T) {
|
|
|
|
cfg := *baseCfg
|
2019-07-12 19:59:46 +05:30
|
|
|
c, err := cfg.open(logger)
|
2018-11-21 16:05:25 +05:30
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error opening connector: %s", err.Error())
|
|
|
|
}
|
|
|
|
defer c.db.Close()
|
|
|
|
if m := c.db.Stats().MaxOpenConnections; m != 5 {
|
|
|
|
t.Errorf("expected MaxOpenConnections to have its default (5), got %d", m)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("with something set, uses that", func(t *testing.T) {
|
|
|
|
cfg := *baseCfg
|
|
|
|
cfg.MaxOpenConns = 101
|
2019-07-12 19:59:46 +05:30
|
|
|
c, err := cfg.open(logger)
|
2018-11-21 16:05:25 +05:30
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error opening connector: %s", err.Error())
|
|
|
|
}
|
|
|
|
defer c.db.Close()
|
|
|
|
if m := c.db.Stats().MaxOpenConnections; m != 101 {
|
|
|
|
t.Errorf("expected MaxOpenConnections to be set to 101, got %d", m)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|