def test_eligible_includes_expired_syncing(initialized_db): """ Mirrors that have an end time in the past are eligible even if their state indicates still syncing. """ disable_existing_mirrors() mirror_first, repo_first = create_mirror_repo_robot(["updated", "created"], repo_name="first") mirror_second, repo_second = create_mirror_repo_robot( ["updated", "created"], repo_name="second") mirror_third, repo_third = create_mirror_repo_robot(["updated", "created"], repo_name="third") mirror_fourth, repo_third = create_mirror_repo_robot( ["updated", "created"], repo_name="fourth") mirror_second.sync_expiration_date = datetime.utcnow() - timedelta(hours=1) mirror_second.sync_status = RepoMirrorStatus.SYNCING mirror_second.save() mirror_fourth.sync_expiration_date = datetime.utcnow() + timedelta(hours=1) mirror_fourth.sync_status = RepoMirrorStatus.SYNCING mirror_fourth.save() candidates = get_eligible_mirrors() assert len(candidates) == 3 assert candidates[0] == mirror_first assert candidates[1] == mirror_second assert candidates[2] == mirror_third
def test_eligible_includes_immediate(initialized_db): """ Mirrors that are SYNC_NOW, regardless of starting time. """ disable_existing_mirrors() mirror_first, repo_first = create_mirror_repo_robot(["updated", "created"], repo_name="first") mirror_second, repo_second = create_mirror_repo_robot( ["updated", "created"], repo_name="second" ) mirror_third, repo_third = create_mirror_repo_robot(["updated", "created"], repo_name="third") mirror_fourth, repo_third = create_mirror_repo_robot(["updated", "created"], repo_name="fourth") mirror_future, _ = create_mirror_repo_robot(["updated", "created"], repo_name="future") mirror_past, _ = create_mirror_repo_robot(["updated", "created"], repo_name="past") mirror_future.sync_start_date = datetime.utcnow() + timedelta(hours=6) mirror_future.sync_status = RepoMirrorStatus.SYNC_NOW mirror_future.save() mirror_past.sync_start_date = datetime.utcnow() - timedelta(hours=6) mirror_past.sync_status = RepoMirrorStatus.SYNC_NOW mirror_past.save() mirror_fourth.sync_expiration_date = datetime.utcnow() + timedelta(hours=1) mirror_fourth.sync_status = RepoMirrorStatus.SYNCING mirror_fourth.save() candidates = get_eligible_mirrors() assert len(candidates) == 5 assert candidates[0] == mirror_first assert candidates[1] == mirror_second assert candidates[2] == mirror_third assert candidates[3] == mirror_past assert candidates[4] == mirror_future
def test_eligible_oldest_first(initialized_db): """ Eligible mirror candidates should be returned with the oldest (earliest created) first. """ disable_existing_mirrors() mirror_first, repo_first = create_mirror_repo_robot(["updated", "created"], repo_name="first") mirror_second, repo_second = create_mirror_repo_robot( ["updated", "created"], repo_name="second" ) mirror_third, repo_third = create_mirror_repo_robot(["updated", "created"], repo_name="third") candidates = get_eligible_mirrors() assert len(candidates) == 3 assert candidates[0] == mirror_first assert candidates[1] == mirror_second assert candidates[2] == mirror_third
def batch_query(): return get_eligible_mirrors()