mirror of
https://github.com/lexmount/moli.git
synced 2026-11-21 16:03:10 +00:00
test(indexeddb): synchronize the SQL commit receipt boundary
This commit is contained in:
@@ -69,8 +69,9 @@ pub(crate) use indexed_db::{
|
||||
create_sql_upgrade_for_test, deserialize_indexed_db_value_for_test,
|
||||
indexed_db_has_in_flight_sql_tasks_for_test, indexed_db_has_queued_task_kind_for_test,
|
||||
indexed_db_metadata_sharing_probe_for_test, indexed_db_native_cursor_count_for_test,
|
||||
indexed_db_transaction_resources_for_test, serialize_indexed_db_value_for_test,
|
||||
sql_transaction_handle_for_test, sql_transaction_started_for_test,
|
||||
indexed_db_transaction_commit_submitted_for_test, indexed_db_transaction_resources_for_test,
|
||||
serialize_indexed_db_value_for_test, sql_transaction_handle_for_test,
|
||||
sql_transaction_started_for_test,
|
||||
};
|
||||
mod location_history_storage;
|
||||
mod location_navigation;
|
||||
|
||||
@@ -22,7 +22,8 @@ mod typed_state;
|
||||
pub(crate) use typed_state::{
|
||||
IndexedDbMetadataSharingProbe, IndexedDbTaskKind, indexed_db_has_in_flight_sql_tasks_for_test,
|
||||
indexed_db_has_queued_task_kind_for_test, indexed_db_metadata_sharing_probe_for_test,
|
||||
indexed_db_native_cursor_count_for_test, indexed_db_transaction_resources_for_test,
|
||||
indexed_db_native_cursor_count_for_test, indexed_db_transaction_commit_submitted_for_test,
|
||||
indexed_db_transaction_resources_for_test,
|
||||
};
|
||||
#[cfg(test)]
|
||||
pub(crate) fn serialize_indexed_db_value_for_test(
|
||||
|
||||
@@ -627,6 +627,30 @@ pub(crate) fn indexed_db_has_in_flight_sql_tasks_for_test(
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn indexed_db_transaction_commit_submitted_for_test<'s>(
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
transaction: v8::Local<'s, v8::Object>,
|
||||
) -> bool {
|
||||
let Some(id) = indexed_db_typed_state_id(scope, transaction) else {
|
||||
return false;
|
||||
};
|
||||
let table = indexed_db_runtime_state_table_for_object(scope, transaction);
|
||||
let table = table.borrow();
|
||||
table.transactions.get(&id).is_some_and(|state| {
|
||||
state.status.committing
|
||||
&& state.status.commit_scheduled
|
||||
&& !state.status.finished
|
||||
&& !state.status.aborted
|
||||
&& !state.operation_in_flight
|
||||
&& state.operations.is_empty()
|
||||
&& table
|
||||
.sql_tasks
|
||||
.values()
|
||||
.any(|task| task.transaction == Some(id))
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn indexed_db_has_queued_task_kind_for_test(
|
||||
scope: &mut v8::PinScope<'_, '_>,
|
||||
|
||||
@@ -179,22 +179,37 @@ async fn idb_sqlite_committed_upgrade_promotes_shared_mirror_before_later_upgrad
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
// Stop between the actual SQL COMMIT and its renderer receipt. No callback
|
||||
// waits for SQL, and no source can change after COMMIT has been observed.
|
||||
// Stop as soon as the renderer submits COMMIT. Checking the worker's version
|
||||
// before another renderer turn races with COMMIT and can consume its receipt.
|
||||
for step in 0..200 {
|
||||
backend.barrier();
|
||||
if backend.client.committed().unwrap().version == 2 {
|
||||
let commit_submitted = vm
|
||||
.with_default_context_scope(|scope, _| {
|
||||
let global = scope.get_current_context().global(scope);
|
||||
let transaction = v8::Local::<v8::Object>::try_from(
|
||||
global
|
||||
.get(scope, crate::util::v8str(scope, "upgrade").into())
|
||||
.unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
Ok(
|
||||
crate::context_bootstrap::indexed_db_transaction_commit_submitted_for_test(
|
||||
scope,
|
||||
transaction,
|
||||
),
|
||||
)
|
||||
})
|
||||
.unwrap();
|
||||
if commit_submitted {
|
||||
break;
|
||||
}
|
||||
assert!(step < 199);
|
||||
backend.barrier();
|
||||
if !vm
|
||||
.run_one_oldest_ready_page_task_executor_turn(&loader)
|
||||
.await
|
||||
.unwrap()
|
||||
{
|
||||
// Quota authorization may still be running outside the SQL worker.
|
||||
// Only await its wake here: executing the next turn could consume
|
||||
// the COMMIT receipt before we exhaust the mirror budget below.
|
||||
// Native schema preparation may still be in flight.
|
||||
assert!(vm.has_in_flight_indexed_db_tasks_for_test().unwrap());
|
||||
assert!(
|
||||
tokio::time::timeout(
|
||||
@@ -206,6 +221,20 @@ async fn idb_sqlite_committed_upgrade_promotes_shared_mirror_before_later_upgrad
|
||||
);
|
||||
}
|
||||
}
|
||||
// Let quota authorization and the worker finish without dispatching the
|
||||
// queued receipt. Owner wakes recheck the actual committed version.
|
||||
tokio::time::timeout(Duration::from_secs(2), async {
|
||||
while backend.client.committed().unwrap().version != 2 {
|
||||
backend.barrier();
|
||||
if backend.client.committed().unwrap().version == 2 {
|
||||
break;
|
||||
}
|
||||
assert!(vm.has_in_flight_indexed_db_tasks_for_test().unwrap());
|
||||
assert!(vm.wait_for_task_executor_work_arrival().await);
|
||||
}
|
||||
})
|
||||
.await
|
||||
.expect("COMMIT completes before its renderer receipt is dispatched");
|
||||
assert_eq!(backend.client.committed().unwrap().version, 2);
|
||||
assert_eq!(vm.eval("JSON.stringify(events)").unwrap(), "[]");
|
||||
backend.drain(&mut vm, &loader).await;
|
||||
|
||||
Reference in New Issue
Block a user