test: 对齐 F06 群发与 M2 离线不保留完成态
This commit is contained in:
@@ -58,7 +58,7 @@ func setup(t *testing.T) (*group.App, *identity.App, *message.App, *store.DB, *m
|
||||
DB: db, Talk: idApp, Downlink: down, MaxGroupMembers: 1000,
|
||||
Now: func() time.Time { return fixed }, DefaultRemoteIP: "1.1.1.1",
|
||||
})
|
||||
lim := message.LimitsFromConfig(config.Default().Limits)
|
||||
lim := message.LimitsFromFullConfig(config.Default())
|
||||
lim.RequestsPerSecond = 0
|
||||
msgApp := message.New(db, lim, auth.NewStubHashPool(),
|
||||
message.WithNow(func() time.Time { return fixed }),
|
||||
@@ -325,6 +325,7 @@ func TestF06GroupSendMembership(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// 默认不保留 + 成员离线(无连接、无 offline_since):投递立即 dropped,消息 completed(DEVELOPMENT 7.4/7.6)
|
||||
res, err := msgApp.Submit(ctx, "alice", port.ConnInfo{}, &protocol.Send{
|
||||
V: protocol.Version, Type: protocol.TypeSend, RID: "s", ID: "m1",
|
||||
To: protocol.Target{Kind: protocol.TargetGroup, ID: created.ID},
|
||||
@@ -333,14 +334,20 @@ func TestF06GroupSendMembership(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if res.State != message.StateDispatched {
|
||||
t.Fatalf("state=%s", res.State)
|
||||
if res.State != message.StateCompleted {
|
||||
t.Fatalf("state=%s want completed (offline, keep=false)", res.State)
|
||||
}
|
||||
var cnt int
|
||||
_ = db.Read.QueryRow(`SELECT COUNT(*) FROM deliveries d JOIN messages m ON m.seq=d.seq WHERE m.id='m1'`).Scan(&cnt)
|
||||
if cnt != 2 {
|
||||
t.Fatalf("deliveries=%d want 2 (not sender)", cnt)
|
||||
}
|
||||
var pending, dropped int
|
||||
_ = db.Read.QueryRow(`SELECT COUNT(*) FROM deliveries d JOIN messages m ON m.seq=d.seq WHERE m.id='m1' AND d.state='pending'`).Scan(&pending)
|
||||
_ = db.Read.QueryRow(`SELECT COUNT(*) FROM deliveries d JOIN messages m ON m.seq=d.seq WHERE m.id='m1' AND d.state='dropped'`).Scan(&dropped)
|
||||
if pending != 0 || dropped != 2 {
|
||||
t.Fatalf("pending=%d dropped=%d want pending=0 dropped=2", pending, dropped)
|
||||
}
|
||||
var self int
|
||||
_ = db.Read.QueryRow(`SELECT COUNT(*) FROM deliveries d JOIN messages m ON m.seq=d.seq WHERE m.id='m1' AND d.endpoint_id='alice'`).Scan(&self)
|
||||
if self != 0 {
|
||||
@@ -363,6 +370,40 @@ func TestF06GroupSendMembership(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestF06GroupSendKeepOfflinePending(t *testing.T) {
|
||||
t.Parallel()
|
||||
gApp, _, msgApp, db, _ := setup(t)
|
||||
ctx := context.Background()
|
||||
insertEP(t, db, "alice", 1)
|
||||
insertEP(t, db, "bob", 1)
|
||||
insertEP(t, db, "carol", 1)
|
||||
created, err := gApp.Create(ctx, "alice", &protocol.GroupCreate{
|
||||
V: protocol.Version, Type: protocol.TypeGroupCreate, RID: "1",
|
||||
Name: "GKeep", Members: []protocol.GroupMemberIn{{ID: "bob"}, {ID: "carol"}},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ttl := int64(3600)
|
||||
res, err := msgApp.Submit(ctx, "alice", port.ConnInfo{}, &protocol.Send{
|
||||
V: protocol.Version, Type: protocol.TypeSend, RID: "s", ID: "mkeep",
|
||||
To: protocol.Target{Kind: protocol.TargetGroup, ID: created.ID},
|
||||
Body: protocol.Body{Enc: protocol.EncUTF8, Data: "kept"},
|
||||
Offline: &protocol.OfflineOpts{Keep: true, TTLSeconds: &ttl},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if res.State != message.StateDispatched {
|
||||
t.Fatalf("state=%s want dispatched (offline keep)", res.State)
|
||||
}
|
||||
var pending int
|
||||
_ = db.Read.QueryRow(`SELECT COUNT(*) FROM deliveries d JOIN messages m ON m.seq=d.seq WHERE m.id='mkeep' AND d.state='pending'`).Scan(&pending)
|
||||
if pending != 2 {
|
||||
t.Fatalf("pending=%d want 2", pending)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGroupTransferRenameListGet(t *testing.T) {
|
||||
t.Parallel()
|
||||
gApp, _, _, db, _ := setup(t)
|
||||
|
||||
Reference in New Issue
Block a user