@@ -198,26 +198,31 @@ def test_device_get_samples_zero_result_returns_tuple(all_devices, subtests):
198198 even when there are zero samples to report, instead of a bare Sample instance.
199199 """
200200 for device in all_devices :
201- with subtests .test (device_index = nvml .device_get_index (device )):
202- with unsupported_before (device , None ):
203- # _FUTURE_TIMESTAMP is newer than any sample can ever be, so the
204- # zero-sample result is deterministic and cannot race with a
205- # newly arriving sample (unlike querying "now" and re-querying).
201+ with subtests .test (device_index = nvml .device_get_index (device )), unsupported_before (device , None ):
202+ last_seen_timestamp = 0
203+ for _ in range (3 ):
206204 try :
207205 result = nvml .device_get_samples (
208- device , nvml .SamplingType .GPU_UTILIZATION_SAMPLES , _FUTURE_TIMESTAMP
206+ device , nvml .SamplingType .GPU_UTILIZATION_SAMPLES , last_seen_timestamp
209207 )
210208 except nvml .NotFoundError :
211209 # Some drivers report NotFoundError instead of a zero-sample
212- # SUCCESS when there is nothing newer than the timestamp;
213- # that is also an acceptable (non-crashing) outcome.
214- continue
210+ # SUCCESS when there is nothing newer than the timestamp.
211+ break
215212
216- assert isinstance (result , tuple )
217- assert len (result ) == 2
218- sample_val_type , samples = result
219- assert isinstance (sample_val_type , int )
220- assert len (samples ) == 0
213+ assert isinstance (result , tuple )
214+ assert len (result ) == 2
215+ sample_val_type , samples = result
216+ assert isinstance (sample_val_type , int )
217+ if len (samples ) == 0 :
218+ break
219+
220+ # NVML documents zero or a timestamp from a previous query.
221+ # Advance to the newest returned sample and try to observe the
222+ # zero-result path before another sample arrives.
223+ last_seen_timestamp = max (sample .time_stamp for sample in samples )
224+ else :
225+ pytest .skip ("NVML continued producing samples before an empty result could be observed" )
221226
222227
223228def _check_vgpu_type_id_list (type_ids ):
0 commit comments