@@ -14,16 +14,17 @@ use deno_core::error::AnyError;
1414use deno_core:: op2;
1515use deno_core:: v8;
1616use deno_core:: ModuleSpecifier ;
17- use deno_core:: OpMetrics ;
17+ use deno_core:: OpMetricsSummary ;
18+ use deno_core:: OpMetricsSummaryTracker ;
1819use deno_core:: OpState ;
1920use deno_runtime:: deno_fetch:: reqwest;
2021use deno_runtime:: permissions:: create_child_permissions;
2122use deno_runtime:: permissions:: ChildPermissionsArg ;
2223use deno_runtime:: permissions:: PermissionsContainer ;
2324use serde:: Serialize ;
24- use std:: cell:: Ref ;
2525use std:: collections:: hash_map:: Entry ;
2626use std:: collections:: HashMap ;
27+ use std:: rc:: Rc ;
2728use std:: sync:: atomic:: AtomicUsize ;
2829use std:: sync:: atomic:: Ordering ;
2930use uuid:: Uuid ;
@@ -243,38 +244,28 @@ fn op_test_event_step_result_failed(
243244struct TestOpSanitizers ( HashMap < u32 , TestOpSanitizerState > ) ;
244245
245246enum TestOpSanitizerState {
246- Collecting { metrics : Vec < OpMetrics > } ,
247+ Collecting { metrics : Vec < OpMetricsSummary > } ,
247248 Finished { report : Vec < TestOpSanitizerReport > } ,
248249}
249250
250251fn try_collect_metrics (
251- state : & OpState ,
252+ metrics : & OpMetricsSummaryTracker ,
252253 force : bool ,
253254 op_id_host_recv_msg : usize ,
254255 op_id_host_recv_ctrl : usize ,
255- ) -> Result < Ref < Vec < OpMetrics > > , bool > {
256- let metrics = state. tracker . per_op ( ) ;
257- for op_metric in & * metrics {
258- let has_pending_ops = op_metric. ops_dispatched_async
259- + op_metric. ops_dispatched_async_unref
260- > op_metric. ops_completed_async + op_metric. ops_completed_async_unref ;
261- if has_pending_ops && !force {
262- let host_recv_msg = metrics
263- . get ( op_id_host_recv_msg)
264- . map ( |op_metric| {
265- op_metric. ops_dispatched_async + op_metric. ops_dispatched_async_unref
266- > op_metric. ops_completed_async
267- + op_metric. ops_completed_async_unref
268- } )
269- . unwrap_or ( false ) ;
270- let host_recv_ctrl = metrics
271- . get ( op_id_host_recv_ctrl)
272- . map ( |op_metric| {
273- op_metric. ops_dispatched_async + op_metric. ops_dispatched_async_unref
274- > op_metric. ops_completed_async
275- + op_metric. ops_completed_async_unref
276- } )
277- . unwrap_or ( false ) ;
256+ ) -> Result < std:: cell:: Ref < Vec < OpMetricsSummary > > , bool > {
257+ let metrics = metrics. per_op ( ) ;
258+ let host_recv_msg = metrics
259+ . get ( op_id_host_recv_msg)
260+ . map ( OpMetricsSummary :: has_outstanding_ops)
261+ . unwrap_or ( false ) ;
262+ let host_recv_ctrl = metrics
263+ . get ( op_id_host_recv_ctrl)
264+ . map ( OpMetricsSummary :: has_outstanding_ops)
265+ . unwrap_or ( false ) ;
266+
267+ for op_metric in metrics. iter ( ) {
268+ if op_metric. has_outstanding_ops ( ) && !force {
278269 return Err ( host_recv_msg || host_recv_ctrl) ;
279270 }
280271 }
@@ -294,23 +285,23 @@ fn op_test_op_sanitizer_collect(
294285 #[ smi] op_id_host_recv_msg : usize ,
295286 #[ smi] op_id_host_recv_ctrl : usize ,
296287) -> Result < u8 , AnyError > {
297- let metrics = {
298- let metrics = match try_collect_metrics (
299- state ,
300- force,
301- op_id_host_recv_msg,
302- op_id_host_recv_ctrl,
303- ) {
304- Ok ( metrics) => metrics,
305- Err ( false ) => {
306- return Ok ( 1 ) ;
307- }
308- Err ( true ) => {
309- return Ok ( 2 ) ;
310- }
311- } ;
312- metrics . clone ( )
313- } ;
288+ let metrics = state . borrow :: < Rc < OpMetricsSummaryTracker > > ( ) ;
289+ let metrics = match try_collect_metrics (
290+ metrics ,
291+ force,
292+ op_id_host_recv_msg,
293+ op_id_host_recv_ctrl,
294+ ) {
295+ Ok ( metrics) => metrics,
296+ Err ( false ) => {
297+ return Ok ( 1 ) ;
298+ }
299+ Err ( true ) => {
300+ return Ok ( 2 ) ;
301+ }
302+ }
303+ . clone ( ) ;
304+
314305 let op_sanitizers = state. borrow_mut :: < TestOpSanitizers > ( ) ;
315306 match op_sanitizers. 0 . entry ( id) {
316307 Entry :: Vacant ( entry) => {
@@ -348,11 +339,12 @@ fn op_test_op_sanitizer_finish(
348339) -> Result < u8 , AnyError > {
349340 // Drop `fetch` connection pool at the end of a test
350341 state. try_take :: < reqwest:: Client > ( ) ;
342+ let metrics = state. borrow :: < Rc < OpMetricsSummaryTracker > > ( ) ;
351343
352344 // Generate a report of pending ops
353345 let report = {
354346 let after_metrics = match try_collect_metrics (
355- state ,
347+ metrics ,
356348 force,
357349 op_id_host_recv_msg,
358350 op_id_host_recv_ctrl,
@@ -380,14 +372,10 @@ fn op_test_op_sanitizer_finish(
380372 for ( id, ( before, after) ) in
381373 before_metrics. iter ( ) . zip ( after_metrics. iter ( ) ) . enumerate ( )
382374 {
383- let async_pending_before = before. ops_dispatched_async
384- + before. ops_dispatched_async_unref
385- - before. ops_completed_async
386- - before. ops_completed_async_unref ;
387- let async_pending_after = after. ops_dispatched_async
388- + after. ops_dispatched_async_unref
389- - after. ops_completed_async
390- - after. ops_completed_async_unref ;
375+ let async_pending_before =
376+ before. ops_dispatched_async - before. ops_completed_async ;
377+ let async_pending_after =
378+ after. ops_dispatched_async - after. ops_completed_async ;
391379 let diff = async_pending_after as i64 - async_pending_before as i64 ;
392380 if diff != 0 {
393381 report. push ( TestOpSanitizerReport { id, diff } ) ;
0 commit comments