Revert DisableStartupCheck changes for select drivers

This commit is contained in:
Juan Calderon-Perez
2025-10-13 13:13:36 -04:00
parent 9b205cb931
commit 92da8e1d90
16 changed files with 209 additions and 102 deletions

View File

@@ -73,6 +73,11 @@ type Config struct {
//
// Optional. Default is false
Reset bool
// DisableStartupCheck skips the initial connection validation during New.
//
// Optional. Default is false
DisableStartupCheck bool
}
```
@@ -80,5 +85,6 @@ type Config struct {
```go
var ConfigDefault = Config{
Servers: "127.0.0.1:11211",
DisableStartupCheck: false,
}
```

View File

@@ -15,6 +15,11 @@ type Config struct {
// Optional. Default is false
Reset bool
// DisableStartupCheck skips the initial connection validation during New.
//
// Optional. Default is false
DisableStartupCheck bool
// The socket read/write timeout.
//
// Optional. Default is 100 * time.Millisecond
@@ -34,6 +39,7 @@ var ConfigDefault = Config{
Servers: "127.0.0.1:11211",
timeout: 100 * time.Millisecond,
maxIdleConns: 2,
DisableStartupCheck: false,
}
// Helper function to set default values

View File

@@ -30,6 +30,7 @@ func New(config ...Config) *Storage {
db.Timeout = cfg.timeout
db.MaxIdleConns = cfg.maxIdleConns
if !cfg.DisableStartupCheck {
// Ping database to ensure a connection has been made
if err := db.Ping(); err != nil {
panic(err)
@@ -40,6 +41,7 @@ func New(config ...Config) *Storage {
panic(err)
}
}
}
// Create storage
store := &Storage{

View File

@@ -178,6 +178,16 @@ func Test_Memcache_Reset(t *testing.T) {
require.Zero(t, len(result))
}
func Test_Memcache_New_DisableStartupCheck(t *testing.T) {
require.NotPanics(t, func() {
store := New(Config{
Servers: "127.0.0.1:11210",
DisableStartupCheck: true,
})
require.NotNil(t, store)
})
}
func Test_Memcache_Close(t *testing.T) {
testStore := newTestStore(t)
require.Nil(t, testStore.Close())

View File

@@ -127,6 +127,11 @@ type Config struct {
// Optional. Default is false
Reset bool
// DisableStartupCheck skips the initial connection validation during New.
//
// Optional. Default is false
DisableStartupCheck bool
// Time before deleting expired keys
//
// Optional. Default is 10 * time.Second
@@ -143,6 +148,7 @@ var ConfigDefault = Config{
Database: "fiber",
Table: "fiber_storage",
Reset: false,
DisableStartupCheck: false,
GCInterval: 10 * time.Second,
}
```

View File

