22//! schema of its own, since the chain covers every event of its database.
33use super :: * ;
44use crate :: { AdminError , AdminService , AuthConfig , config:: AuditConfig , tests:: operator} ;
5- use chrono:: SubsecRound ;
5+ use chrono:: { SubsecRound , TimeDelta } ;
66use piquel_common:: {
77 Personal , Provider ,
88 config:: { Origin , Variable } ,
@@ -182,8 +182,9 @@ impl Fixture {
182182 }
183183
184184 /// Stores a checkpoint of the stored head at `position`, signed by another
185- /// key, as someone with auth's database role but not its audit key can.
186- async fn forge_checkpoint ( & self , position : u64 ) {
185+ /// key and dated `ahead` of now, as someone with auth's database role but not
186+ /// its audit key can: a trigger allows up to a minute.
187+ async fn forge_checkpoint ( & self , position : u64 , ahead : TimeDelta ) {
187188 let head = self
188189 . database
189190 . audit ( )
@@ -192,7 +193,7 @@ impl Fixture {
192193 . expect ( "chain" ) [ 0 ]
193194 . sealed
194195 . link ;
195- let time = Utc :: now ( ) . trunc_subsecs ( 0 ) ;
196+ let time = ( Utc :: now ( ) + ahead ) . trunc_subsecs ( 0 ) ;
196197 let text = CheckpointText {
197198 origin : "auth.example/audit" . into ( ) ,
198199 head,
@@ -635,9 +636,9 @@ fn committed_keys_are_per_environment() {
635636}
636637
637638/// A checkpoint whose signature does not verify, as someone with auth's database
638- /// role but not the audit key could add, is never built on or served: the sealer
639- /// signs the next one from the newest that verifies, and verification still
640- /// reports the forged one.
639+ /// role but not the audit key could add, is never served, and postpones nothing
640+ /// though dated ahead: the sealer signs the next one from the newest that
641+ /// verifies, and verification still reports the forged one.
641642#[ tokio:: test]
642643#[ ignore = "requires TEST_DATABASE_URL" ]
643644async fn forged_checkpoints_are_passed_over_and_not_served ( ) {
@@ -651,7 +652,9 @@ async fn forged_checkpoints_are_passed_over_and_not_served() {
651652 fixture. record ( 1 ) . await ;
652653 let mut lock = fixture. lock ( ) . await ;
653654 fixture. seal_with ( & mut lock) . await ;
654- fixture. forge_checkpoint ( 7 ) . await ;
655+ // Dated ahead, so a sealer that counted its interval from the newest stored
656+ // checkpoint would wait for it.
657+ fixture. forge_checkpoint ( 7 , TimeDelta :: seconds ( 30 ) ) . await ;
655658 let response = fixture
656659 . router ( )
657660 . await
@@ -706,7 +709,7 @@ async fn forged_checkpoints_are_never_built_on() {
706709 fixture
707710 . tamper ( Tamper :: EditPayload ( 7 , serde_json:: json!( { } ) ) )
708711 . await ;
709- fixture. forge_checkpoint ( 7 ) . await ;
712+ fixture. forge_checkpoint ( 7 , TimeDelta :: zero ( ) ) . await ;
710713 fixture. record ( 1 ) . await ;
711714 fixture. seal_with ( & mut lock) . await ;
712715 assert ! ( matches!(
@@ -727,7 +730,13 @@ async fn forged_checkpoints_are_never_built_on() {
727730async fn checkpoints_keep_their_interval_while_batches_stay_full ( ) {
728731 let mut fixture = Fixture :: new ( ) . await ;
729732 fixture. sealer = fixture. sealer . sealing ( 2 , EventContent :: UNTAGGED ) ;
730- fixture. record ( 5 ) . await ;
733+ // One transaction, so all five become ready to seal at once.
734+ let database = fixture. database . clone ( ) ;
735+ let mut tx = database. begin ( ) . await . expect ( "transaction" ) ;
736+ for _ in 0 ..5 {
737+ fixture. record_in ( & mut tx) . await ;
738+ }
739+ tx. commit ( ) . await . expect ( "commit" ) ;
731740 let mut lock = fixture. lock ( ) . await ;
732741 tokio:: time:: timeout ( Duration :: from_secs ( 30 ) , async {
733742 while fixture. unsealed ( ) . await > 0 {
0 commit comments