fix: 压测客户端改为 MQTT 5 并完成 hello 与收发统计
This commit is contained in:
+19
-58
@@ -1,21 +1,15 @@
|
||||
package load_test
|
||||
package load
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.asio.asia/nixevol/NixMsg/test/accept"
|
||||
"git.asio.asia/nixevol/NixMsg/test/harness"
|
||||
)
|
||||
|
||||
const (
|
||||
epPassword = "password1234"
|
||||
// 本机短时压测目标:几十连接收发。不做 1000 / 10 分钟(见 DEVIATIONS)。
|
||||
q3LivePairs = 16 // 32 个端、16 对收发
|
||||
)
|
||||
const epPassword = "password1234"
|
||||
|
||||
// TestQ3LiveShortBurst 短时几十连接登录并完成单聊收发。
|
||||
// TestQ3LiveShortBurst 短时真实登录+单聊,覆盖原先 Q3 冒烟;完整 50×1m 见 TestLocalLoadReport。
|
||||
func TestQ3LiveShortBurst(t *testing.T) {
|
||||
srv, err := harness.Start(harness.Options{})
|
||||
if err != nil {
|
||||
@@ -23,56 +17,23 @@ func TestQ3LiveShortBurst(t *testing.T) {
|
||||
}
|
||||
defer func() { _ = srv.Stop() }()
|
||||
|
||||
ac := accept.AdminLogin(t, srv)
|
||||
type pair struct {
|
||||
a, b string
|
||||
cfg := Config{
|
||||
HTTPBase: srv.HTTPBase,
|
||||
AdminPass: srv.AdminPassword,
|
||||
Password: epPassword,
|
||||
Prefix: "q3",
|
||||
N: 8,
|
||||
Rate: 10,
|
||||
Duration: 3 * time.Second,
|
||||
GroupSize: 8,
|
||||
Scenario: "all",
|
||||
}
|
||||
pairs := make([]pair, 0, q3LivePairs)
|
||||
for i := 0; i < q3LivePairs; i++ {
|
||||
a := fmt.Sprintf("q3la%04d", i)
|
||||
b := fmt.Sprintf("q3lb%04d", i)
|
||||
accept.CreateEndpoint(t, ac, a, epPassword)
|
||||
accept.CreateEndpoint(t, ac, b, epPassword)
|
||||
pairs = append(pairs, pair{a: a, b: b})
|
||||
rep, err := Run(cfg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
sessions := make([]*accept.MQTTSession, 0, q3LivePairs*2)
|
||||
defer func() {
|
||||
for _, s := range sessions {
|
||||
s.Close()
|
||||
}
|
||||
}()
|
||||
|
||||
for _, p := range pairs {
|
||||
sa := accept.MQTTLogin(t, srv.HTTPBase, p.a, epPassword)
|
||||
sb := accept.MQTTLogin(t, srv.HTTPBase, p.b, epPassword)
|
||||
sessions = append(sessions, sa, sb)
|
||||
if rep.Disconnects != 0 || rep.SubmitMs.N == 0 || len(rep.Errors) != 0 || rep.GroupMembers != 8 {
|
||||
t.Fatalf("%s", rep.Format())
|
||||
}
|
||||
|
||||
for i, p := range pairs {
|
||||
sa := sessions[i*2]
|
||||
sb := sessions[i*2+1]
|
||||
msgID := fmt.Sprintf("q3-load-%d", i)
|
||||
resp := sa.Request(t, map[string]any{
|
||||
"v": 1, "type": "send", "rid": fmt.Sprintf("ls%d", i), "id": msgID,
|
||||
"to": map[string]any{"kind": "endpoint", "id": p.b},
|
||||
"body": map[string]any{"enc": "utf8", "data": "burst"},
|
||||
"delay_ms": int64(0),
|
||||
})
|
||||
if !resp.OK {
|
||||
t.Fatalf("pair %d send: %+v", i, resp)
|
||||
}
|
||||
msg := sb.WaitType(t, "msg", 15*time.Second)
|
||||
if msg["id"] != msgID {
|
||||
t.Fatalf("pair %d want %s got %v", i, msgID, msg)
|
||||
}
|
||||
ack := sb.Request(t, map[string]any{
|
||||
"v": 1, "type": "ack", "rid": fmt.Sprintf("la%d", i),
|
||||
"from": p.a, "id": msgID,
|
||||
})
|
||||
if !ack.OK {
|
||||
t.Fatalf("pair %d ack: %+v", i, ack)
|
||||
}
|
||||
}
|
||||
t.Logf("短时压测通过:%d 连接、%d 对单聊收发成功(未做 1000 连接 / 10 分钟)", q3LivePairs*2, q3LivePairs)
|
||||
t.Logf("短时压测通过:\n%s", rep.Format())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user