fix: 修复无订阅者时消息静默丢失问题,完善测试
- 新增 pending 缓冲区,publish 时若无订阅者则暂存消息
- subscribe 时自动将缓冲消息投入 channel,解决服务重启后恢复任务丢失的问题
- 去除 broadcast 5ms 超时导致的消息丢失
- chan bool 改为 chan struct{},RWMutex 改为 Mutex
- 新增 broker_test.go,12 个单元测试覆盖核心场景(含 -race)
- 为 client_test.go 中的无限循环 demo 添加 t.Skip()
This commit is contained in:
@@ -10,6 +10,7 @@ const topic = "Golang梦工厂"
|
||||
|
||||
// 一个topic 测试
|
||||
func TestOnceTopic(t *testing.T) {
|
||||
t.Skip("infinite loop demo, not a unit test")
|
||||
m := NewClient()
|
||||
defer m.Close()
|
||||
m.SetConditions(10)
|
||||
@@ -24,7 +25,7 @@ func TestOnceTopic(t *testing.T) {
|
||||
|
||||
// 定时推送
|
||||
func OncePub(c *Client) {
|
||||
t := time.NewTicker(10 * time.Second)
|
||||
t := time.NewTicker(1 * time.Second)
|
||||
defer t.Stop()
|
||||
for {
|
||||
select {
|
||||
@@ -47,8 +48,9 @@ func OnceSub(m <-chan interface{}, c *Client) {
|
||||
}
|
||||
}
|
||||
|
||||
//多个topic测试
|
||||
// 多个topic测试
|
||||
func TestManyTopic(t *testing.T) {
|
||||
t.Skip("infinite loop demo, not a unit test")
|
||||
m := NewClient()
|
||||
defer m.Close()
|
||||
m.SetConditions(10)
|
||||
|
||||
Reference in New Issue
Block a user