Commit b744d2d
committed
Fix flaky TestPartialStateJoin/Outgoing_device_list_updates from a leave-handler race
`WithWaitForLeave` registered a PDU handler (whose callback feeds
`leaveChannel`) but then decided whether to wait by peeking at
`room.CurrentState`. Because an incoming PDU is added to the room
(`HandleTransactionRequests` calls `room.AddEvent`, updating
`CurrentState`) *before* the PDU callback runs, the test goroutine could
observe the updated state, take the "already seen" shortcut and return,
firing the deferred `removePDUHandler()` in the window before the
callback ran. The now-handler-less callback then flagged the (expected)
leave as an unexpected PDU, failing the test.
Wait on the channel fed by the handler instead of polling
`room.CurrentState`, so the handler stays registered until its own
callback has run.
Every caller passes a joined user and an action that performs the leave, so the
leave always arrives fresh via that callback. Make this contract
explicit: snapshot membership before the action and fail if the user has
already left (rather than silently treating it as "already seen"), and
fail on timeout, since neither should happen in correct usage. The
action still runs in the already-left case so any cleanup it performs is
preserved.
The `HandleTransactionRequests` ordering (callback after `room.AddEvent`) is left
unchanged, as other tests rely on it (e.g.
`federation_redaction_test.go` reads `serverRoom.Timeline` immediately
after a callback-driven waiter).1 parent db8c562 commit b744d2d
1 file changed
Lines changed: 24 additions & 13 deletions
Lines changed: 24 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
144 | | - | |
145 | | - | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
146 | 149 | | |
147 | | - | |
| 150 | + | |
148 | 151 | | |
149 | 152 | | |
150 | 153 | | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
161 | 172 | | |
162 | 173 | | |
163 | 174 | | |
| |||
0 commit comments