1// Copyright Joyent, Inc. and other Node contributors. 2// 3// Permission is hereby granted, free of charge, to any person obtaining a 4// copy of this software and associated documentation files (the 5// "Software"), to deal in the Software without restriction, including 6// without limitation the rights to use, copy, modify, merge, publish, 7// distribute, sublicense, and/or sell copies of the Software, and to permit 8// persons to whom the Software is furnished to do so, subject to the 9// following conditions: 10// 11// The above copyright notice and this permission notice shall be included 12// in all copies or substantial portions of the Software. 13// 14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20// USE OR OTHER DEALINGS IN THE SOFTWARE. 21 22'use strict'; 23require('../common'); 24const assert = require('assert'); 25 26// This is the inverse of test-next-tick-starvation. it verifies 27// that process.nextTick will *always* come before other events 28 29let ran = false; 30let starved = false; 31const start = +new Date(); 32let timerRan = false; 33 34function spin() { 35 ran = true; 36 const now = +new Date(); 37 if (now - start > 100) { 38 console.log('The timer is starving, just as we planned.'); 39 starved = true; 40 41 // now let it out. 42 return; 43 } 44 45 process.nextTick(spin); 46} 47 48function onTimeout() { 49 if (!starved) throw new Error('The timer escaped!'); 50 console.log('The timer ran once the ban was lifted'); 51 timerRan = true; 52} 53 54spin(); 55setTimeout(onTimeout, 50); 56 57process.on('exit', function() { 58 assert.ok(ran); 59 assert.ok(starved); 60 assert.ok(timerRan); 61}); 62