|
| 1 | +'use strict'; |
| 2 | +constcommon=require('../common'); |
| 3 | +consttmpdir=require('../common/tmpdir'); |
| 4 | +tmpdir.refresh(); |
| 5 | + |
| 6 | +if(!common.enoughTestCpu) |
| 7 | +common.skip('test is CPU-intensive'); |
| 8 | + |
| 9 | +if(common.isCPPSymbolsNotMapped){ |
| 10 | +common.skip('C++ symbols are not mapped for this OS.'); |
| 11 | +} |
| 12 | + |
| 13 | +// This test will produce a broken profile log. |
| 14 | +// ensure prof-polyfill not stuck in infinite loop |
| 15 | +// and success process |
| 16 | + |
| 17 | + |
| 18 | +constassert=require('assert'); |
| 19 | +constcp=require('child_process'); |
| 20 | +constpath=require('path'); |
| 21 | +constfs=require('fs'); |
| 22 | + |
| 23 | +constLOG_FILE=path.join(tmpdir.path,'tick-processor.log'); |
| 24 | +constRETRY_TIMEOUT=150; |
| 25 | +constBROKEN_PART='tick,'; |
| 26 | +constWARN_REG_EXP=/\(node:\d+\)\[BROKEN_PROFILE_FILE]Warning:Profilefile.*isbroken/; |
| 27 | +constWARN_DETAIL_REG_EXP=/".*tick,"atthefileendisbroken/; |
| 28 | + |
| 29 | +constcode=`function f() { |
| 30 | + this.ts = Date.now(); |
| 31 | + setImmediate(function() { new f(); }); |
| 32 | + }; |
| 33 | + f();`; |
| 34 | + |
| 35 | +constproc=cp.spawn(process.execPath,[ |
| 36 | +'--no_logfile_per_isolate', |
| 37 | +'--logfile=-', |
| 38 | +'--prof', |
| 39 | +'-pe',code |
| 40 | +],{ |
| 41 | +stdio: ['ignore','pipe','inherit'] |
| 42 | +}); |
| 43 | + |
| 44 | +letticks=''; |
| 45 | +proc.stdout.on('data',(chunk)=>ticks+=chunk); |
| 46 | + |
| 47 | + |
| 48 | +functionrunPolyfill(content){ |
| 49 | +proc.kill(); |
| 50 | +content+=BROKEN_PART; |
| 51 | +fs.writeFileSync(LOG_FILE,content); |
| 52 | +constchild=cp.spawnSync( |
| 53 | +`${process.execPath}`, |
| 54 | +[ |
| 55 | +'--prof-process',LOG_FILE |
| 56 | +]); |
| 57 | +assert(WARN_REG_EXP.test(child.stderr.toString())); |
| 58 | +assert(WARN_DETAIL_REG_EXP.test(child.stderr.toString())); |
| 59 | +assert.strictEqual(child.status,0); |
| 60 | +} |
| 61 | + |
| 62 | +setTimeout(()=>runPolyfill(ticks),RETRY_TIMEOUT); |
0 commit comments