@@ -40,8 +40,9 @@ describe('AsyncJSCallsHandler', function() {
4040 const allEvents = [ ...rendererEvents , ...flowEvents ] ;
4141
4242 const asyncCallStacksData = await buildAsyncJSCallsHandlerData ( allEvents ) ;
43- const testRunEntryPoint = asyncCallStacksData . schedulerToRunEntryPoints . get ( jsTaskScheduler ) ;
44- assert . strictEqual ( testRunEntryPoint , jsTaskRunEntryPoint ) ;
43+ const testRunEntryPoints = asyncCallStacksData . schedulerToRunEntryPoints . get ( jsTaskScheduler ) ;
44+ assert . strictEqual ( testRunEntryPoints ?. length , 1 ) ;
45+ assert . strictEqual ( testRunEntryPoints ?. [ 0 ] , jsTaskRunEntryPoint ) ;
4546 } ) ;
4647
4748 it ( 'uses the nearest profile call ancestor of a debuggerTaskScheduled as JS task scheduler' , async function ( ) {
@@ -62,8 +63,9 @@ describe('AsyncJSCallsHandler', function() {
6263 const allEvents = [ ...rendererEvents , ...flowEvents ] ;
6364
6465 const asyncCallStacksData = await buildAsyncJSCallsHandlerData ( allEvents ) ;
65- const testRunEntryPoint = asyncCallStacksData . schedulerToRunEntryPoints . get ( jsTaskScheduler ) ;
66- assert . strictEqual ( testRunEntryPoint , jsTaskRunEntryPoint ) ;
66+ const testRunEntryPoints = asyncCallStacksData . schedulerToRunEntryPoints . get ( jsTaskScheduler ) ;
67+ assert . strictEqual ( testRunEntryPoints ?. length , 1 ) ;
68+ assert . strictEqual ( testRunEntryPoints ?. [ 0 ] , jsTaskRunEntryPoint ) ;
6769 } ) ;
6870
6971 it ( 'uses the nearest JS entry point descendant of a debuggerTaskRun as async task run' , async function ( ) {
@@ -85,8 +87,75 @@ describe('AsyncJSCallsHandler', function() {
8587 const allEvents = [ ...rendererEvents , ...flowEvents ] ;
8688
8789 const asyncCallStacksData = await buildAsyncJSCallsHandlerData ( allEvents ) ;
88- const testRunEntryPoint = asyncCallStacksData . schedulerToRunEntryPoints . get ( jsTaskScheduler ) ;
89- assert . strictEqual ( testRunEntryPoint , jsTaskRunEntryPoint ) ;
90+ const testRunEntryPoints = asyncCallStacksData . schedulerToRunEntryPoints . get ( jsTaskScheduler ) ;
91+ assert . strictEqual ( testRunEntryPoints ?. length , 1 ) ;
92+ assert . strictEqual ( testRunEntryPoints ?. [ 0 ] , jsTaskRunEntryPoint ) ;
93+ } ) ;
94+
95+ it ( 'falls back to a JS invocation as task scheduler if no profile call is found before in the debuggerTaskScheduled ancestors' ,
96+ async function ( ) {
97+ const jsTaskScheduler = makeCompleteEvent ( Trace . Types . Events . Name . FUNCTION_CALL , 0 , 30 , cat , tid , pid ) ;
98+ const asyncTaskScheduled =
99+ makeCompleteEvent ( Trace . Types . Events . Name . DEBUGGER_ASYNC_TASK_SCHEDULED , 0 , 0 , cat , pid , tid ) ;
100+
101+ const asyncTaskRun =
102+ makeCompleteEvent ( Trace . Types . Events . Name . DEBUGGER_ASYNC_TASK_RUN , 60 , 100 , cat , tid , pid ) ;
103+
104+ // Two JS entry points belonging to the same subtree are
105+ // descendants to the debuggerTaskRun event. Test the one closest
106+ // to the debuggerTaskRun in the global tree is picked.
107+ const jsTaskRunEntryPoint = makeCompleteEvent ( Trace . Types . Events . Name . FUNCTION_CALL , 70 , 20 , cat , tid , pid ) ;
108+ const secondFakeEntryPoint = makeCompleteEvent ( Trace . Types . Events . Name . FUNCTION_CALL , 71 , 10 , cat , tid , pid ) ;
109+
110+ const flowEvents = makeFlowEvents ( [ asyncTaskScheduled , asyncTaskRun ] ) ;
111+ const rendererEvents =
112+ [ jsTaskScheduler , asyncTaskScheduled , asyncTaskRun , jsTaskRunEntryPoint , secondFakeEntryPoint ] ;
113+ const allEvents = [ ...rendererEvents , ...flowEvents ] ;
114+
115+ const asyncCallStacksData = await buildAsyncJSCallsHandlerData ( allEvents ) ;
116+ const testRunEntryPoints = asyncCallStacksData . schedulerToRunEntryPoints . get ( jsTaskScheduler ) ;
117+ assert . strictEqual ( testRunEntryPoints ?. length , 1 ) ;
118+ assert . strictEqual ( testRunEntryPoints ?. [ 0 ] , jsTaskRunEntryPoint ) ;
119+ } ) ;
120+
121+ it ( 'returns multiple JS entry points when scheduled by the same function' , async function ( ) {
122+ const jsTaskScheduler = makeCompleteEvent ( Trace . Types . Events . Name . FUNCTION_CALL , 0 , 30 , cat , tid , pid ) ;
123+ // Two asyncTaskScheduled events right under the function call.
124+ const asyncTaskScheduled1 =
125+ makeCompleteEvent ( Trace . Types . Events . Name . DEBUGGER_ASYNC_TASK_SCHEDULED , 0 , 0 , cat , pid , tid ) ;
126+
127+ const asyncTaskScheduled2 =
128+ makeCompleteEvent ( Trace . Types . Events . Name . DEBUGGER_ASYNC_TASK_SCHEDULED , 10 , 0 , cat , pid , tid ) ;
129+
130+ const asyncTaskRun1 = makeCompleteEvent ( Trace . Types . Events . Name . DEBUGGER_ASYNC_TASK_RUN , 60 , 100 , cat , tid , pid ) ;
131+
132+ const asyncTaskRun2 = makeCompleteEvent ( Trace . Types . Events . Name . DEBUGGER_ASYNC_TASK_RUN , 200 , 100 , cat , tid , pid ) ;
133+
134+ // Two JS entry points,
135+ const firstJSTaskRunEntryPoint = makeCompleteEvent ( Trace . Types . Events . Name . FUNCTION_CALL , 70 , 20 , cat , tid , pid ) ;
136+ const secondJSTaskRunEntryPoint =
137+ makeCompleteEvent ( Trace . Types . Events . Name . FUNCTION_CALL , 210 , 10 , cat , tid , pid ) ;
138+
139+ const flow1Events = makeFlowEvents ( [ asyncTaskScheduled1 , asyncTaskRun1 ] , 1 ) ;
140+ const flow2Events = makeFlowEvents ( [ asyncTaskScheduled2 , asyncTaskRun2 ] , 2 ) ;
141+ const flowEvents = [ ...flow1Events , ...flow2Events ] . sort ( ( a , b ) => a . ts - b . ts ) ;
142+ const rendererEvents = [
143+ jsTaskScheduler ,
144+ asyncTaskScheduled1 ,
145+ asyncTaskRun1 ,
146+ asyncTaskScheduled2 ,
147+ firstJSTaskRunEntryPoint ,
148+ asyncTaskRun2 ,
149+ secondJSTaskRunEntryPoint ,
150+ ] ;
151+ const allEvents = [ ...rendererEvents , ...flowEvents ] ;
152+
153+ const asyncCallStacksData = await buildAsyncJSCallsHandlerData ( allEvents ) ;
154+
155+ const testRunEntryPoints = asyncCallStacksData . schedulerToRunEntryPoints . get ( jsTaskScheduler ) ;
156+ assert . strictEqual ( testRunEntryPoints ?. length , 2 ) ;
157+ assert . strictEqual ( testRunEntryPoints ?. [ 0 ] , firstJSTaskRunEntryPoint ) ;
158+ assert . strictEqual ( testRunEntryPoints ?. [ 1 ] , secondJSTaskRunEntryPoint ) ;
90159 } ) ;
91160 } ) ;
92161 describe ( 'Resolving async JS tasks to schedulers' , function ( ) {
0 commit comments