fix: Refuse to start if max_open_connections is below 5 (#2097)
* server refuses to start if max_open_connections is below 5 * suggested changes - Update internal/db/db.go Co-authored-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com> Co-authored-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
This commit is contained in:
1 parent
0425384b49
commit
3521c21cd5
2 files changed
+13
No files matched your search
@@ -95,6 +95,9 @@ func Open(dbType DbType, connectionUrl string, opt ...Option) (*DB, error) {
|
||||
wrappedOpts = append(wrappedOpts, dbw.WithLogger(opts.withGormFormatter))
|
||||
}
|
||||
if opts.withMaxOpenConnections > 0 {
|
||||
if opts.withMaxOpenConnections < 5 {
|
||||
return nil, fmt.Errorf("max_open_connections cannot be below 5")
|
||||
}
|
||||
wrappedOpts = append(wrappedOpts, dbw.WithMaxOpenConnections(opts.withMaxOpenConnections))
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ func TestOpen(t *testing.T) {
|
||||
type args struct {
|
||||
dbType DbType
|
||||
connectionUrl string
|
||||
opt []Option
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
@@ -44,6 +45,15 @@ func TestOpen(t *testing.T) {
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "invalid - max_open_connections set to 3",
|
||||
args: args{
|
||||
dbType: Postgres,
|
||||
connectionUrl: "",
|
||||
opt: []Option{WithMaxOpenConnections(3)},
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
||||
Reference in new issue
Block a user