|
62 | 62 | metadataTable string |
63 | 63 | logger log.Logger |
64 | 64 | rootDatabase string |
| 65 | + dropTimeout time.Duration |
65 | 66 | } |
66 | 67 |
|
67 | 68 | OnInstanceFactoryOpt func(*onInstanceFactoryOptions) |
@@ -102,6 +103,13 @@ func WithRootDatabase(db string) OnInstanceFactoryOpt { |
102 | 103 | } |
103 | 104 | } |
104 | 105 |
|
| 106 | +// WithDropTimeout sets the timeout used when dropping database |
| 107 | +func WithDropTimeout(d time.Duration) OnInstanceFactoryOpt { |
| 108 | + return func(opts *onInstanceFactoryOptions) { |
| 109 | + opts.dropTimeout = d |
| 110 | + } |
| 111 | +} |
| 112 | + |
105 | 113 | type ( |
106 | 114 | CreateConnPoolForDbFn func(ctx context.Context, dbName string) (*sql.DB, error) |
107 | 115 |
|
@@ -129,6 +137,7 @@ func NewOnInstanceFactory(ctx context.Context, createConnPoolForDb CreateConnPoo |
129 | 137 | dbPrefix: DefaultOnInstanceDbPrefix, |
130 | 138 | metadataSchema: DefaultOnInstanceMetadataSchema, |
131 | 139 | metadataTable: DefaultOnInstanceMetadataTable, |
| 140 | + dropTimeout: DefaultStatementTimeout, |
132 | 141 | rootDatabase: "postgres", |
133 | 142 | logger: log.SimpleLogger(), |
134 | 143 | } |
@@ -259,6 +268,10 @@ func (o *onInstanceFactory) dropTempDatabase(ctx context.Context, dbName string) |
259 | 268 | } |
260 | 269 | defer rootConn.Close() |
261 | 270 |
|
| 271 | + if _, err := rootConn.ExecContext(ctx, fmt.Sprintf("SET SESSION statement_timeout = %d;", o.options.dropTimeout.Milliseconds())); err != nil { |
| 272 | + return fmt.Errorf("setting statement timeout: %w", err) |
| 273 | + } |
| 274 | + |
262 | 275 | _, err = rootConn.ExecContext(ctx, fmt.Sprintf("DROP DATABASE %s;", dbName)) |
263 | 276 | if err != nil { |
264 | 277 | return fmt.Errorf("dropping temporary database: %w", err) |
|
0 commit comments