Fix the try: guard shared test state with mutexes, pgxpool over one conn, a short batch gap for integration builds, unique+forced database drops (issues 1431, 1524, 1517)
This commit is contained in:
@@ -46,15 +46,15 @@ func TestAcceptanceRefusedJudgementIsUnhealthyThenCatchesUpInPublishedOrder(t *t
|
||||
r.stand.MailAccounts = oneAccountAnswer("bob")
|
||||
r.stand.MailRead = func(map[string]any) (any, error) { return map[string]any{"text": "hi"}, nil }
|
||||
r.stand.MessengerCheck = func(map[string]any) (any, error) { return map[string]any{"allowed": true}, nil }
|
||||
var tellCalls int
|
||||
var tellCalls count
|
||||
r.stand.Tell = func(map[string]any) (any, error) {
|
||||
tellCalls++
|
||||
tellCalls.inc()
|
||||
return map[string]any{"sent_on": time.Now().UTC().Format(time.RFC3339)}, nil
|
||||
}
|
||||
|
||||
var mu sync.Mutex
|
||||
refusing := true
|
||||
var judgedOrder []int64
|
||||
var judgedOrder recorded[int64]
|
||||
r.stand.Judge = func(args map[string]any) (any, error) {
|
||||
mu.Lock()
|
||||
stillRefusing := refusing
|
||||
@@ -66,9 +66,9 @@ func TestAcceptanceRefusedJudgementIsUnhealthyThenCatchesUpInPublishedOrder(t *t
|
||||
}
|
||||
question, _ := args["question"].(string)
|
||||
ids := extractMailIDs(question)
|
||||
mu.Lock()
|
||||
judgedOrder = append(judgedOrder, ids...)
|
||||
mu.Unlock()
|
||||
for _, id := range ids {
|
||||
judgedOrder.add(id)
|
||||
}
|
||||
mails := make([]map[string]any, len(ids))
|
||||
for i, id := range ids {
|
||||
mails[i] = map[string]any{"id": id, "mark": "neither", "summary": "s"}
|
||||
@@ -90,8 +90,8 @@ func TestAcceptanceRefusedJudgementIsUnhealthyThenCatchesUpInPublishedOrder(t *t
|
||||
if !strings.Contains(why, "licence") {
|
||||
t.Fatalf("health = %v, want why naming the licence", h)
|
||||
}
|
||||
if tellCalls != 0 {
|
||||
t.Fatalf("a tell was sent while unhealthy: %d call(s)", tellCalls)
|
||||
if n := tellCalls.get(); n != 0 {
|
||||
t.Fatalf("a tell was sent while unhealthy: %d call(s)", n)
|
||||
}
|
||||
|
||||
// A second mail, heard while still unhealthy — it must stay waiting, in order, not lost (1518's own
|
||||
@@ -114,9 +114,7 @@ func TestAcceptanceRefusedJudgementIsUnhealthyThenCatchesUpInPublishedOrder(t *t
|
||||
return n == 2
|
||||
})
|
||||
|
||||
mu.Lock()
|
||||
order := append([]int64(nil), judgedOrder...)
|
||||
mu.Unlock()
|
||||
order := judgedOrder.snapshot()
|
||||
if len(order) < 2 {
|
||||
t.Fatalf("judged ids = %v, want at least 2 (both mails, in one batch or more)", order)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user