-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
race test cache of unauthed query & refactor Pause library (#33289)
Test a race condition that's happening with the query cache, where unauthed queries don't wait for each other. To test this race condition, I needed a more powerful PauseController, so that's the majority of this PR. Motivating example: I want to run two queries in parallel, pause them both right before they start executing the function (after they have checked the cache and determined it's a miss), then run them both to completion. In order to do that, I need two PauseGuards at the same time for the same label. Issues with existing PauseController impl: 1. when PauseController is created, all labels become breakpoints that the test code will pause on. You don't have the control to only enable breakpoints after database setup, for example. if there's a `.wait` call you don't care about, you must wait for it in parallel or you'll get a deadlock. 2. while you're paused on one breakpoint, you can't set any other breakpoints or pause on the same breakpoint again, because the PauseGuard holds a mut ref to PauseController. 3. there's a deadlock if you try to do this pattern, which looks reasonable: ```rust let mut fut = Box::pin(do_something_that_waits(pause_client)); let mut pause_guard = select! { pause_guard = pause_controller.wait_for_blocked("label") => pause_guard, _ = &mut fut => panic!("fut should wait"), }; pause_guard.unpause(); fut.await; ``` (if you're interested, you can try to find the deadlock. hint: in logs you can see [this log line](https://github.com/get-convex/convex/blob/9dabf6eb63a57ab2fbd9eaa1787aa57931a88902/crates/common/src/pause.rs#L98). My new version fixes these issues, and incidentally it's closer to Dropbox's library with the same purpose. 1. by default all breakpoints are inactive. activate a breakpoint with `pause_controller.hold(label)`. Then it's active until `.wait(label)` has been called, after which it becomes inactive unless the controller calls `.hold` again. This gives the test framework fine-grained control over which breakpoints are active. 2. while you're paused on one breakpoint, you can set other breakpoints or re-activate the same breakpoint with `.hold`. This was useful for my auth-caching test because I want to pause two parallel-running queries after they have checked the cache, and only then unpause them to execute the functions. 3. fixed the deadlock in the pattern above by only using the `rendezvous` for the initial pause. for the unpause we can use a `oneshot` so it doesn't block. GitOrigin-RevId: 57c15b2648570929e16e6f82e6644316d2316f42
- Loading branch information
Showing
19 changed files
with
334 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.