fix(openapi): harden story 2.1 production lifecycle
This commit is contained in:
@@ -385,6 +385,16 @@ async fn multipart_boundary_rejections_are_localized_and_leave_no_entities() {
|
||||
Some("no supported methods"),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(
|
||||
sqlx::query_scalar::<_, i64>(
|
||||
"select count(*) from artifact_sources where lifecycle = 'active'",
|
||||
)
|
||||
.fetch_one(registry.pool())
|
||||
.await
|
||||
.unwrap(),
|
||||
0,
|
||||
"no_methods must not leave an active source behind",
|
||||
);
|
||||
assert_rejected(
|
||||
&client,
|
||||
&server,
|
||||
@@ -432,6 +442,42 @@ async fn multipart_boundary_rejections_are_localized_and_leave_no_entities() {
|
||||
assert!(!rendered.contains("digest"));
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
#[serial]
|
||||
async fn cleanup_is_bounded_and_malformed_expired_jobs_do_not_block_later_rows() {
|
||||
let registry = test_registry().await;
|
||||
for index in 0..129 {
|
||||
sqlx::query(
|
||||
"insert into import_jobs (
|
||||
id, workspace_id, kind, source_format, source_version, status,
|
||||
preview_payload, created_operation_ids, error_text, created_at, expires_at, finished_at
|
||||
) values (
|
||||
$1, 'ws_default', 'openapi', 'openapi', null, 'pending',
|
||||
'{\"source\": {\"source_id\": 1}}'::jsonb, '[]'::jsonb, null,
|
||||
now() - interval '2 hours', now() - interval '1 hour', null
|
||||
)",
|
||||
)
|
||||
.bind(format!("imp_cleanup_{index:03}"))
|
||||
.execute(registry.pool())
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
let first = registry.cleanup_expired_import_jobs(128).await.unwrap();
|
||||
assert_eq!(first.deleted_jobs, 128);
|
||||
assert!(first.more_work);
|
||||
let second = registry.cleanup_expired_import_jobs(128).await.unwrap();
|
||||
assert_eq!(second.deleted_jobs, 1);
|
||||
assert!(!second.more_work);
|
||||
assert_eq!(
|
||||
sqlx::query_scalar::<_, i64>("select count(*) from import_jobs")
|
||||
.fetch_one(registry.pool())
|
||||
.await
|
||||
.unwrap(),
|
||||
0,
|
||||
);
|
||||
}
|
||||
|
||||
async fn wait_for_source_lifecycle(
|
||||
registry: &crank_registry::PostgresRegistry,
|
||||
lifecycle: ArtifactSourceLifecycle,
|
||||
@@ -746,11 +792,15 @@ async fn cancellation_detaches_and_restart_cleanup_recovers_a_dangling_source()
|
||||
preview_task.abort();
|
||||
let cancellation = preview_task.await.unwrap_err();
|
||||
assert!(cancellation.is_cancelled());
|
||||
wait_for_blocked_import_insert_to_stop(&observer).await;
|
||||
// Dropping a sqlx query future does not synchronously cancel the backend
|
||||
// statement. Release the artificial blocker first; the abandoned
|
||||
// transaction can then finish and roll back before the detach fallback
|
||||
// obtains another pooled connection.
|
||||
sqlx::query("select pg_advisory_unlock(2147483001)")
|
||||
.execute(&mut *lock_connection)
|
||||
.await
|
||||
.unwrap();
|
||||
wait_for_blocked_import_insert_to_stop(&observer).await;
|
||||
wait_for_specific_source_lifecycle(
|
||||
®istry,
|
||||
&cancelled_source_id,
|
||||
|
||||
Reference in New Issue
Block a user