-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1357 from srenatus/sr/issue-1354
postgres: expose database/sql tunables Fixes #1354. I've not had a need for MaxIdleConns and ConnMaxLifetime myself, but it felt weird to only expose of the three settings.
- Loading branch information
Showing
3 changed files
with
88 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// +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{ | ||
Database: getenv("DEX_POSTGRES_DATABASE", "postgres"), | ||
User: getenv("DEX_POSTGRES_USER", "postgres"), | ||
Password: getenv("DEX_POSTGRES_PASSWORD", "postgres"), | ||
Host: host, | ||
SSL: PostgresSSL{ | ||
Mode: sslDisable, // Postgres container doesn't support SSL. | ||
}} | ||
|
||
t.Run("with nothing set, uses defaults", func(t *testing.T) { | ||
cfg := *baseCfg | ||
c, err := cfg.open(logger, cfg.createDataSourceName()) | ||
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 | ||
c, err := cfg.open(logger, cfg.createDataSourceName()) | ||
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) | ||
} | ||
}) | ||
} |