1 // In these tests, we do the following:
2 // try for 200ms (rt=2)
4 // try for 200ms (rt=1)
6 // try for 200ms (rt=0)
8 // Actual time will be more like 1220-ish for setTimeout irregularity
9 // But it should NOT be as slow as 2000.
11 var lockFile = require('../')
12 var touch = require('touch')
13 var test = require('tap').test
14 var fs = require('fs')
19 var EXPECTTIME = (RETRYWAIT * RETRIES) + (WAIT * (RETRIES + 1))
20 var TOOLONG = EXPECTTIME * 1.1
22 test('setup', function (t) {
23 touch.sync('file.lock')
27 var pollPeriods = [10, 100, 10000]
28 pollPeriods.forEach(function (pp) {
29 test('retry+wait, poll=' + pp, function (t) {
31 var timer = setTimeout(function() {
32 t.fail('taking too long!')
38 var start = Date.now()
39 lockFile.lock('file.lock', {
46 var time = Date.now() - start
47 console.error('t=%d', time)
48 t.ok(time >= EXPECTTIME, 'should take at least ' + EXPECTTIME)
49 t.ok(time < TOOLONG, 'should take less than ' + TOOLONG)
56 test('cleanup', function (t) {
57 fs.unlinkSync('file.lock')
59 setTimeout(function() {