21
21
import pytest
22
22
23
23
24
- @pytest .fixture (scope = "session" , autouse = True )
25
- def cleanup_commitments (
26
- reservation_client : reservation_service .ReservationServiceClient , location_path : str
27
- ) -> None :
28
- for commitment in reservation_client .list_capacity_commitments (
29
- parent = location_path
30
- ):
31
- if commitment .state == reservation_types .CapacityCommitment .State .FAILED or (
32
- commitment .commitment_start_time is not None
33
- and commitment .commitment_start_time
34
- < datetime .datetime .now (datetime .timezone .utc ) - datetime .timedelta (days = 1 )
35
- ):
36
- reservation_client .delete_capacity_commitment (name = commitment .name )
37
-
38
-
39
24
@pytest .fixture (scope = "session" )
40
25
def project_id () -> str :
41
26
return os .environ ["GOOGLE_CLOUD_PROJECT" ]
@@ -58,22 +43,3 @@ def location_path(project_id: str, location: str) -> str:
58
43
return reservation_service .ReservationServiceClient .common_location_path (
59
44
project_id , location
60
45
)
61
-
62
-
63
- @pytest .fixture (scope = "session" , autouse = True )
64
- def capacity_commitment (
65
- location_path : str , reservation_client : reservation_service .ReservationServiceClient
66
- ) -> reservation_types .CapacityCommitment :
67
- commitment = reservation_types .CapacityCommitment ()
68
- commitment .slot_count = 100
69
- commitment .plan = reservation_types .CapacityCommitment .CommitmentPlan .FLEX
70
- commitment = reservation_client .create_capacity_commitment (
71
- parent = location_path , capacity_commitment = commitment
72
- )
73
- yield commitment
74
- # Commitments can only be removed after 1 minute.
75
- now = datetime .datetime .now (datetime .timezone .utc )
76
- delta = commitment .commitment_end_time - now
77
- sleep_seconds = max (0 , delta .total_seconds ()) + 5
78
- time .sleep (sleep_seconds )
79
- reservation_client .delete_capacity_commitment (name = commitment .name )
0 commit comments