Commit 2b6e8f2
committed
test(adapter): widen raft election budget + retry gRPC on leader churn
PR #602 (leader-stability window) fixed setup-side flake in the redis
tests but left Test_consistency_satisfy_write_after_read_sequence,
Test_consistency_satisfy_write_after_read_for_parallel, and
Test_grpc_transaction flaky on CI. Those tests drive 9,999 (or 1,000×
parallel) raw/txn RPCs against the leader in a loop; if the leader
loses quorum mid-run -- easy under `-race` on a loaded GHA runner --
the first Put/Get after step-down returns "etcd raft engine is not
leader" or "leader not found" and the test fails (with a bonus nil
panic when assert.NoError let a nil response flow into resp.Value).
Root cause of the churn: the test raft config used ElectionTick=10
(100 ms election timeout) with HeartbeatTick=1. etcd/raft's CheckQuorum
only holds ~1 ElectionTick of heartbeat-response history, so any
goroutine-scheduler pause > 100 ms under -race made the leader
conclude quorum was lost and step down.
Fix:
1. Raise testEngineHeartbeatTick / testEngineElectionTick to 5/50
(50 ms heartbeat, 500-1000 ms randomised election timeout). Still
well within the etcd/raft recommended 10x ratio, fast enough for
tests, and generous enough to survive -race scheduling jitter.
As a bonus, LeaseDuration is now 200 ms (500-300 margin) instead
of 0, so the lease-read fast path is actually exercised.
2. Extend isTransientNotLeaderErr to also match "leader not found"
(ErrLeaderNotFound) -- the coordinator emits that variant during
the re-election window, distinct from "not leader".
3. Add rawPut/rawGet/txnPut/txnGet/txnDeleteEventually wrappers that
reuse doEventually to retry on transient leader-unavailable errors,
mirroring rpushEventually/lpushEventually from #596 for the gRPC
paths.
4. Rewrite the three 9999- / 1000-iteration consistency tests to use
the *Eventually helpers. This also removes the nil-pointer crash:
rawGetEventually / txnGetEventually only return a non-nil response.
Verified: all four originally-flaky tests run clean 3 out of 3 with
go test -race -count=1, and the full adapter package passes with
go test -race ./adapter/... -count=1.1 parent 0dc74d4 commit 2b6e8f2
2 files changed
Lines changed: 118 additions & 44 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
154 | 159 | | |
155 | 160 | | |
156 | 161 | | |
157 | 162 | | |
| 163 | + | |
158 | 164 | | |
159 | 165 | | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
170 | 170 | | |
171 | | - | |
172 | 171 | | |
173 | 172 | | |
174 | 173 | | |
| |||
183 | 182 | | |
184 | 183 | | |
185 | 184 | | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
186 | 191 | | |
187 | 192 | | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
| 193 | + | |
| 194 | + | |
199 | 195 | | |
| 196 | + | |
200 | 197 | | |
201 | 198 | | |
202 | 199 | | |
| |||
209 | 206 | | |
210 | 207 | | |
211 | 208 | | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
212 | 212 | | |
213 | 213 | | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
| 214 | + | |
| 215 | + | |
221 | 216 | | |
222 | 217 | | |
223 | | - | |
224 | | - | |
| 218 | + | |
225 | 219 | | |
226 | | - | |
227 | | - | |
| 220 | + | |
228 | 221 | | |
229 | 222 | | |
230 | 223 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
31 | | - | |
32 | | - | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
33 | 46 | | |
34 | 47 | | |
35 | 48 | | |
36 | 49 | | |
37 | | - | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
38 | 53 | | |
39 | 54 | | |
40 | 55 | | |
| |||
519 | 534 | | |
520 | 535 | | |
521 | 536 | | |
522 | | - | |
523 | | - | |
524 | | - | |
525 | | - | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
526 | 542 | | |
527 | | - | |
528 | | - | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
529 | 548 | | |
530 | 549 | | |
531 | 550 | | |
532 | 551 | | |
533 | | - | |
| 552 | + | |
| 553 | + | |
534 | 554 | | |
535 | 555 | | |
536 | 556 | | |
| |||
568 | 588 | | |
569 | 589 | | |
570 | 590 | | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
0 commit comments