@@ -53,6 +53,11 @@ type Config struct {
// Optional. Default is false
Reset bool
// DisableStartupCheck skips the initial connection validation during New.
//
// Optional. Default is false
DisableStartupCheck bool
// Time before deleting expired keys
//
// Optional. Default is 10 * time.Second
@@ -76,6 +81,7 @@ var ConfigDefault = Config{
Database: "fiber",
Table: "fiber_storage",
Reset: false,
DisableStartupCheck: false,
GCInterval: 10 * time.Second,
maxOpenConns: 100,
maxIdleConns: 100,

View File

@@ -63,6 +63,7 @@ func New(config ...Config) *Storage {
db.SetConnMaxLifetime(cfg.connMaxLifetime)
}
if !cfg.DisableStartupCheck {
// Ping database to ensure a connection has been made
if err := db.Ping(); err != nil {
panic(err)
@@ -85,6 +86,7 @@ func New(config ...Config) *Storage {
panic(err)
}
}
}
// Create storage
store := &Storage{
@@ -98,7 +100,9 @@ func New(config ...Config) *Storage {
sqlGC: fmt.Sprintf("DELETE FROM %s WHERE e <= ? AND e != 0", cfg.Table),
}
if !cfg.DisableStartupCheck {
store.checkSchema(cfg.Table)
}
// Start garbage collector
go store.gcTicker()

View File

@@ -108,6 +108,18 @@ func Test_MYSQL_New(t *testing.T) {
defer newConfigStore.Close()
}
func Test_MYSQL_New_DisableStartupCheck(t *testing.T) {
require.NotPanics(t, func() {
store := New(Config{
Host: "127.0.0.1",
Port: 3308,
DisableStartupCheck: true,
})
require.NotNil(t, store)
defer store.Close()
})
}
func Test_MYSQL_GC(t *testing.T) {
testVal := []byte("doe")

View File

@@ -117,6 +117,11 @@ type Config struct {
// Optional. Default is false
Reset bool
// DisableStartupCheck skips the initial connection validation during New.
//
// Optional. Default is false
DisableStartupCheck bool
// Time before deleting expired keys
//
// Optional. Default is 10 * time.Second
@@ -135,6 +140,7 @@ var ConfigDefault = Config{
Table: "fiber_storage",
SSLMode: "disable",
Reset: false,
DisableStartupCheck: false,
GCInterval: 10 * time.Second,
}
```

View File

@@ -61,6 +61,11 @@ type Config struct {
// Optional. Default is false
Reset bool
// DisableStartupCheck skips the initial connection validation during New.
//
// Optional. Default is false
DisableStartupCheck bool
// Time before deleting expired keys
//
// Optional. Default is 10 * time.Second
@@ -76,6 +81,7 @@ var ConfigDefault = Config{
Table: "fiber_storage",
SSLMode: "disable",
Reset: false,
DisableStartupCheck: false,
GCInterval: 10 * time.Second,
}

View File

@@ -68,6 +68,7 @@ func New(config ...Config) *Storage {
}
}
if !cfg.DisableStartupCheck {
// Ping database
if err := db.Ping(context.Background()); err != nil {
panic(err)
@@ -108,6 +109,7 @@ func New(config ...Config) *Storage {
}
}
}
}
// Create storage
store := &Storage{
@@ -121,7 +123,9 @@ func New(config ...Config) *Storage {
sqlGC: fmt.Sprintf("DELETE FROM %s WHERE e <= $1 AND e != 0", cfg.Table),
}
if !cfg.DisableStartupCheck {
store.checkSchema(cfg.Table)
}
// Start garbage collector
go store.gcTicker()

View File

@@ -202,6 +202,18 @@ func TestNoCreateUser(t *testing.T) {
})
}
func Test_Postgres_New_DisableStartupCheck(t *testing.T) {
require.NotPanics(t, func() {
store := New(Config{
Host: "127.0.0.1",
Port: 65432,
DisableStartupCheck: true,
})
require.NotNil(t, store)
defer store.Close()
})
}
func Test_Should_Panic_On_Wrong_Schema(t *testing.T) {
testStore := newTestStore(t)
defer testStore.Close()

View File

@@ -180,6 +180,11 @@ type Config struct {
// Optional. Default is false
Reset bool
// DisableStartupCheck skips the initial connection validation during New.
//
// Optional. Default is false
DisableStartupCheck bool
// TLS Config to use. When set TLS will be negotiated.
//
// Optional. Default is nil
@@ -208,6 +213,7 @@ var ConfigDefault = Config{
URL: "",
Database: 0,
Reset: false,
DisableStartupCheck: false,
TLSConfig: nil,
PoolSize: 10 * runtime.GOMAXPROCS(0),
Addrs: []string{},

View File

@@ -68,6 +68,11 @@ type Config struct {
// Optional. Default is false
Reset bool
// DisableStartupCheck skips the initial connection validation during New.
//
// Optional. Default is false
DisableStartupCheck bool
// TLS Config to use. When set TLS will be negotiated.
//
// Optional. Default is nil
@@ -94,6 +99,7 @@ var ConfigDefault = Config{
URL: "",
Database: 0,
Reset: false,
DisableStartupCheck: false,
TLSConfig: nil,
PoolSize: 10 * runtime.GOMAXPROCS(0),
Addrs: []string{},

View File

@@ -65,6 +65,7 @@ func New(config ...Config) *Storage {
IsClusterMode: cfg.IsClusterMode,
})
if !cfg.DisableStartupCheck {
// Test connection
if err := db.Ping(context.Background()).Err(); err != nil {
panic(err)
@@ -76,6 +77,7 @@ func New(config ...Config) *Storage {
panic(err)
}
}
}
// Create new store
return &Storage{

View File

@@ -198,6 +198,19 @@ func Test_Redis_Delete(t *testing.T) {
require.Nil(t, keys)
}
func Test_Redis_New_DisableStartupCheck(t *testing.T) {
require.NotPanics(t, func() {
store := New(Config{
Host: "127.0.0.1",
Port: 6390,
Addrs: []string{"127.0.0.1:6390"},
DisableStartupCheck: true,
})
require.NotNil(t, store)
_ = store.Close()
})
}
func Test_Redis_DeleteWithContext(t *testing.T) {
var (
key = "john"