merged from gramsrv upstream
This commit is contained in:
parent
79c64ee916
commit
21a0856587
651 changed files with 54774 additions and 4590 deletions
|
|
@ -10,7 +10,7 @@ import (
|
|||
"telesrv/internal/domain"
|
||||
)
|
||||
|
||||
func TestPhoneChangeStoreAtomicUserEventOutboxPostgres(t *testing.T) {
|
||||
func TestPhoneChangeStoreUpdatesUserWithoutPTSPostgres(t *testing.T) {
|
||||
pool := testPool(t)
|
||||
ctx := context.Background()
|
||||
users := NewUserStore(pool)
|
||||
|
|
@ -43,7 +43,7 @@ func TestPhoneChangeStoreAtomicUserEventOutboxPostgres(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("change phone: %v", err)
|
||||
}
|
||||
if !result.Changed || result.User.Phone != newPhone || result.Event.Pts != 1 || result.Event.Phone != newPhone {
|
||||
if !result.Changed || result.User.Phone != newPhone {
|
||||
t.Fatalf("result = %+v", result)
|
||||
}
|
||||
loaded, found, err := users.ByID(ctx, u1.ID)
|
||||
|
|
@ -51,28 +51,27 @@ func TestPhoneChangeStoreAtomicUserEventOutboxPostgres(t *testing.T) {
|
|||
t.Fatalf("loaded user = %+v found=%v err=%v", loaded, found, err)
|
||||
}
|
||||
storedEvents, err := events.ListAfter(ctx, u1.ID, 0, 10)
|
||||
if err != nil || len(storedEvents) != 1 || storedEvents[0].Type != domain.UpdateEventUserPhone || storedEvents[0].Phone != newPhone {
|
||||
if err != nil || len(storedEvents) != 0 {
|
||||
t.Fatalf("stored events = %+v err=%v", storedEvents, err)
|
||||
}
|
||||
var outboxCount int
|
||||
var excludedAuth, excludedSession int64
|
||||
if err := pool.QueryRow(ctx, `SELECT count(*), max(exclude_auth_key_id), max(exclude_session_id) FROM dispatch_outbox WHERE target_user_id = $1 AND pts = $2`, u1.ID, result.Event.Pts).Scan(&outboxCount, &excludedAuth, &excludedSession); err != nil {
|
||||
if err := pool.QueryRow(ctx, `SELECT count(*) FROM dispatch_outbox WHERE target_user_id = $1`, u1.ID).Scan(&outboxCount); err != nil {
|
||||
t.Fatalf("query outbox: %v", err)
|
||||
}
|
||||
if outboxCount != 1 || excludedAuth != authKeyIDToInt64(authKeyID) || excludedSession != 77 {
|
||||
t.Fatalf("outbox count/auth/session = %d/%d/%d", outboxCount, excludedAuth, excludedSession)
|
||||
if outboxCount != 0 {
|
||||
t.Fatalf("outbox count = %d, want 0", outboxCount)
|
||||
}
|
||||
|
||||
// 同号重试是幂等读,不得重复推进 pts 或重复入 outbox。
|
||||
// 同号重试是幂等读,不得产生 PTS/event/outbox。
|
||||
retry, err := changes.ChangePhone(ctx, domain.PhoneChangeRequest{UserID: u1.ID, Phone: newPhone, Date: 1700000002})
|
||||
if err != nil || retry.Changed || retry.Event.Pts != 0 || retry.User.Phone != newPhone {
|
||||
if err != nil || retry.Changed || retry.User.Phone != newPhone {
|
||||
t.Fatalf("idempotent retry = %+v err=%v", retry, err)
|
||||
}
|
||||
if pts, err := events.MaxContiguousPts(ctx, u1.ID); err != nil || pts != 1 {
|
||||
t.Fatalf("pts after retry = %d err=%v", pts, err)
|
||||
}
|
||||
|
||||
// 冲突更新整体回滚:号码和 pts/event 都不变。
|
||||
// 冲突更新整体回滚:号码不变,也不产生 PTS/event。
|
||||
if _, err := changes.ChangePhone(ctx, domain.PhoneChangeRequest{UserID: u2.ID, Phone: newPhone}); !errors.Is(err, domain.ErrPhoneNumberOccupied) {
|
||||
t.Fatalf("occupied change err = %v", err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue