diff --git a/e2e/concurrency_test.go b/e2e/concurrency_test.go index 16342c8..4312842 100644 --- a/e2e/concurrency_test.go +++ b/e2e/concurrency_test.go @@ -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, diff --git a/e2e/rqlite_http_test.go b/e2e/rqlite_http_test.go index 0d7df2b..a25f605 100644 --- a/e2e/rqlite_http_test.go +++ b/e2e/rqlite_http_test.go @@ -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, diff --git a/pkg/rqlite/adapter.go b/pkg/rqlite/adapter.go index ec456d3..fa84c7c 100644 --- a/pkg/rqlite/adapter.go +++ b/pkg/rqlite/adapter.go @@ -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,