| Server IP : 185.11.201.71 / Your IP : 192.168.7.18 Web Server : Apache/2.4.29 (Ubuntu) System : Linux tech-virtual-machine 4.15.0-213-generic #224-Ubuntu SMP Mon Jun 19 13:30:12 UTC 2023 x86_64 User : tech ( 1000) PHP Version : 7.4.28 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/share/npm/node_modules/lockfile/test/ |
Upload File : |
// In these tests, we do the following:
// try for 200ms (rt=2)
// wait for 300ms
// try for 200ms (rt=1)
// wait for 300ms
// try for 200ms (rt=0)
// fail after 1200
// Actual time will be more like 1220-ish for setTimeout irregularity
// But it should NOT be as slow as 2000.
var lockFile = require('../')
var touch = require('touch')
var test = require('tap').test
var fs = require('fs')
var RETRYWAIT = 100
var WAIT = 100
var RETRIES = 2
var EXPECTTIME = (RETRYWAIT * RETRIES) + (WAIT * (RETRIES + 1))
var TOOLONG = EXPECTTIME * 1.1
test('setup', function (t) {
touch.sync('file.lock')
t.end()
})
var pollPeriods = [10, 100, 10000]
pollPeriods.forEach(function (pp) {
test('retry+wait, poll=' + pp, function (t) {
var ended = false
var timer = setTimeout(function() {
t.fail('taking too long!')
ended = true
t.end()
}, 2000)
timer.unref()
var start = Date.now()
lockFile.lock('file.lock', {
wait: WAIT,
retries: RETRIES,
retryWait: RETRYWAIT,
pollPeriod: pp
}, function (er) {
if (ended) return
var time = Date.now() - start
console.error('t=%d', time)
t.ok(time >= EXPECTTIME, 'should take at least ' + EXPECTTIME)
t.ok(time < TOOLONG, 'should take less than ' + TOOLONG)
clearTimeout(timer)
t.end()
})
})
})
test('cleanup', function (t) {
fs.unlinkSync('file.lock')
t.end()
setTimeout(function() {
process.exit(1)
}, 500).unref()
})