@@ -1162,108 +1162,3 @@ def fake_remote_fct(
11621162 (mock .ANY , "my name is progress" )
11631163 )
11641164 await _assert_wait_for_cb_call (mocked_user_completed_cb )
1165-
1166-
1167- async def test_get_cluster_details (
1168- dask_client : DaskClient ,
1169- user_id : UserID ,
1170- project_id : ProjectID ,
1171- image_params : ImageParams ,
1172- _mocked_node_ports : None ,
1173- mocked_user_completed_cb : mock .AsyncMock ,
1174- mocked_storage_service_api : respx .MockRouter ,
1175- comp_run_metadata : RunMetadataDict ,
1176- empty_hardware_info : HardwareInfo ,
1177- faker : Faker ,
1178- resource_tracking_run_id : ServiceRunID ,
1179- ):
1180- cluster_details = await dask_client .get_cluster_details ()
1181- assert cluster_details
1182-
1183- _DASK_EVENT_NAME = faker .pystr ()
1184-
1185- # send a fct that uses resources
1186- def fake_sidecar_fct (
1187- task_parameters : ContainerTaskParameters ,
1188- docker_auth : DockerBasicAuth ,
1189- log_file_url : LogFileUploadURL ,
1190- s3_settings : S3Settings | None ,
1191- expected_annotations ,
1192- ) -> TaskOutputData :
1193- # get the task data
1194- worker = get_worker ()
1195- task = worker .state .tasks .get (worker .get_current_task ())
1196- assert task is not None
1197- assert task .annotations == expected_annotations
1198- assert task_parameters .command == ["run" ]
1199- event = distributed .Event (_DASK_EVENT_NAME )
1200- event .wait (timeout = 25 )
1201-
1202- return TaskOutputData .model_validate ({"some_output_key" : 123 })
1203-
1204- # NOTE: We pass another fct so it can run in our localy created dask cluster
1205- published_computation_task = await dask_client .send_computation_tasks (
1206- user_id = user_id ,
1207- project_id = project_id ,
1208- tasks = image_params .fake_tasks ,
1209- callback = mocked_user_completed_cb ,
1210- remote_fct = functools .partial (
1211- fake_sidecar_fct , expected_annotations = image_params .expected_annotations
1212- ),
1213- metadata = comp_run_metadata ,
1214- hardware_info = empty_hardware_info ,
1215- resource_tracking_run_id = resource_tracking_run_id ,
1216- )
1217- assert published_computation_task
1218- assert len (published_computation_task ) == 1
1219-
1220- assert published_computation_task [0 ].node_id in image_params .fake_tasks
1221-
1222- # check status goes to PENDING/STARTED
1223- await _assert_wait_for_task_status (
1224- published_computation_task [0 ].job_id ,
1225- dask_client ,
1226- expected_status = RunningState .STARTED ,
1227- )
1228-
1229- # check we have one worker using the resources
1230- # one of the workers should now get the job and use the resources
1231- worker_with_the_task : AnyUrl | None = None
1232- async for attempt in AsyncRetrying (reraise = True , stop = stop_after_delay (10 )):
1233- with attempt :
1234- cluster_details = await dask_client .get_cluster_details ()
1235- assert cluster_details
1236- assert (
1237- cluster_details .scheduler .workers
1238- ), f"there are no workers in { cluster_details .scheduler = !r} "
1239- for worker_url , worker_data in cluster_details .scheduler .workers .items ():
1240- if all (
1241- worker_data .used_resources .get (res_name ) == res_value
1242- for res_name , res_value in image_params .expected_used_resources .items ()
1243- ):
1244- worker_with_the_task = worker_url
1245- assert (
1246- worker_with_the_task is not None
1247- ), f"there is no worker in { cluster_details .scheduler .workers .keys ()= } consuming { image_params .expected_annotations = !r} "
1248-
1249- # using the event we let the remote fct continue
1250- event = distributed .Event (_DASK_EVENT_NAME , client = dask_client .backend .client )
1251- await event .set () # type: ignore
1252-
1253- # wait for the task to complete
1254- await _assert_wait_for_task_status (
1255- published_computation_task [0 ].job_id ,
1256- dask_client ,
1257- expected_status = RunningState .SUCCESS ,
1258- )
1259-
1260- # check the resources are released
1261- cluster_details = await dask_client .get_cluster_details ()
1262- assert cluster_details
1263- assert cluster_details .scheduler .workers
1264- assert worker_with_the_task
1265- currently_used_resources = cluster_details .scheduler .workers [
1266- worker_with_the_task
1267- ].used_resources
1268-
1269- assert all (res == 0.0 for res in currently_used_resources .values ())
0 commit comments