You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.1 KiB

  1. var mkdirp = require('../').mkdirp;
  2. var path = require('path');
  3. var fs = require('fs');
  4. var test = require('tap').test;
  5. test('race', function (t) {
  6. t.plan(4);
  7. var ps = [ '', 'tmp' ];
  8. for (var i = 0; i < 25; i++) {
  9. var dir = Math.floor(Math.random() * Math.pow(16,4)).toString(16);
  10. ps.push(dir);
  11. }
  12. var file = ps.join('/');
  13. var res = 2;
  14. mk(file, function () {
  15. if (--res === 0) t.end();
  16. });
  17. mk(file, function () {
  18. if (--res === 0) t.end();
  19. });
  20. function mk (file, cb) {
  21. mkdirp(file, 0755, function (err) {
  22. if (err) t.fail(err);
  23. else path.exists(file, function (ex) {
  24. if (!ex) t.fail('file not created')
  25. else fs.stat(file, function (err, stat) {
  26. if (err) t.fail(err)
  27. else {
  28. t.equal(stat.mode & 0777, 0755);
  29. t.ok(stat.isDirectory(), 'target not a directory');
  30. if (cb) cb();
  31. }
  32. })
  33. })
  34. });
  35. }
  36. });