服务端(Go): - GM 塞背包/带属性装备发放:在线角色推送 op14 增量物品行,背包实时刷新,无需回角色选择界面 - GM 改金币/改等级:去掉在线拒绝,落库后推送 op14 钱包/op37 等级状态,在线实时刷新 - 等级端点统一切换到新版 GMSetCharacterLevel(自带在线刷新) - 无限/锁死疲劳模式 + 燃烧疲劳:每房间消耗 2 点、打怪与通关经验双倍 - 燃烧疲劳开关时给所有在线角色推送系统提示(op12 mode 0) - 深渊史诗掉率:GM 全局倍率 + 城镇增益药剂窗口倍率,真实接入掉落结算 启动器(Python/JS): - 标题栏自绘、窗口 1204x717、禁止拖拽改大小、仅最小化/关闭 - GM 工具:疲劳与燃烧、深渊史诗掉率、拍卖行上架(单一定价对齐) - 拍卖行上架前端对齐服务端单一价格语义,修复 400 报错
112 lines
2.8 KiB
Go
112 lines
2.8 KiB
Go
package pvf
|
|
|
|
import (
|
|
"sync"
|
|
"testing"
|
|
)
|
|
|
|
func TestByteLRUEvictsByResidentBytes(t *testing.T) {
|
|
cache := newByteLRU(5)
|
|
cache.add(1, "1234", 4)
|
|
cache.add(2, "56", 2)
|
|
if _, ok := cache.get(1); ok {
|
|
t.Fatal("oldest entry was not evicted")
|
|
}
|
|
value, ok := cache.get(2)
|
|
if !ok || value.(string) != "56" {
|
|
t.Fatalf("newest entry=%v ok=%v", value, ok)
|
|
}
|
|
snapshot := cache.snapshot()
|
|
if snapshot.entries != 1 || snapshot.bytes != 2 || snapshot.evictions != 1 {
|
|
t.Fatalf("snapshot=%+v", snapshot)
|
|
}
|
|
}
|
|
|
|
func TestByteLRUReplacesEntryWithoutExceedingLimit(t *testing.T) {
|
|
cache := newByteLRU(8)
|
|
cache.add(1, []byte("1234"), 4)
|
|
cache.add(1, []byte("12345678"), 8)
|
|
value, ok := cache.get(1)
|
|
if !ok || string(value.([]byte)) != "12345678" {
|
|
t.Fatalf("value=%v ok=%v", value, ok)
|
|
}
|
|
if got := cache.snapshot(); got.entries != 1 || got.bytes != 8 {
|
|
t.Fatalf("snapshot=%+v", got)
|
|
}
|
|
}
|
|
|
|
func TestByteLRUConcurrentAccess(t *testing.T) {
|
|
cache := newByteLRU(1024)
|
|
var wg sync.WaitGroup
|
|
for worker := 0; worker < 8; worker++ {
|
|
wg.Add(1)
|
|
go func(worker int) {
|
|
defer wg.Done()
|
|
for index := 0; index < 500; index++ {
|
|
key := worker*500 + index
|
|
cache.add(key, "value", 5)
|
|
cache.get(key)
|
|
}
|
|
}(worker)
|
|
}
|
|
wg.Wait()
|
|
if got := cache.snapshot(); got.bytes > 1024 {
|
|
t.Fatalf("resident bytes=%d exceed limit", got.bytes)
|
|
}
|
|
}
|
|
|
|
func TestArchiveReadRemainsStableAfterCacheEviction(t *testing.T) {
|
|
archive, err := OpenArchive(&Bundle{
|
|
data: buildSyntheticNKPIArchive(t),
|
|
textCacheBytes: 1,
|
|
chunkCacheBytes: 1,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("open archive: %v", err)
|
|
}
|
|
first, err := archive.ReadText("dir/test.ani")
|
|
if err != nil {
|
|
t.Fatalf("first read: %v", err)
|
|
}
|
|
second, err := archive.ReadText("dir/test.ani")
|
|
if err != nil {
|
|
t.Fatalf("second read: %v", err)
|
|
}
|
|
if first != second {
|
|
t.Fatalf("read changed after eviction: first=%q second=%q", first, second)
|
|
}
|
|
snapshot := archive.Snapshot()
|
|
if snapshot.CachedChunkBytes > 1 || snapshot.CachedTextBytes > 1 {
|
|
t.Fatalf("cache limits exceeded: %+v", snapshot)
|
|
}
|
|
}
|
|
|
|
func TestArchiveMaterializesFileMetadataOnDemand(t *testing.T) {
|
|
archive, err := OpenBytes(buildSyntheticNKPIArchive(t))
|
|
if err != nil {
|
|
t.Fatalf("open archive: %v", err)
|
|
}
|
|
if got := archive.FileCount(); got != 1 {
|
|
t.Fatalf("file count=%d want=1", got)
|
|
}
|
|
file, ok := archive.FindFile("DIR\\TEST.ANI")
|
|
if !ok {
|
|
t.Fatal("find normalized archive path")
|
|
}
|
|
if file.Index != 0 || file.Path != "dir" || file.Name != "test.ani" || file.ArchivePath != "dir/test.ani" {
|
|
t.Fatalf("file=%+v", file)
|
|
}
|
|
files := archive.Files()
|
|
if len(files) != 1 || files[0] != file {
|
|
t.Fatalf("files=%+v want=%+v", files, file)
|
|
}
|
|
var paths []string
|
|
archive.RangePaths(func(archivePath string) bool {
|
|
paths = append(paths, archivePath)
|
|
return true
|
|
})
|
|
if len(paths) != 1 || paths[0] != "dir/test.ani" {
|
|
t.Fatalf("paths=%v", paths)
|
|
}
|
|
}
|