11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciconst assert = require('assert'); 51cb0ef41Sopenharmony_ciconst tick = require('../common/tick'); 61cb0ef41Sopenharmony_ciconst initHooks = require('./init-hooks'); 71cb0ef41Sopenharmony_ciconst { checkInvocations } = require('./hook-checks'); 81cb0ef41Sopenharmony_ciconst fs = require('fs'); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciif (!common.isMainThread) 111cb0ef41Sopenharmony_ci common.skip('Worker bootstrapping works differently -> different async IDs'); 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ciconst hooks = initHooks(); 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_cihooks.enable(); 161cb0ef41Sopenharmony_cifs.readFile(__filename, common.mustCall(onread)); 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_cifunction onread() { 191cb0ef41Sopenharmony_ci const as = hooks.activitiesOfTypes('FSREQCALLBACK'); 201cb0ef41Sopenharmony_ci let lastParent = 1; 211cb0ef41Sopenharmony_ci for (let i = 0; i < as.length; i++) { 221cb0ef41Sopenharmony_ci const a = as[i]; 231cb0ef41Sopenharmony_ci assert.strictEqual(a.type, 'FSREQCALLBACK'); 241cb0ef41Sopenharmony_ci assert.strictEqual(typeof a.uid, 'number'); 251cb0ef41Sopenharmony_ci assert.strictEqual(a.triggerAsyncId, lastParent); 261cb0ef41Sopenharmony_ci lastParent = a.uid; 271cb0ef41Sopenharmony_ci } 281cb0ef41Sopenharmony_ci checkInvocations(as[0], { init: 1, before: 1, after: 1, destroy: 1 }, 291cb0ef41Sopenharmony_ci 'reqwrap[0]: while in onread callback'); 301cb0ef41Sopenharmony_ci checkInvocations(as[1], { init: 1, before: 1, after: 1, destroy: 1 }, 311cb0ef41Sopenharmony_ci 'reqwrap[1]: while in onread callback'); 321cb0ef41Sopenharmony_ci checkInvocations(as[2], { init: 1, before: 1, after: 1, destroy: 1 }, 331cb0ef41Sopenharmony_ci 'reqwrap[2]: while in onread callback'); 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ci // This callback is called from within the last fs req callback therefore 361cb0ef41Sopenharmony_ci // the last req is still going and after/destroy haven't been called yet 371cb0ef41Sopenharmony_ci checkInvocations(as[3], { init: 1, before: 1 }, 381cb0ef41Sopenharmony_ci 'reqwrap[3]: while in onread callback'); 391cb0ef41Sopenharmony_ci tick(2); 401cb0ef41Sopenharmony_ci} 411cb0ef41Sopenharmony_ci 421cb0ef41Sopenharmony_ciprocess.on('exit', onexit); 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_cifunction onexit() { 451cb0ef41Sopenharmony_ci hooks.disable(); 461cb0ef41Sopenharmony_ci hooks.sanityCheck('FSREQCALLBACK'); 471cb0ef41Sopenharmony_ci const as = hooks.activitiesOfTypes('FSREQCALLBACK'); 481cb0ef41Sopenharmony_ci const a = as.pop(); 491cb0ef41Sopenharmony_ci checkInvocations(a, { init: 1, before: 1, after: 1, destroy: 1 }, 501cb0ef41Sopenharmony_ci 'when process exits'); 511cb0ef41Sopenharmony_ci} 52