test(backend): add RPT log output to server stub

- Stub now parses -profiles= arg and writes RPT entries to
  profilesDir/arma3server_x64_<timestamp>.rpt
- RPT includes header (exe timestamp, computer name, OS) and periodic
  entries (MissionEditor, World, Server: Player) on each heartbeat cycle
- New test TestStart_StubWritesRPTLog verifies RPT file creation and
  content via the profiles directory
This commit is contained in:
MrFastwind
2026-07-23 21:20:53 +02:00
parent 04882b3c80
commit 930b6cbca6
2 changed files with 105 additions and 0 deletions
@@ -773,3 +773,77 @@ func TestStart_StubAutoExit(t *testing.T) {
t.Error("IsRunning() should be false after stub auto-exited (timeout 2s)")
}
}
func TestStart_StubWritesRPTLog(t *testing.T) {
dir := t.TempDir()
serverfileDir := filepath.Join(dir, "server")
profilesDir := filepath.Join(dir, "profiles")
modsDir := filepath.Join(dir, "mods")
cfgDir := filepath.Join(dir, "cfg")
os.MkdirAll(serverfileDir, 0755)
stubSrc, _ := os.ReadFile("testdata/arma3server_x64")
os.WriteFile(filepath.Join(serverfileDir, "arma3server_x64"), stubSrc, 0755)
sm := NewSettingsManager(dir)
mm := NewModlistManager(filepath.Join(dir, "modlists"))
cm := NewConfigManager(cfgDir)
streamer := NewLogStreamer()
pm := NewProcessManager(serverfileDir, modsDir, cfgDir, profilesDir, sm, mm, cm, streamer)
s, _ := sm.Load()
s.ServerParameters = "-t 7"
sm.Save(s)
if err := pm.Start(); err != nil {
t.Fatalf("Start() error = %v", err)
}
// Wait for the stub to write RPT entries (heartbeat at ~5s)
deadline := time.Now().Add(8 * time.Second)
var rptPath string
for time.Now().Before(deadline) {
matches, _ := filepath.Glob(filepath.Join(profilesDir, "arma3server_x64_*.rpt"))
if len(matches) > 0 {
rptPath = matches[0]
break
}
time.Sleep(200 * time.Millisecond)
}
if rptPath == "" {
pm.Stop()
t.Fatal("RPT file not found in profiles dir")
}
// Wait for heartbeat entries to be written (heartbeat at ~5s)
deadline2 := time.Now().Add(6 * time.Second)
for time.Now().Before(deadline2) {
data, _ := os.ReadFile(rptPath)
if strings.Contains(string(data), "MissionEditor") {
break
}
time.Sleep(500 * time.Millisecond)
}
data, err := os.ReadFile(rptPath)
if err != nil {
pm.Stop()
t.Fatalf("ReadFile(%s) error = %v", rptPath, err)
}
content := string(data)
if !strings.Contains(content, "RPT log started") {
t.Errorf("RPT missing header, got:\n%s", content)
}
if !strings.Contains(content, "MissionEditor") {
t.Errorf("RPT missing MissionEditor entry, got:\n%s", content)
}
if !strings.Contains(content, "Server: Player") {
t.Errorf("RPT missing Server: Player entry, got:\n%s", content)
}
pm.Stop()
time.Sleep(100 * time.Millisecond)
}
+31
View File
@@ -1,17 +1,39 @@
#!/bin/sh
# Stub arma3server binary for testing.
# Logs binary path and all arguments, prints heartbeat every 5s.
# Writes RPT log entries to the profiles directory (like the real server).
# Use -t N to exit after N seconds (for auto-exit tests).
echo "[STUB] binary=$0 args=$*"
DURATION=0
PROFILES_DIR=""
while [ $# -gt 0 ]; do
case "$1" in
-t) DURATION="$2"; shift 2 ;;
-profiles=*) PROFILES_DIR="${1#-profiles=}"; shift ;;
*) shift ;;
esac
done
# Create RPT file in profiles dir if provided
RPT_FILE=""
if [ -n "$PROFILES_DIR" ]; then
mkdir -p "$PROFILES_DIR"
RPT_FILE="$PROFILES_DIR/arma3server_x64_$(date +%Y%m%d_%H%M%S).rpt"
echo "--- RPT log started ---" > "$RPT_FILE"
echo "Exe timestamp: 2024/01/15 12:00:00" >> "$RPT_FILE"
echo "Computer name: STUB-TEST" >> "$RPT_FILE"
echo "Operating system: Linux" >> "$RPT_FILE"
fi
write_rpt() {
if [ -n "$RPT_FILE" ]; then
echo "$1" >> "$RPT_FILE"
fi
}
TICK=0
if [ "$DURATION" -gt 0 ] 2>/dev/null; then
ELAPSED=0
while [ "$ELAPSED" -lt "$DURATION" ]; do
@@ -20,12 +42,21 @@ if [ "$DURATION" -gt 0 ] 2>/dev/null; then
if [ "$REMAINING" -lt 5 ]; then WAIT=$REMAINING; fi
sleep "$WAIT"
ELAPSED=$((ELAPSED + WAIT))
TICK=$((TICK + 1))
echo "[STUB] heartbeat elapsed=${ELAPSED}s remaining=$((REMAINING - WAIT))s"
write_rpt "$(date +%H:%M:%S) MissionEditor: Mission file selected: test_mission.Tanoa"
write_rpt "$(date +%H:%M:%S) World: Avoid neighbor island: 0.00 ms (1.00 ms)"
write_rpt "$(date +%H:%M:%S) Server: Player #1 connected (id=12345)"
done
write_rpt "$(date +%H:%M:%S) Server: Shutdown completed"
echo "[STUB] server exiting after ${DURATION}s"
else
while true; do
sleep 5
TICK=$((TICK + 1))
echo "[STUB] heartbeat running..."
write_rpt "$(date +%H:%M:%S) MissionEditor: Mission file selected: test_mission.Tanoa"
write_rpt "$(date +%H:%M:%S) World: Avoid neighbor island: 0.00 ms (1.00 ms)"
write_rpt "$(date +%H:%M:%S) Server: Player #1 connected (id=12345)"
done
fi