|
28 | 28 | ClaimRaceTestCase, |
29 | 29 | ClaimWaitTestCase, |
30 | 30 | DoubleCloseTestCase, |
| 31 | + LongClaimWaitTestCase, |
31 | 32 | QuietTokenTestCase, |
32 | 33 | RefusedResumeTestCase, |
33 | 34 | StaleSyncResumeTestCase, |
|
43 | 44 | RefusingResumeAdapter, |
44 | 45 | SyncDuringTakeoverAdapter, |
45 | 46 | TokenPausingDuckDbAdapter, |
| 47 | + age_beat_and_sync, |
46 | 48 | build_lease_project, |
47 | 49 | claim_events, |
| 50 | + expired_hold_plan, |
48 | 51 | finish_claimed_resume, |
49 | 52 | heartbeat_count, |
50 | 53 | held_by_dead_run, |
@@ -736,30 +739,8 @@ def test_given_two_builds_taking_over_one_expired_hold_when_one_holds_the_model_ |
736 | 739 | adapter: ClaimHookAdapter = ClaimHookAdapter() |
737 | 740 | connection: Any = adapter.connect({"database": str(database_path)}) |
738 | 741 | connection.execute("CREATE SCHEMA staging") |
739 | | - _ = build_lease_project( |
740 | | - adapter=adapter, |
741 | | - connection=connection, |
742 | | - case=lease_project_case( |
743 | | - orders_query="SELECT 1 AS order_id", report_locations={}, refresh_on_build=False |
744 | | - ), |
745 | | - runtime=BuildRuntimeParams(run_id="first_run"), |
746 | | - database_path=database_path, |
747 | | - ) |
748 | | - plan: PlanOutput = plan_lease_project( |
749 | | - adapter=adapter, |
750 | | - connection=connection, |
751 | | - case=lease_project_case( |
752 | | - orders_query="SELECT 1 AS order_id UNION ALL SELECT 2", |
753 | | - report_locations={}, |
754 | | - refresh_on_build=False, |
755 | | - ), |
756 | | - ) |
757 | | - seed_hold( |
758 | | - adapter=adapter, |
759 | | - connection=connection, |
760 | | - run_id="dead_run", |
761 | | - name="daily_totals", |
762 | | - idle_seconds=3600, |
| 742 | + plan: PlanOutput = expired_hold_plan( |
| 743 | + adapter=adapter, connection=connection, database_path=database_path |
763 | 744 | ) |
764 | 745 | holder: DynamicHold | None = hold_dynamic_models( |
765 | 746 | plan=plan, |
@@ -787,3 +768,62 @@ def test_given_two_builds_taking_over_one_expired_hold_when_one_holds_the_model_ |
787 | 768 | assert states == test_case.expected_states |
788 | 769 | assert tuple(sorted(hold.run_id for hold in holds)) == test_case.expected_open_holds |
789 | 770 | assert claims == list(test_case.expected_claims) |
| 771 | + |
| 772 | + |
| 773 | +@pytest.mark.parametrize( |
| 774 | + "test_case", |
| 775 | + [ |
| 776 | + LongClaimWaitTestCase( |
| 777 | + description="a build waiting past its grace on a claim still beats, so it keeps its hold", |
| 778 | + grace_seconds=61, |
| 779 | + waited_seconds=62, |
| 780 | + expected_open_holds=("second_run",), |
| 781 | + expected_states={"daily_totals": "SUSPENDED"}, |
| 782 | + expected_released_states={"daily_totals": "ACTIVE"}, |
| 783 | + ), |
| 784 | + ], |
| 785 | + ids=lambda case: case.description, |
| 786 | +) |
| 787 | +def test_given_a_build_waiting_on_a_claim_past_its_grace_when_another_sync_passes_then_its_hold_stays_live( |
| 788 | + test_case: LongClaimWaitTestCase, database_path: Path |
| 789 | +) -> None: |
| 790 | + adapter: ClaimHookAdapter = ClaimHookAdapter() |
| 791 | + connection: Any = adapter.connect({"database": str(database_path)}) |
| 792 | + connection.execute("CREATE SCHEMA staging") |
| 793 | + plan: PlanOutput = expired_hold_plan( |
| 794 | + adapter=adapter, connection=connection, database_path=database_path |
| 795 | + ) |
| 796 | + claim_run: str = f"{_SYNC}/claim/slow" |
| 797 | + seed_claim(adapter=adapter, connection=connection, claim_run=claim_run, age_seconds=0) |
| 798 | + adapter.after_claim_read.append( |
| 799 | + lambda read: age_beat_and_sync( |
| 800 | + adapter=adapter, |
| 801 | + connection=read, |
| 802 | + waiting=("second_run", test_case.waited_seconds), |
| 803 | + sync=("location-sync:other", float(test_case.grace_seconds), claim_run), |
| 804 | + ) |
| 805 | + ) |
| 806 | + building: DynamicHold | None = hold_dynamic_models( |
| 807 | + plan=plan, |
| 808 | + adapter=adapter, |
| 809 | + runtime=BuildRuntimeParams( |
| 810 | + run_id="second_run", dynamic_heartbeat_grace_seconds=test_case.grace_seconds |
| 811 | + ), |
| 812 | + connection_config={"database": str(database_path)}, |
| 813 | + heartbeat_seconds=0.05, |
| 814 | + claim_wait=(60.0, 0.02), |
| 815 | + ) |
| 816 | + assert building is not None |
| 817 | + |
| 818 | + building.acquire(connection=connection, on_progress=None) |
| 819 | + |
| 820 | + holds: tuple[OpenHold, ...] = read_open_holds( |
| 821 | + adapter=adapter, connection=connection, location=(None, "staging") |
| 822 | + ) |
| 823 | + states: dict[str, str] = dict(adapter.states) |
| 824 | + building.release(connection=connection) |
| 825 | + released: dict[str, str] = dict(adapter.states) |
| 826 | + adapter.close(connection) |
| 827 | + assert tuple(sorted(hold.run_id for hold in holds)) == test_case.expected_open_holds |
| 828 | + assert states == test_case.expected_states |
| 829 | + assert released == test_case.expected_released_states |
0 commit comments