mirror of
https://github.com/tiennm99/keepalive.git
synced 2026-10-11 03:13:31 +00:00
- Generated service names come only from a URL host, a key=value DSN's host=, or a MySQL tcp() address, so a password in a key=value DSN can no longer end up in the name printed on every log line. - connect_timeout is added only to postgres:// and postgresql:// URLs (parsed, so it never lands after a fragment) or as a key=value token, never glued onto a key=value value containing "://". - Driver parse errors that quote password fragments (mongo escape errors, lib/pq's missing "=" error) are replaced with generic hints. - MongoDB keeps its client only after a successful connect, so a failed connect is not disconnected twice. - Couchbase gets ready_timeout plus 1 minute to connect, so raising ready_timeout takes effect. - Shutdown waits at most 7 seconds, inside Docker's 10-second grace period. - Each adapter declares its config keys; unknown keys anywhere in the file, including under config, log a warning without blocking start.
39 lines
1.7 KiB
Go
39 lines
1.7 KiB
Go
package adapter
|
|
|
|
import "testing"
|
|
|
|
func TestWithDefaultConnectTimeout(t *testing.T) {
|
|
for _, tc := range []struct{ in, want string }{
|
|
{"postgres://u:p@db.example.com/k", "postgres://u:p@db.example.com/k?connect_timeout=30"},
|
|
{"postgresql://u:p@db.example.com/k?sslmode=require", "postgresql://u:p@db.example.com/k?connect_timeout=30&sslmode=require"},
|
|
{"postgres://db.example.com/k?connect_timeout=5", "postgres://db.example.com/k?connect_timeout=5"},
|
|
// The timeout belongs in the query, never after a fragment.
|
|
{"postgres://u:p@db.example.com/k#x", "postgres://u:p@db.example.com/k?connect_timeout=30#x"},
|
|
{"host=db.example.com dbname=k", "host=db.example.com dbname=k connect_timeout=30"},
|
|
{"host=db.example.com connect_timeout=5", "host=db.example.com connect_timeout=5"},
|
|
// "://" inside a key=value value does not make it a URL.
|
|
{"host=h user=u password=a://b dbname=k", "host=h user=u password=a://b dbname=k connect_timeout=30"},
|
|
// Unparseable URLs are left for Connect to report.
|
|
{"postgres://u:p%zz@db.example.com/k", "postgres://u:p%zz@db.example.com/k"},
|
|
} {
|
|
if got := withDefaultConnectTimeout(tc.in); got != tc.want {
|
|
t.Errorf("withDefaultConnectTimeout(%q) = %q, want %q", tc.in, got, tc.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestConfigKeysCoverEveryAdapter(t *testing.T) {
|
|
for name := range Registry {
|
|
if _, ok := ConfigKeys[name]; !ok {
|
|
t.Errorf("adapter %q has no ConfigKeys entry", name)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestCouchbaseConnectTimeoutExceedsReadyTimeout(t *testing.T) {
|
|
a := &couchbaseAdapter{readyTimeout: 2 * 60 * 1e9}
|
|
if a.ConnectTimeout() <= a.readyTimeout {
|
|
t.Fatalf("ConnectTimeout %s does not exceed ready_timeout %s", a.ConnectTimeout(), a.readyTimeout)
|
|
}
|
|
}
|