🚀 feat: implement random port selection for BDD tests to prevent conflicts
Some checks failed
CI/CD Pipeline / Build Docker Cache (push) Successful in 9s
CI/CD Pipeline / CI Pipeline (push) Failing after 4m47s

This commit is contained in:
2026-04-10 14:29:04 +02:00
parent 9467fd942c
commit 7b0135c537
3 changed files with 57 additions and 3 deletions

View File

@@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"fmt"
"math/rand"
"net/http"
"os"
"strconv"
@@ -25,12 +26,22 @@ type Server struct {
db *sql.DB
}
func init() {
// Seed the random number generator for random port selection
rand.Seed(time.Now().UnixNano())
}
func NewServer() *Server {
// Get feature-specific port from configuration
feature := os.Getenv("FEATURE")
port := 9191 // Default port
if feature != "" {
// Check for random port mode (better for parallel testing)
if os.Getenv("RANDOM_TEST_PORT") == "true" {
// Generate a random port in the test range (10000-19999)
port = 10000 + rand.Intn(9999)
log.Debug().Int("port", port).Msg("Using random test port")
} else if feature != "" {
// Try to read port from feature-specific config
configPath := fmt.Sprintf("features/%s/%s-test-config.yaml", feature, feature)
if _, statErr := os.Stat(configPath); statErr == nil {