fix: track live downstream cmpp connections
This commit is contained in:
@@ -99,6 +99,7 @@ func TestInboundServerAuthenticatesAndSubmits(t *testing.T) {
|
||||
password := "secret-hash"
|
||||
var gotAuth authRequest
|
||||
var gotSubmit submitRequest
|
||||
connectionEvents := make(chan downstreamConnectionEvent, 8)
|
||||
api := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.URL.Path {
|
||||
case "/api/gateway/events/inbound/authenticate":
|
||||
@@ -113,6 +114,13 @@ func TestInboundServerAuthenticatesAndSubmits(t *testing.T) {
|
||||
_ = json.NewEncoder(w).Encode(submitResponse{Accepted: true, MessageID: "MSG-1"})
|
||||
case "/api/gateway/events/downstream/pending":
|
||||
_ = json.NewEncoder(w).Encode([]pendingDelivery{})
|
||||
case "/api/gateway/events/inbound/connection":
|
||||
var event downstreamConnectionEvent
|
||||
if err := json.NewDecoder(r.Body).Decode(&event); err != nil {
|
||||
t.Fatalf("decode connection event: %v", err)
|
||||
}
|
||||
connectionEvents <- event
|
||||
w.WriteHeader(http.StatusOK)
|
||||
default:
|
||||
t.Fatalf("unexpected api path: %s", r.URL.Path)
|
||||
}
|
||||
@@ -130,6 +138,14 @@ func TestInboundServerAuthenticatesAndSubmits(t *testing.T) {
|
||||
if err := client.Connect(addr, account, password, 2*time.Second); err != nil {
|
||||
t.Fatalf("connect inbound cmpp: %v", err)
|
||||
}
|
||||
select {
|
||||
case event := <-connectionEvents:
|
||||
if event.Status != "connected" || event.Account != account || event.ConnectionID == "" || event.RemoteIP == "" || event.Protocol != "cmpp30" {
|
||||
t.Fatalf("unexpected connection event: %+v", event)
|
||||
}
|
||||
case <-time.After(2 * time.Second):
|
||||
t.Fatal("expected downstream connected callback")
|
||||
}
|
||||
|
||||
content, err := cmpputils.Utf8ToUcs2("测试入站")
|
||||
if err != nil {
|
||||
@@ -207,6 +223,8 @@ func TestInboundServerNegotiatesCMPP2AndUsesAuthenticatedAccountForSubmit(t *tes
|
||||
_ = json.NewEncoder(w).Encode(submitResponse{Accepted: true, MessageID: "MSG-CMPP2"})
|
||||
case "/api/gateway/events/downstream/pending":
|
||||
_ = json.NewEncoder(w).Encode([]pendingDelivery{})
|
||||
case "/api/gateway/events/inbound/connection":
|
||||
w.WriteHeader(http.StatusOK)
|
||||
default:
|
||||
t.Fatalf("unexpected api path: %s", r.URL.Path)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user