Files
azerothcore-wotlk/apps/startup-scripts/test/test_startup_scripts.bats
Yehonal 9a837ee1f7 fix(bash): Improve session management and GDB handling in service scripts (#22418)
This pull request introduces several enhancements and fixes to the startup scripts for AzerothCore, focusing on improving service management, interactive mode handling, and script execution. The most important changes include adding support for non-interactive mode, enhancing systemd integration, and refactoring the starter script to handle binary paths and files more robustly.

### Enhancements to Service Management:
* **Non-Interactive Mode:** Added `AC_DISABLE_INTERACTIVE` environment variable to disable interactive prompts for services running without session managers (e.g., systemd/pm2). This prevents hanging during non-interactive execution. (`apps/startup-scripts/src/run-engine`, `apps/startup-scripts/src/service-manager.sh`) [[1]](diffhunk://#diff-1792abab64da981c71221890876ce832aab405f670f320f75b73b8788b1a4174R336-R349) [[2]](diffhunk://#diff-31edfed7f73d0647a5fc96ce74c249e025e884cd1fe06621cb78eb4a381464f9R724-R727)
* **Enhanced Systemd Integration:** Services using session managers like tmux/screen are automatically configured with `Type=forking` and appropriate `ExecStop` commands to terminate sessions gracefully. (`apps/startup-scripts/src/service-manager.sh`) [[1]](diffhunk://#diff-31edfed7f73d0647a5fc96ce74c249e025e884cd1fe06621cb78eb4a381464f9R401-R425) [[2]](diffhunk://#diff-31edfed7f73d0647a5fc96ce74c249e025e884cd1fe06621cb78eb4a381464f9R567-R578)

### Improvements to Script Execution:
* **Starter Script Refactor:** Updated the starter script to require both binary path and file name as parameters, improving clarity and error handling. (`apps/startup-scripts/src/starter`) [[1]](diffhunk://#diff-e92f132163ec1e49dc625eac9107c6841ae14e416aa35adec787dca5031dc631L6-R16) [[2]](diffhunk://#diff-e92f132163ec1e49dc625eac9107c6841ae14e416aa35adec787dca5031dc631L26-R44)
* **Temporary GDB File Management:** Enhanced handling of temporary GDB configuration files, ensuring proper cleanup after execution. (`apps/startup-scripts/src/starter`) [[1]](diffhunk://#diff-e92f132163ec1e49dc625eac9107c6841ae14e416aa35adec787dca5031dc631R68-R70) [[2]](diffhunk://#diff-e92f132163ec1e49dc625eac9107c6841ae14e416aa35adec787dca5031dc631R92-R141)

### Updates to Tests:
* **Test Adjustments:** Modified test cases to reflect the updated starter script parameter requirements and error messages. (`apps/startup-scripts/test/test_startup_scripts.bats`) [[1]](diffhunk://#diff-febbaeb294e50bdba0511ecad5d44b0c3f11ae92c79dd19dbd5f61d41a654278L26-R26) [[2]](diffhunk://#diff-febbaeb294e50bdba0511ecad5d44b0c3f11ae92c79dd19dbd5f61d41a654278L41-R49)
2025-07-05 23:02:04 +02:00

157 lines
5.6 KiB
Bash

#!/usr/bin/env bats
# AzerothCore Startup Scripts Test Suite
# This script tests the basic functionality of the startup scripts using the unified test framework
# Load the AzerothCore test framework
load '../../test-framework/bats_libs/acore-support'
load '../../test-framework/bats_libs/acore-assert'
# Setup that runs before each test
setup() {
startup_scripts_setup
export SCRIPT_DIR="$(cd "$(dirname "$BATS_TEST_FILENAME")/../src" && pwd)"
}
# Cleanup that runs after each test
teardown() {
acore_test_teardown
}
# ===== STARTER SCRIPT TESTS =====
@test "starter: should fail with missing parameters" {
run timeout 3s "$SCRIPT_DIR/starter" '' ''
[ "$status" -ne 0 ]
[[ "$output" =~ "Error: Binary path and file are required" ]]
}
@test "starter: should start with valid binary" {
cd "$TEST_DIR"
run timeout 5s "$SCRIPT_DIR/starter" "$TEST_DIR/bin" "test-server" "" "$TEST_DIR/test-server.conf" "" "" 0
debug_on_failure
# The starter might have issues with the script command, so we check for specific behavior
# Either it should succeed or show a specific error we can work with
[[ "$output" =~ "Test server starting" ]] || [[ "$output" =~ "script:" ]] || [[ "$status" -eq 124 ]]
}
@test "starter: should validate binary path exists" {
run "$SCRIPT_DIR/starter" "/nonexistent/path" "test-server"
[ "$status" -ne 0 ]
[[ "$output" =~ "Binary '/nonexistent/path/test-server' not found" ]]
}
@test "starter: should detect PM2 environment properly" {
cd "$TEST_DIR"
# Test with AC_LAUNCHED_BY_PM2=1 (should not use script command)
AC_LAUNCHED_BY_PM2=1 run timeout 5s "$SCRIPT_DIR/starter" "$TEST_DIR/bin" "test-server" "" "$TEST_DIR/test-server.conf" "" "" 0
debug_on_failure
# Should start without using script command
[[ "$output" =~ "Test server starting" ]]
}
# ===== SIMPLE RESTARTER TESTS =====
@test "simple-restarter: should fail with missing parameters" {
run timeout 3s "$SCRIPT_DIR/simple-restarter" '' ''
[ "$status" -ne 0 ]
[[ "$output" =~ "Error: Binary path and file are required" ]]
}
@test "simple-restarter: should fail with missing binary" {
run timeout 3s "$SCRIPT_DIR/simple-restarter" "$TEST_DIR/bin" 'nonexistent'
[ "$status" -ne 0 ]
[[ "$output" =~ "not found" ]] || [[ "$output" =~ "terminated with exit code" ]]
}
@test "simple-restarter: should detect starter script" {
# Test that it finds the starter script
run timeout 1s "$SCRIPT_DIR/simple-restarter" '' ''
# Should not fail because starter script is missing
[[ ! "$output" =~ "starter script not found" ]]
}
# ===== RUN-ENGINE TESTS =====
@test "run-engine: should show help" {
run "$SCRIPT_DIR/run-engine" help
[ "$status" -eq 0 ]
[[ "$output" =~ "AzerothCore Run Engine" ]]
}
@test "run-engine: should validate parameters for start command" {
run "$SCRIPT_DIR/run-engine" start
[ "$status" -ne 0 ]
[[ "$output" =~ "Missing required arguments" ]]
}
@test "run-engine: should detect binary with full path" {
run timeout 5s "$SCRIPT_DIR/run-engine" start "$TEST_DIR/bin/test-server" --server-config "$TEST_DIR/test-server.conf"
debug_on_failure
[[ "$output" =~ "Starting server: test-server" ]] || [[ "$status" -eq 124 ]]
}
@test "run-engine: should detect binary in current directory" {
cd "$TEST_DIR/bin"
run timeout 5s "$SCRIPT_DIR/run-engine" start test-server --server-config "$TEST_DIR/test-server.conf"
debug_on_failure
[[ "$output" =~ "Binary found in current directory" ]] || [[ "$output" =~ "Starting server: test-server" ]] || [[ "$status" -eq 124 ]]
}
@test "run-engine: should support restart mode" {
run timeout 5s "$SCRIPT_DIR/run-engine" restart "$TEST_DIR/bin/test-server" --server-config "$TEST_DIR/test-server.conf"
debug_on_failure
[[ "$output" =~ "Starting server: test-server" ]] || [[ "$status" -eq 124 ]]
}
# ===== SERVICE MANAGER TESTS =====
@test "service-manager: should show help" {
run "$SCRIPT_DIR/service-manager.sh" help
[ "$status" -eq 0 ]
[[ "$output" =~ "AzerothCore Service Setup" ]]
}
@test "service-manager: should validate create command parameters" {
run "$SCRIPT_DIR/service-manager.sh" create
[ "$status" -ne 0 ]
[[ "$output" =~ "Missing required arguments" ]] || [[ "$output" =~ "Error:" ]]
}
# ===== EXAMPLE SCRIPTS TESTS =====
@test "examples: restarter-world should show configuration error" {
run "$SCRIPT_DIR/examples/restarter-world.sh"
[[ "$output" =~ "Configuration file not found" ]]
}
@test "examples: starter-auth should show configuration error" {
run "$SCRIPT_DIR/examples/starter-auth.sh"
[[ "$output" =~ "Configuration file not found" ]]
}
@test "examples: restarter-auth should show configuration error" {
run "$SCRIPT_DIR/examples/restarter-auth.sh"
[[ "$output" =~ "Configuration file not found" ]]
}
@test "examples: restarter-world should show alternative suggestions" {
run "$SCRIPT_DIR/examples/restarter-world.sh"
[[ "$output" =~ "Alternative: Start with binary path directly" ]]
}
# ===== INTEGRATION TESTS =====
@test "integration: starter and simple-restarter work together" {
# Test that simple-restarter can use starter
run timeout 5s "$SCRIPT_DIR/simple-restarter" "$TEST_DIR/bin" "test-server"
# Should start and then restart at least once
[[ "$output" =~ "terminated with exit code" ]] || [[ "$status" -eq 124 ]]
}
@test "integration: run-engine can handle missing config gracefully" {
run timeout 3s "$SCRIPT_DIR/run-engine" start "$TEST_DIR/bin/test-server"
# Should either work or give a meaningful error
[[ "$status" -eq 124 ]] || [[ "$status" -eq 0 ]] || [[ "$output" =~ "config" ]]
}