some more fixes

This commit is contained in:
anonpenguin23 2026-01-22 18:23:37 +02:00
parent 1c2bde2d81
commit 5547c8ccb5
3 changed files with 77 additions and 4 deletions

View File

@ -232,6 +232,17 @@ func TestRQLite_ConcurrentInserts(t *testing.T) {
defer cancel()
table := GenerateTableName()
// Cleanup table after test
defer func() {
dropReq := &HTTPRequest{
Method: http.MethodPost,
URL: GetGatewayURL() + "/v1/rqlite/drop-table",
Body: map[string]interface{}{"table": table},
}
dropReq.Do(context.Background())
}()
schema := fmt.Sprintf(
"CREATE TABLE IF NOT EXISTS %s (id INTEGER PRIMARY KEY AUTOINCREMENT, value INTEGER)",
table,
@ -320,6 +331,17 @@ func TestRQLite_LargeBatchTransaction(t *testing.T) {
defer cancel()
table := GenerateTableName()
// Cleanup table after test
defer func() {
dropReq := &HTTPRequest{
Method: http.MethodPost,
URL: GetGatewayURL() + "/v1/rqlite/drop-table",
Body: map[string]interface{}{"table": table},
}
dropReq.Do(context.Background())
}()
schema := fmt.Sprintf(
"CREATE TABLE IF NOT EXISTS %s (id INTEGER PRIMARY KEY AUTOINCREMENT, value TEXT)",
table,

View File

@ -17,6 +17,17 @@ func TestRQLite_CreateTable(t *testing.T) {
defer cancel()
table := GenerateTableName()
// Cleanup table after test
defer func() {
dropReq := &HTTPRequest{
Method: http.MethodPost,
URL: GetGatewayURL() + "/v1/rqlite/drop-table",
Body: map[string]interface{}{"table": table},
}
dropReq.Do(context.Background())
}()
schema := fmt.Sprintf(
"CREATE TABLE IF NOT EXISTS %s (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, created_at DATETIME DEFAULT CURRENT_TIMESTAMP)",
table,
@ -47,6 +58,17 @@ func TestRQLite_InsertQuery(t *testing.T) {
defer cancel()
table := GenerateTableName()
// Cleanup table after test
defer func() {
dropReq := &HTTPRequest{
Method: http.MethodPost,
URL: GetGatewayURL() + "/v1/rqlite/drop-table",
Body: map[string]interface{}{"table": table},
}
dropReq.Do(context.Background())
}()
schema := fmt.Sprintf(
"CREATE TABLE IF NOT EXISTS %s (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)",
table,
@ -245,6 +267,17 @@ func TestRQLite_LargeTransaction(t *testing.T) {
defer cancel()
table := GenerateTableName()
// Cleanup table after test
defer func() {
dropReq := &HTTPRequest{
Method: http.MethodPost,
URL: GetGatewayURL() + "/v1/rqlite/drop-table",
Body: map[string]interface{}{"table": table},
}
dropReq.Do(context.Background())
}()
schema := fmt.Sprintf(
"CREATE TABLE IF NOT EXISTS %s (id INTEGER PRIMARY KEY AUTOINCREMENT, value INTEGER)",
table,
@ -320,6 +353,23 @@ func TestRQLite_ForeignKeyMigration(t *testing.T) {
orgsTable := GenerateTableName()
usersTable := GenerateTableName()
// Cleanup tables after test
defer func() {
dropUsersReq := &HTTPRequest{
Method: http.MethodPost,
URL: GetGatewayURL() + "/v1/rqlite/drop-table",
Body: map[string]interface{}{"table": usersTable},
}
dropUsersReq.Do(context.Background())
dropOrgsReq := &HTTPRequest{
Method: http.MethodPost,
URL: GetGatewayURL() + "/v1/rqlite/drop-table",
Body: map[string]interface{}{"table": orgsTable},
}
dropOrgsReq.Do(context.Background())
}()
// Create base tables
createOrgsReq := &HTTPRequest{
Method: http.MethodPost,

View File

@ -23,10 +23,11 @@ func NewRQLiteAdapter(manager *RQLiteManager) (*RQLiteAdapter, error) {
}
// Configure connection pool with proper timeouts and limits
db.SetMaxOpenConns(25) // Maximum number of open connections
db.SetMaxIdleConns(5) // Maximum number of idle connections
db.SetConnMaxLifetime(5 * time.Minute) // Maximum lifetime of a connection
db.SetConnMaxIdleTime(2 * time.Minute) // Maximum idle time before closing
// Optimized for concurrent operations and fast bad connection eviction
db.SetMaxOpenConns(100) // Allow more concurrent connections to prevent queuing
db.SetMaxIdleConns(10) // Keep fewer idle connections to force fresh reconnects
db.SetConnMaxLifetime(30 * time.Second) // Short lifetime ensures bad connections die quickly
db.SetConnMaxIdleTime(10 * time.Second) // Kill idle connections quickly to prevent stale state
return &RQLiteAdapter{
manager: manager,