|
| 1 | +var assert = require('assert'); |
| 2 | +var fs = require('fs'); |
| 3 | +var path = require('path'); |
| 4 | +var nw = require('./nw'); |
| 5 | + |
| 6 | +describe('fd-limit', function() { |
| 7 | + |
| 8 | + describe('file descriptor limit', function() { |
| 9 | + |
| 10 | + before(function(done) { |
| 11 | + this.timeout(5000); |
| 12 | + fs.mkdir('testfiles', function(err) { |
| 13 | + if (err) throw err; |
| 14 | + var n = 0; |
| 15 | + (function next() { |
| 16 | + fs.writeFile('testfiles/' + n + '.json', JSON.stringify({i: n}), function(err) { |
| 17 | + if (err) throw err; |
| 18 | + |
| 19 | + if (++n === 2000) { |
| 20 | + done(); |
| 21 | + } else { |
| 22 | + next(); |
| 23 | + } |
| 24 | + }); |
| 25 | + }()); |
| 26 | + }); |
| 27 | + }); |
| 28 | + |
| 29 | + after(function(done) { |
| 30 | + this.timeout(5000); |
| 31 | + var n = 0; |
| 32 | + (function next() { |
| 33 | + fs.unlink('testfiles/' + n + '.json', function(err) { |
| 34 | + if (err) throw err; |
| 35 | + |
| 36 | + if (++n === 2000) { |
| 37 | + fs.rmdir('testfiles', function(err){ |
| 38 | + if (err) throw err; |
| 39 | + done(); |
| 40 | + }); |
| 41 | + } else { |
| 42 | + next(); |
| 43 | + } |
| 44 | + }); |
| 45 | + }()); |
| 46 | + }); |
| 47 | + |
| 48 | + it('fetches 2k files via XHR should succeed with --file-descriptor-limit=8192', function(done) { |
| 49 | + if (process.platform === 'win32') { |
| 50 | + assert.equal(true, true); |
| 51 | + done(); |
| 52 | + } |
| 53 | + |
| 54 | + this.timeout(5000); |
| 55 | + |
| 56 | + nw.spawn(['test_app', '--file-descriptor-limit=8192'], function(err, data) { |
| 57 | + if (err) throw err; |
| 58 | + assert.equal(data.ok, true); |
| 59 | + done(); |
| 60 | + }); |
| 61 | + |
| 62 | + }); |
| 63 | + |
| 64 | + it('fetches 2k files via XHR should fail with --file-descriptor-limit=100', function(done) { |
| 65 | + if (process.platform === 'win32') { |
| 66 | + assert.equal(true, true); |
| 67 | + done(); |
| 68 | + } |
| 69 | + |
| 70 | + this.timeout(5000); |
| 71 | + |
| 72 | + nw.spawn(['test_app', '--file-descriptor-limit=100'], function(err, data) { |
| 73 | + if (err) throw err; |
| 74 | + assert.equal(data.ok, false); |
| 75 | + done(); |
| 76 | + }); |
| 77 | + |
| 78 | + }); |
| 79 | + |
| 80 | + }); |
| 81 | + |
| 82 | +}); |
0 commit comments