PageRenderTime 34ms CodeModel.GetById 18ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/app/node_modules/jade/node_modules/mkdirp/test/race.js

https://bitbucket.org/jorritposthuma/inventory-counter-mobile
JavaScript | 41 lines | 36 code | 5 blank | 0 comment | 10 complexity | 009053221aaea15a1cd91315df02c692 MD5 | raw file
Possible License(s): MIT, Apache-2.0
 1var mkdirp = require('../').mkdirp;
 2var path = require('path');
 3var fs = require('fs');
 4var test = require('tap').test;
 5
 6test('race', function (t) {
 7    t.plan(4);
 8    var ps = [ '', 'tmp' ];
 9    
10    for (var i = 0; i < 25; i++) {
11        var dir = Math.floor(Math.random() * Math.pow(16,4)).toString(16);
12        ps.push(dir);
13    }
14    var file = ps.join('/');
15    
16    var res = 2;
17    mk(file, function () {
18        if (--res === 0) t.end();
19    });
20    
21    mk(file, function () {
22        if (--res === 0) t.end();
23    });
24    
25    function mk (file, cb) {
26        mkdirp(file, 0755, function (err) {
27            if (err) t.fail(err);
28            else path.exists(file, function (ex) {
29                if (!ex) t.fail('file not created')
30                else fs.stat(file, function (err, stat) {
31                    if (err) t.fail(err)
32                    else {
33                        t.equal(stat.mode & 0777, 0755);
34                        t.ok(stat.isDirectory(), 'target not a directory');
35                        if (cb) cb();
36                    }
37                })
38            })
39        });
40    }
41});