Skip to content

Commit e6b9f48

Browse files
ldanilekConvex, Inc.
authored andcommitted
fix race in crons tests (#31020)
udf-tests contains crons, so the crons tests have a race: - load the modules with crons - crons start running for the first time in the background, reading and writing the `_crons` table - then we create a new cron for the test and that can hit an OCC this is currently not causing a failure, but when i change some internal tokio scheduling within queries, it starts failing. so let's preemptively fix it. note this is using TestRuntime, so time jumps forward as much as it needs to, and the 100 second sleep takes a few milliseconds while running all crons that are scheduled to run immediately GitOrigin-RevId: a433f7edb42c47719f924ea75902c912d0769fb8
1 parent e64c277 commit e6b9f48

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

crates/application/src/tests/cron_jobs.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ fn cron_log_query<RT: Runtime>(
110110
pub(crate) async fn test_cron_jobs_success(rt: TestRuntime) -> anyhow::Result<()> {
111111
let application = Application::new_for_tests(&rt).await?;
112112
application.load_udf_tests_modules().await?;
113+
// udf-tests include crons, so we let them execute so that we can then add
114+
// a new cron without hitting an OCC.
115+
rt.wait(Duration::from_secs(100)).await;
113116

114117
let mut tx = application.begin(Identity::system()).await?;
115118

@@ -146,6 +149,9 @@ pub(crate) async fn test_cron_jobs_success(rt: TestRuntime) -> anyhow::Result<()
146149
pub(crate) async fn test_cron_jobs_race_condition(rt: TestRuntime) -> anyhow::Result<()> {
147150
let application = Application::new_for_tests(&rt).await?;
148151
application.load_udf_tests_modules().await?;
152+
// udf-tests include crons, so we let them execute so that we can then add
153+
// a new cron without hitting an OCC.
154+
rt.wait(Duration::from_secs(100)).await;
149155

150156
let mut tx = application.begin(Identity::system()).await?;
151157
let (original_jobs, mut model) = create_cron_job(&mut tx).await?;

0 commit comments

Comments
 (0)