aboutsummaryrefslogtreecommitdiff
path: root/internal/game/hardening_shutdown_save_error_test.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-10-03 07:11:58 -0400
committerhistoria <[not public]>2026-10-03 07:11:58 -0400
commit0fb83bdf433b9b48240f4ac7a5d4c912f6b808cc (patch)
treeac0af51cc2513b1ddd8a280f360af820d1f097af /internal/game/hardening_shutdown_save_error_test.go
parent6232d41e5639f9c38e47b2bb65266e343ca26e8f (diff)
downloadthehouseoficarus-0fb83bdf433b9b48240f4ac7a5d4c912f6b808cc.tar.gz
feat: added big 6 wheel to the casino
Diffstat (limited to 'internal/game/hardening_shutdown_save_error_test.go')
-rw-r--r--internal/game/hardening_shutdown_save_error_test.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/internal/game/hardening_shutdown_save_error_test.go b/internal/game/hardening_shutdown_save_error_test.go
index c75f6fc..5842f9b 100644
--- a/internal/game/hardening_shutdown_save_error_test.go
+++ b/internal/game/hardening_shutdown_save_error_test.go
@@ -7,10 +7,59 @@ package game
import (
"os"
"path/filepath"
+ "reflect"
"strings"
"testing"
+ "time"
+
+ "thehouseoficarus/internal/player"
)
+func TestShutdownPreservesOnlineLocationAndExploration(t *testing.T) {
+ h := newHarness(t)
+ h.seedAccount("alice")
+ p := h.seedCharacter("alice", "alice")
+ p.RoomID = 6101
+ p.Stats.RecordRoomVisit(6101)
+ if err := h.g.AccountStore.SaveCharacter(p); err != nil {
+ t.Fatal(err)
+ }
+ sess, _ := h.connect("alice")
+ wantRooms := []int{6101, 6182, 6183, 6199}
+ h.g.RunOnOwner(func() {
+ sess.Player.RoomID = 6199
+ for _, id := range wantRooms {
+ sess.Player.Stats.RecordRoomVisit(id)
+ }
+ })
+ // Deliberately leave disk at the older state. The signal shutdown path
+ // must persist the connected character before closing the transport,
+ // without requiring the player to quit or disconnect first.
+ var saved *player.Player
+ var loadErr error
+ h.g.SetTransportStop(func() {
+ saved, loadErr = player.NewAccountStore(h.dir).LoadCharacter("alice")
+ })
+ h.g.RequestShutdown("signal")
+ select {
+ case <-h.g.ShutdownDone():
+ case <-time.After(5 * time.Second):
+ t.Fatal("shutdown did not finish")
+ }
+ if err := h.g.ShutdownSaveError(); err != nil {
+ t.Fatal(err)
+ }
+ if loadErr != nil {
+ t.Fatal(loadErr)
+ }
+ if saved == nil {
+ t.Fatal("transport stop was not called")
+ }
+ if saved.RoomID != 6199 || !reflect.DeepEqual(saved.Stats.RoomsVisited.Keys(), wantRooms) {
+ t.Fatalf("shutdown lost progress: room=%d explored=%v", saved.RoomID, saved.Stats.RoomsVisited.Keys())
+ }
+}
+
// TestShutdownSaveErrorReportsFailedFinalSave makes the character save fail
// (the character file is replaced by a directory, so the atomic replace cannot
// land) and requires the shutdown sequence to record the failure on the Game.