ModernUO/Projects/Server.Tests/Tests/Serialization
Kamron Batman 003491472f
fix: world save failure handling — no partial snapshots, no worker crash, staged publication (#2612)
Three pre-existing world-save failure-handling bugs, found while reviewing the delta-saves engine (#2610), split out so they land and get adopted on their own before the larger change. #2610 will be rebased on top once this merges. Tracked in project Delta Saves (#7).

## 1. A snapshot missing a segment was published

`GenericEntityPersistence.WriteSnapshot` logged a segment (or self-payload) write error and carried on. The save was published without those records, and every entity in the failed segment was deleted at the next load. The error now propagates: `WriteFiles` never moves a partial snapshot over `Saves/`, the previous save stays authoritative, and staff are told.

## 2. A serializer exception killed the process, or published a partial freeze

An entity whose `Serialize` threw on a worker thread was an unhandled exception on that thread, which terminates the process. On the inline (main-thread) drain it was caught, but the snapshot was still queued for writing with whatever the workers had produced. Workers now record the first exception and keep draining so the queue empties and the wake/pause handshake completes; after every worker paused, `Snapshot` treats a recorded error (or a failure of the drain itself) as a failed save: nothing is written, the previous save stays, staff are told, and the world resumes. A `WorldSave` handler throwing is logged but does not invalidate the serialized snapshot.

## 3. Publication was not transactional

Publishing moved the previous `Saves/` away (`AutoArchive` in `WorldSavePostSnapshot`) and only then moved the new files in. A subscriber throwing after the archive, or the final move failing, left nothing at `Saves/` until the next save; a crash in that window lost the newest save at the next boot.

The snapshot now moves to `Saves.next` as soon as its files are complete; only then do subscribers archive the previous save (same event, same `OldSavePath`, so `AutoArchive` and shard subscribers are unchanged), and the staged directory is renamed into place, which is atomic on one volume (file-by-file move across volumes). A staged directory is by construction a complete save newer than `Saves/`, so an interrupted publish is finished at the next boot (before load) or before the next save: whatever sits at `Saves/` is set aside as `Saves.previous-<timestamp>` (never deleted) and the staged save is published, with a warning naming the directory to archive or delete by hand.

## Tests

Server.Tests 860 / UOContent.Tests green. New: a throwing serializer is recorded on the worker and the next drain starts clean; a segment that cannot be indexed fails `WriteSnapshot` instead of dropping records; staged-save recovery with and without an existing `Saves/`, and as a no-op.
2026-09-06 13:46:14 -07:00
..
AnchoredItemSerializationTests.cs feat: convert all delta-time serialization to anchored time (#2589) 2026-08-22 19:34:43 -07:00
AnchoredTimeTests.cs feat: anchored-time infrastructure with a save-start anchor in idx v5 (#2585) 2026-08-22 15:59:39 -07:00
BufferWriterTests.cs perf(saves): eliminate world-save freeze bottlenecks (~9.5x faster freeze) (#2525) 2026-07-16 22:53:28 -07:00
DecimalSerializationTests.cs chore: Use var everywhere (#2294) 2025-12-27 16:47:28 -08:00
EnumConversionTests.cs fix: Fixes spawner timer deserialization, decimal deserialization, and adds potion keg reverse lookup (#1711) 2024-03-28 13:34:12 -07:00
FileBufferWriterTests.cs perf(saves): eliminate world-save freeze bottlenecks (~9.5x faster freeze) (#2525) 2026-07-16 22:53:28 -07:00
GenericEntityPersistenceRoundTripTests.cs fix: world save failure handling — no partial snapshots, no worker crash, staged publication (#2612) 2026-09-06 13:46:14 -07:00
GenericEntityPersistenceTypeTableTests.cs perf(saves): eliminate world-save freeze bottlenecks (~9.5x faster freeze) (#2525) 2026-07-16 22:53:28 -07:00
SerializationChunkSourceTests.cs perf(saves): eliminate world-save freeze bottlenecks (~9.5x faster freeze) (#2525) 2026-07-16 22:53:28 -07:00
SerializationThreadWorkerHandshakeTests.cs perf(saves): eliminate world-save freeze bottlenecks (~9.5x faster freeze) (#2525) 2026-07-16 22:53:28 -07:00
ShadowDictionaryEntriesTests.cs perf(saves): eliminate world-save freeze bottlenecks (~9.5x faster freeze) (#2525) 2026-07-16 22:53:28 -07:00
StagedSavePublishTests.cs fix: world save failure handling — no partial snapshots, no worker crash, staged publication (#2612) 2026-09-06 13:46:14 -07:00
TypeConverterTests.cs chore: Use var everywhere (#2294) 2025-12-27 16:47:28 -08:00