redis/TEST.md

25 lines
1.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Redis Module Test Report
## Test Coverage
- **Base Operations**: GET, SET, SETEX, DEL, EXISTS, EXPIRE, etc. (Verified in `TestBase`)
- **Distributed ID**: Integrated with `go/id`, supports high-concurrency pre-fetching. (Verified in `TestIDMaker`)
- **Generics**: Type-safe result binding using `To[T]`. (Verified in `TestGenerics`)
- **Pub/Sub**: Thread-safe publish and subscribe with automatic re-connection. (Verified in `TestSub`)
- **Robustness**: Automatic retry on network failure/server restart. (Verified in `TestRetry`)
## Deadlock Verification
- Refactored `Redis` struct to use a shared `pubsub` state.
- Verified that `CopyByLogger` correctly shares PubSub state without race conditions.
- Fixed `Start()` and `Stop()` logic to prevent redundant goroutines and ensure clean exit.
## Benchmarks
- **BenchmarkGetSet**: ~80,000 ns/op (Simple GET/SET loop)
- **BenchmarkIDMaker**: ~2,300 ns/op (High-performance sequence generation)
## 🛡️ 鲁棒性防御 (Robustness)
- **安全沙箱拦截**:在 `SafeMode` 下,仅允许 GET/EXISTS/ZRANGE 等读操作命令,自动拦截所有写操作命令并返回错误。
- **JS 错误调用栈**JS 桥接层改用具名导出并使用 `jsmod.MakeError` 包裹错误(包括 Do 返回的 Result.Error 字段),确保 JS 抛出异常时携带准确的 Go 运行时堆栈。
> Date: 2026-06-21
> Environment: Darwin / Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz