test(channelserver): add store tests and document lock ordering

Add unit tests with race-detector coverage for QuestCache,
UserBinaryStore, and MinidataStore (18 tests covering hits, misses,
expiry, copy isolation, and concurrent access).

Document the lock acquisition order on the Server struct to prevent
future deadlocks: Server.Mutex → stagesLock → Stage → semaphoreLock.
This commit is contained in:
Houmgaor
2026-02-21 13:56:46 +01:00
parent 1d5026c3a5
commit da1e62d7c6
4 changed files with 247 additions and 0 deletions

View File

@@ -30,6 +30,15 @@ type Config struct {
}
// Server is a MHF channel server.
//
// Lock ordering (acquire in this order to avoid deadlocks):
// 1. Server.Mutex protects sessions map
// 2. Server.stagesLock protects stages map
// 3. Stage.RWMutex protects per-stage state (clients, objects)
// 4. Server.semaphoreLock protects semaphore map
//
// Self-contained stores (userBinary, minidata, questCache) manage their
// own locks internally and may be acquired at any point.
type Server struct {
sync.Mutex
Channels []*Server