Commit 4105082
fix(resolve): fix flaky singleflight deduplication tests (#1393)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Refactor**
* Improved request deduplication and follower tracking by switching to a
low‑contention atomic counter for more reliable concurrency and
streamlined lifecycle handling.
* **Tests**
* Updated test coordination to poll for follower registration with
time‑based deadlines and added gating for deterministic ordering.
* Converted several previously concurrent test actions to synchronous
calls to stabilize timing.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
The inbound request singleflight tests used a channel-based
synchronization pattern that signalled \"entered\" before followers
actually called `GetOrCreate`. Under `-race`, the leader could finish
and delete the singleflight key before followers registered, causing
them to start fresh requests instead of deduplicating — making
`TestResolver_ArenaResolveGraphQLResponse_RequestDeduplication` and two
related tests flaky.
Replace `HasFollowers bool` + `Mu sync.Mutex` on `InflightRequest` with
a single `followerCount atomic.Int32`, incremented inside `GetOrCreate`
at the exact point a follower joins. Tests now poll this counter to
guarantee all followers have registered before the leader is unblocked,
eliminating the race entirely.
## Checklist
- [ ] I have discussed my proposed changes in an issue and have received
approval to proceed.
- [ ] I have followed the coding standards of the project.
- [x] Tests or benchmarks have been added or updated.
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>1 parent f79d071 commit 4105082
4 files changed
Lines changed: 78 additions & 54 deletions
File tree
- execution/subscription
- v2/pkg/engine/resolve
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
417 | 417 | | |
418 | 418 | | |
419 | 419 | | |
420 | | - | |
| 420 | + | |
421 | 421 | | |
422 | 422 | | |
423 | 423 | | |
| |||
481 | 481 | | |
482 | 482 | | |
483 | 483 | | |
484 | | - | |
| 484 | + | |
485 | 485 | | |
486 | 486 | | |
487 | 487 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
49 | | - | |
50 | | - | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
51 | 59 | | |
52 | 60 | | |
53 | 61 | | |
| |||
90 | 98 | | |
91 | 99 | | |
92 | 100 | | |
93 | | - | |
94 | | - | |
95 | | - | |
| 101 | + | |
96 | 102 | | |
97 | 103 | | |
98 | 104 | | |
| |||
113 | 119 | | |
114 | 120 | | |
115 | 121 | | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
| 122 | + | |
120 | 123 | | |
121 | 124 | | |
122 | 125 | | |
| |||
Lines changed: 10 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
75 | 76 | | |
76 | 77 | | |
77 | 78 | | |
78 | | - | |
79 | | - | |
| 79 | + | |
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | 88 | | |
94 | 89 | | |
95 | 90 | | |
96 | 91 | | |
97 | 92 | | |
98 | 93 | | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
107 | 102 | | |
108 | 103 | | |
109 | 104 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
152 | 186 | | |
153 | 187 | | |
154 | 188 | | |
| |||
4694 | 4728 | | |
4695 | 4729 | | |
4696 | 4730 | | |
4697 | | - | |
4698 | | - | |
4699 | | - | |
4700 | 4731 | | |
4701 | 4732 | | |
4702 | 4733 | | |
4703 | 4734 | | |
4704 | | - | |
4705 | | - | |
4706 | 4735 | | |
4707 | 4736 | | |
4708 | 4737 | | |
4709 | 4738 | | |
4710 | 4739 | | |
4711 | 4740 | | |
4712 | | - | |
4713 | | - | |
4714 | | - | |
4715 | | - | |
4716 | | - | |
4717 | | - | |
4718 | | - | |
4719 | | - | |
4720 | | - | |
| 4741 | + | |
| 4742 | + | |
| 4743 | + | |
| 4744 | + | |
4721 | 4745 | | |
4722 | 4746 | | |
4723 | 4747 | | |
| |||
4823 | 4847 | | |
4824 | 4848 | | |
4825 | 4849 | | |
4826 | | - | |
4827 | | - | |
4828 | | - | |
4829 | 4850 | | |
4830 | 4851 | | |
4831 | 4852 | | |
| |||
4838 | 4859 | | |
4839 | 4860 | | |
4840 | 4861 | | |
4841 | | - | |
4842 | | - | |
4843 | 4862 | | |
4844 | 4863 | | |
4845 | 4864 | | |
4846 | 4865 | | |
4847 | 4866 | | |
4848 | 4867 | | |
4849 | | - | |
4850 | | - | |
4851 | | - | |
4852 | | - | |
4853 | | - | |
4854 | | - | |
4855 | | - | |
4856 | | - | |
4857 | | - | |
| 4868 | + | |
| 4869 | + | |
| 4870 | + | |
| 4871 | + | |
4858 | 4872 | | |
4859 | 4873 | | |
4860 | 4874 | | |
| |||
6426 | 6440 | | |
6427 | 6441 | | |
6428 | 6442 | | |
| 6443 | + | |
| 6444 | + | |
| 6445 | + | |
| 6446 | + | |
| 6447 | + | |
| 6448 | + | |
6429 | 6449 | | |
6430 | 6450 | | |
6431 | 6451 | | |
6432 | 6452 | | |
| 6453 | + | |
| 6454 | + | |
| 6455 | + | |
| 6456 | + | |
| 6457 | + | |
6433 | 6458 | | |
6434 | 6459 | | |
6435 | 6460 | | |
| |||
6451 | 6476 | | |
6452 | 6477 | | |
6453 | 6478 | | |
| 6479 | + | |
6454 | 6480 | | |
6455 | 6481 | | |
6456 | 6482 | | |
| |||
0 commit comments