Reverts PR #26 (BDD_SCHEMA_ISOLATION caused empty schemas with no tables, 500 errors). Adds sequential package execution (-p 1) + cache flush AfterScenario. AuthBDD goes from 0/5 PASS to 5/5 PASS deterministically. Parallel BDD deferred as architectural follow-up (requires per-schema migrations + dedicated connection pools). Co-authored-by: Gabriel Radureau <arcodange@gmail.com> Co-committed-by: Gabriel Radureau <arcodange@gmail.com>
This commit was merged in pull request #28.
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"dance-lessons-coach/pkg/cache"
|
||||
"dance-lessons-coach/pkg/config"
|
||||
"dance-lessons-coach/pkg/server"
|
||||
"dance-lessons-coach/pkg/user"
|
||||
@@ -48,6 +49,7 @@ type Server struct {
|
||||
baseURL string
|
||||
db *sql.DB
|
||||
authService user.AuthService // Reference to auth service for cleanup
|
||||
cacheService cache.Service // Reference to cache service for cleanup
|
||||
schemaMutex sync.Mutex // Protects schema operations
|
||||
currentSchema string // Current schema being used
|
||||
originalSearchPath string // Original search_path to restore
|
||||
@@ -153,6 +155,9 @@ func (s *Server) Start() error {
|
||||
// Store auth service for cleanup
|
||||
s.authService = realServer.GetAuthService()
|
||||
|
||||
// Store cache service for cleanup
|
||||
s.cacheService = realServer.GetCacheService()
|
||||
|
||||
// Initialize database connection for cleanup
|
||||
if err := s.initDBConnection(); err != nil {
|
||||
return fmt.Errorf("failed to initialize database connection: %w", err)
|
||||
@@ -409,6 +414,23 @@ func (s *Server) ResetJWTSecrets() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// FlushCache clears all cached data to prevent cache pollution between scenarios
|
||||
// This prevents cached responses from affecting subsequent test scenarios
|
||||
func (s *Server) FlushCache() error {
|
||||
if s.cacheService == nil {
|
||||
if isCleanupLoggingEnabled() {
|
||||
log.Info().Msg("CLEANUP: No cache service available, skipping cache flush")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
s.cacheService.Flush()
|
||||
if isCleanupLoggingEnabled() {
|
||||
log.Info().Msg("CLEANUP: Cache flushed successfully")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CleanupDatabase deletes all test data from all tables
|
||||
// This uses raw SQL to avoid dependency on repositories and handles foreign keys properly
|
||||
// Uses SET CONSTRAINTS ALL DEFERRED to temporarily disable foreign key checks
|
||||
@@ -555,7 +577,7 @@ func (s *Server) SetupScenarioSchema(feature, scenario string) error {
|
||||
return fmt.Errorf("failed to create schema %s: %w", schemaName, err)
|
||||
}
|
||||
|
||||
// Set search path to use the new schema
|
||||
// Set search path to use the new schema (testserver's own connection)
|
||||
searchPathSQL := fmt.Sprintf("SET search_path = %s, %s", schemaName, s.originalSearchPath)
|
||||
if _, err := s.db.Exec(searchPathSQL); err != nil {
|
||||
return fmt.Errorf("failed to set search_path: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user