Skip to content

Commit 893f81f

Browse files
bradseilercodex
andcommitted
test(db): derive push lease fixture time from persisted receipt
Avoid comparing host and PostgreSQL clocks in the async enqueue guard regression. Assert strict lease ordering before releasing activation. Co-authored-by: Codex <[email protected]> Signed-off-by: Brad Seiler <[email protected]>
1 parent 1caaf74 commit 893f81f

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

‎crates/buzz-db/src/store/event_follow_up_postgres_tests.rs‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1018,13 +1018,30 @@ async fn assert_async_isolation(db: &Db, community: CommunityId, keys: &Keys) {
10181018
endpoint_grant, max_class, subscriptions, expires_at, updated_at) \
10191019
SELECT $1, author, installation_id, source_event_id, source_created_at, generation, \
10201020
active, endpoint_enabled, endpoint_hash, endpoint_grant, max_class, \
1021-
subscriptions, expires_at, clock_timestamp() FROM push_leases WHERE community_id=$2",
1021+
subscriptions, expires_at, \
1022+
(SELECT received_at + interval '1 second' FROM events WHERE community_id=$1 AND id=$3) \
1023+
FROM push_leases WHERE community_id=$2",
10221024
)
10231025
.bind(later.as_uuid())
10241026
.bind(community.as_uuid())
1027+
.bind(before_enrollment.id.as_bytes().as_slice())
10251028
.execute(&mut *activation)
10261029
.await
10271030
.unwrap();
1031+
let leases_strictly_newer: bool = sqlx::query_scalar(
1032+
"SELECT count(*) > 0 AND bool_and(l.updated_at > e.received_at) \
1033+
FROM push_leases l JOIN events e ON e.community_id=l.community_id \
1034+
WHERE l.community_id=$1 AND e.id=$2",
1035+
)
1036+
.bind(later.as_uuid())
1037+
.bind(before_enrollment.id.as_bytes().as_slice())
1038+
.fetch_one(&mut *activation)
1039+
.await
1040+
.unwrap();
1041+
assert!(
1042+
leases_strictly_newer,
1043+
"fixture leases must follow recorded receipt"
1044+
);
10281045
activation.commit().await.unwrap();
10291046
assert_eq!(match_count(&isolated, later, &before_enrollment).await, 0);
10301047
assert_eq!(

0 commit comments

Comments
 (0)