@@ -799,55 +799,66 @@ func (t *TestSuite) GetPackageRevisionWithFilter(repo, pkgName string, filter Pa
799799 return & prList .Items [0 ]
800800}
801801
802- // TriggerRepoSync schedules a one-time sync for the given repository by setting
803- // spec.sync.runOnceAt to now+7s, then waits for the sync to complete.
804802func (t * TestSuite ) TriggerRepoSync (repoName string , timeout time.Duration ) {
805803 t .T ().Helper ()
806804 repoKey := client.ObjectKey {Namespace : t .Namespace , Name : repoName }
807805
808806 var repo configapi.Repository
809807 t .GetF (repoKey , & repo )
810808
809+ baselineLastSync := time.Time {}
810+ if repo .Status .LastFullSyncTime != nil {
811+ baselineLastSync = repo .Status .LastFullSyncTime .Time
812+ }
813+
811814 if repo .Spec .Sync == nil {
812815 repo .Spec .Sync = & configapi.RepositorySync {}
813816 }
814- // The handleRunOnceAt goroutine polls every 5s and requires time.Until(runOnceAt) > 0
815- // when it observes the change, so we add 8s of lead time to be safe.
816- repo .Spec .Sync .RunOnceAt = ptr .To (metav1 .NewTime (time .Now ().Add (8 * time .Second )))
817+ // Schedule runOnceAt slightly in the past so the controller's isOneTimeSyncDue
818+ // check triggers a full sync on the next reconcile without an extra delay.
819+ runOnceAt := metav1 .NewTime (time .Now ().Add (- 1 * time .Second ))
820+ repo .Spec .Sync .RunOnceAt = ptr .To (runOnceAt )
817821 t .UpdateF (& repo )
818822
819823 t .Logf ("TriggerRepoSync: set runOnceAt for repo %s, waiting for sync to complete" , repoName )
820- t .WaitForNextRepoSync (repoName , timeout )
824+ t .WaitForNextRepoSync (repoName , timeout , baselineLastSync , runOnceAt . Time )
821825}
822826
823- // WaitForNextRepoSync waits until the Ready condition message changes, indicating a sync cycle completed.
824- func (t * TestSuite ) WaitForNextRepoSync (repoName string , timeout time.Duration ) {
827+ func (t * TestSuite ) WaitForNextRepoSync (repoName string , timeout time.Duration , baselineLastSync , triggeredRunOnceAt time.Time ) {
825828 t .T ().Helper ()
826829 repoKey := client.ObjectKey {Namespace : t .Namespace , Name : repoName }
827830
828- var repo configapi.Repository
829- t .GetF (repoKey , & repo )
830-
831- currentMsg := ""
832- for _ , cond := range repo .Status .Conditions {
833- if cond .Type == configapi .RepositoryReady {
834- currentMsg = cond .Message
835- break
836- }
837- }
838-
839- t .Logf ("WaitForNextRepoSync: waiting for repo %s condition to change from %q (timeout %v)" , repoName , currentMsg , timeout )
831+ t .Logf ("WaitForNextRepoSync: waiting for repo %s full sync after LastFullSyncTime %v (timeout %v)" ,
832+ repoName , baselineLastSync , timeout )
840833 waitErr := wait .PollUntilContextTimeout (t .GetContext (), 1 * time .Second , timeout , false , func (ctx context.Context ) (bool , error ) {
841834 var latest configapi.Repository
842835 if err := t .Reader .Get (ctx , repoKey , & latest ); err != nil {
843836 return false , err
844837 }
838+
839+ ready := false
845840 for _ , cond := range latest .Status .Conditions {
846- if cond .Type == configapi .RepositoryReady && cond .Message != currentMsg {
847- t . Logf ( "WaitForNextRepoSync: repo %s sync completed (new message=%q)" , repoName , cond . Message )
848- return true , nil
841+ if cond .Type == configapi .RepositoryReady && cond .Status == metav1 . ConditionTrue {
842+ ready = true
843+ break
849844 }
850845 }
846+ if ! ready {
847+ return false , nil
848+ }
849+
850+ if latest .Status .LastFullSyncTime != nil && latest .Status .LastFullSyncTime .Time .After (baselineLastSync ) {
851+ t .Logf ("WaitForNextRepoSync: repo %s sync completed (LastFullSyncTime=%s)" ,
852+ repoName , latest .Status .LastFullSyncTime .Time .Format (time .RFC3339 ))
853+ return true , nil
854+ }
855+
856+ if latest .Status .ObservedRunOnceAt != nil && latest .Status .ObservedRunOnceAt .Time .Equal (triggeredRunOnceAt ) {
857+ t .Logf ("WaitForNextRepoSync: repo %s runOnceAt sync completed (ObservedRunOnceAt=%s)" ,
858+ repoName , latest .Status .ObservedRunOnceAt .Time .Format (time .RFC3339 ))
859+ return true , nil
860+ }
861+
851862 return false , nil
852863 })
853864
0 commit comments