@@ -397,13 +397,40 @@ async def test_read_rows_stream(self, table, temp_rows, handler, cluster_config)
397397 assert attempt .grpc_throttling_time_ns == 0 # TODO: confirm
398398
399399 @CrossSync .pytest
400- async def test_read_rows_stream_failure_grpc (
400+ async def test_read_rows_stream_failure_closed (
401401 self , table , temp_rows , handler , error_injector
402402 ):
403403 """
404- Test failure in grpc layer by injecting an error into an interceptor
404+ Test how metrics collection handles closed generator
405+ """
406+ await temp_rows .add_row (b"row_key_1" )
407+ await temp_rows .add_row (b"row_key_2" )
408+ handler .clear ()
409+ generator = await table .read_rows_stream (
410+ ReadRowsQuery ()
411+ )
412+ await generator .__anext__ ()
413+ await generator .aclose ()
414+ with pytest .raises (CrossSync .StopIteration ):
415+ await generator .__anext__ ()
416+ # validate counts
417+ assert len (handler .completed_operations ) == 1
418+ assert len (handler .completed_attempts ) == 1
419+ assert len (handler .cancelled_operations ) == 0
420+ # validate operation
421+ operation = handler .completed_operations [0 ]
422+ assert operation .final_status .name == "CANCELLED"
423+ assert operation .op_type .value == "ReadRows"
424+ assert operation .is_streaming is True
425+ assert len (operation .completed_attempts ) == 1
426+ assert operation .cluster_id == "unspecified"
427+ assert operation .zone == "global"
428+ # validate attempt
429+ attempt = handler .completed_attempts [0 ]
430+ assert attempt .end_status .name == "CANCELLED"
431+ assert attempt .gfe_latency_ns is None
432+
405433
406- No headers expected
407434 """
408435 await temp_rows.add_row(b"row_key_1")
409436 handler.clear()
0 commit comments