package accept import ( "os" "testing" "time" "git.asio.asia/nixevol/NixMsg/test/harness" ) // TestF08NetemRemote 连到已经在丢包路径上的服务,确认保留消息能送达,且相同消息号不再投递一次。 // 由虚拟机脚本准备地址。不进入 task check。 func TestF08NetemRemote(t *testing.T) { if os.Getenv("NIXMSG_NETEM") != "1" { t.Skip("设置 NIXMSG_NETEM=1 才连到外部丢包环境") } httpBase := os.Getenv("NIXMSG_HTTP") tcpAddr := os.Getenv("NIXMSG_TCP") adminPass := os.Getenv("NIXMSG_ADMIN_PASS") if httpBase == "" || tcpAddr == "" || adminPass == "" { t.Fatal("需要 NIXMSG_HTTP、NIXMSG_TCP、NIXMSG_ADMIN_PASS") } hs := &harness.Server{ HTTPBase: httpBase, AdminHTTPBase: httpBase, AdminPassword: adminPass, Addr: tcpAddr, } ac := AdminLogin(t, hs) const password = "password1234" CreateEndpoint(t, ac, "nemalice1", password) CreateEndpoint(t, ac, "nembob001", password) alice := MQTTLoginTCP(t, tcpAddr, "nemalice1", password) defer alice.Close() bob := MQTTLoginTCP(t, tcpAddr, "nembob001", password) defer bob.Close() send := alice.Request(t, map[string]any{ "v": 1, "type": "send", "rid": "nem1", "id": "nem-msg-1", "to": map[string]any{"kind": "endpoint", "id": "nembob001"}, "body": map[string]any{"enc": "utf8", "data": "through-loss"}, "delay_ms": int64(0), "offline": map[string]any{"keep": true, "ttl_seconds": int64(3600)}, }) if !send.OK { t.Fatalf("send: %+v", send) } msg := bob.WaitType(t, "msg", 45*time.Second) if msg["id"] != "nem-msg-1" { t.Fatalf("msg: %v", msg) } again := alice.Request(t, map[string]any{ "v": 1, "type": "send", "rid": "nem2", "id": "nem-msg-1", "to": map[string]any{"kind": "endpoint", "id": "nembob001"}, "body": map[string]any{"enc": "utf8", "data": "through-loss"}, "delay_ms": int64(0), "offline": map[string]any{"keep": true, "ttl_seconds": int64(3600)}, }) if !again.OK { t.Fatalf("resend same id: %+v", again) } if extra := bob.TryType("msg", 3*time.Second); extra != nil && extra["id"] == "nem-msg-1" { t.Fatalf("duplicate delivery: %v", extra) } }