mirror of https://github.com/lukechilds/node.git
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.
86 lines
2.6 KiB
86 lines
2.6 KiB
14 years ago
|
// Copyright Joyent, Inc. and other Node contributors.
|
||
|
//
|
||
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
||
|
// copy of this software and associated documentation files (the
|
||
|
// "Software"), to deal in the Software without restriction, including
|
||
|
// without limitation the rights to use, copy, modify, merge, publish,
|
||
|
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
||
|
// persons to whom the Software is furnished to do so, subject to the
|
||
|
// following conditions:
|
||
|
//
|
||
|
// The above copyright notice and this permission notice shall be included
|
||
|
// in all copies or substantial portions of the Software.
|
||
|
//
|
||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
||
|
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||
|
|
||
14 years ago
|
|
||
14 years ago
|
var common = require('../common');
|
||
|
var assert = require('assert');
|
||
15 years ago
|
|
||
15 years ago
|
var count = 100;
|
||
|
var fs = require('fs');
|
||
15 years ago
|
|
||
13 years ago
|
// person.jpg is 57kb. We just need some file that is sufficently large.
|
||
|
var filename = require('path').join(common.fixturesDir, 'person.jpg');
|
||
|
|
||
15 years ago
|
function tryToKillEventLoop() {
|
||
15 years ago
|
console.log('trying to kill event loop ...');
|
||
15 years ago
|
|
||
14 years ago
|
fs.stat(__filename, function(err) {
|
||
15 years ago
|
if (err) {
|
||
14 years ago
|
throw new Exception('first fs.stat failed');
|
||
15 years ago
|
} else {
|
||
14 years ago
|
fs.stat(__filename, function(err) {
|
||
15 years ago
|
if (err) {
|
||
14 years ago
|
throw new Exception('second fs.stat failed');
|
||
15 years ago
|
} else {
|
||
15 years ago
|
console.log('could not kill event loop, retrying...');
|
||
15 years ago
|
|
||
14 years ago
|
setTimeout(function() {
|
||
15 years ago
|
if (--count) {
|
||
|
tryToKillEventLoop();
|
||
|
} else {
|
||
13 years ago
|
console.log('done trying to kill event loop');
|
||
15 years ago
|
process.exit(0);
|
||
|
}
|
||
|
}, 1);
|
||
15 years ago
|
}
|
||
|
});
|
||
|
}
|
||
|
});
|
||
15 years ago
|
}
|
||
|
|
||
|
// Generate a lot of thread pool events
|
||
|
var pos = 0;
|
||
13 years ago
|
fs.open(filename, 'r', 0666, function(err, fd) {
|
||
15 years ago
|
if (err) throw err;
|
||
|
|
||
14 years ago
|
function readChunk() {
|
||
13 years ago
|
fs.read(fd, 1024, 0, 'binary', function(err, chunk, bytesRead) {
|
||
15 years ago
|
if (err) throw err;
|
||
15 years ago
|
if (chunk) {
|
||
|
pos += bytesRead;
|
||
15 years ago
|
//console.log(pos);
|
||
15 years ago
|
readChunk();
|
||
|
} else {
|
||
15 years ago
|
fs.closeSync(fd);
|
||
13 years ago
|
throw new Exception("Shouldn't get EOF");
|
||
15 years ago
|
}
|
||
|
});
|
||
|
}
|
||
|
readChunk();
|
||
|
});
|
||
|
|
||
|
tryToKillEventLoop();
|
||
|
|
||
13 years ago
|
process.on('exit', function() {
|
||
13 years ago
|
console.log('done with test');
|
||
15 years ago
|
assert.ok(pos > 10000);
|
||
|
});
|