🚀 feat: implement random port selection for BDD tests to prevent conflicts
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user