2010-03-09 00:06:29 +01:00
|
|
|
require('../common');
|
2010-03-03 12:39:41 +01:00
|
|
|
|
|
|
|
var
|
2010-03-08 19:02:19 +01:00
|
|
|
path = require('path'),
|
|
|
|
fs = require('fs'),
|
2010-04-03 01:02:48 +02:00
|
|
|
fn = path.join(fixturesDir, 'test_ca.pem'),
|
2010-03-05 18:56:25 +01:00
|
|
|
file = fs.createReadStream(fn),
|
2010-03-03 12:39:41 +01:00
|
|
|
|
|
|
|
callbacks = {
|
|
|
|
open: -1,
|
|
|
|
end: -1,
|
2010-03-07 16:33:21 +01:00
|
|
|
close: -1,
|
2010-04-08 19:44:22 +02:00
|
|
|
destroy: -1
|
2010-03-03 12:39:41 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
paused = false,
|
|
|
|
|
|
|
|
fileContent = '';
|
|
|
|
|
|
|
|
file
|
|
|
|
.addListener('open', function(fd) {
|
|
|
|
callbacks.open++;
|
|
|
|
assert.equal('number', typeof fd);
|
|
|
|
assert.ok(file.readable);
|
|
|
|
})
|
|
|
|
.addListener('error', function(err) {
|
|
|
|
throw err;
|
|
|
|
})
|
|
|
|
.addListener('data', function(data) {
|
|
|
|
assert.ok(!paused);
|
|
|
|
fileContent += data;
|
|
|
|
|
|
|
|
paused = true;
|
|
|
|
file.pause();
|
|
|
|
assert.ok(file.paused);
|
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
paused = false;
|
|
|
|
file.resume();
|
|
|
|
assert.ok(!file.paused);
|
|
|
|
}, 10);
|
|
|
|
})
|
|
|
|
.addListener('end', function(chunk) {
|
|
|
|
callbacks.end++;
|
|
|
|
})
|
|
|
|
.addListener('close', function() {
|
|
|
|
callbacks.close++;
|
|
|
|
assert.ok(!file.readable);
|
|
|
|
|
|
|
|
assert.equal(fs.readFileSync(fn), fileContent);
|
|
|
|
});
|
|
|
|
|
2010-03-07 16:33:21 +01:00
|
|
|
var file2 = fs.createReadStream(fn);
|
2010-04-08 19:44:22 +02:00
|
|
|
file2.destroy(function(err) {
|
2010-03-07 16:33:21 +01:00
|
|
|
assert.ok(!err);
|
2010-04-08 19:44:22 +02:00
|
|
|
callbacks.destroy++;
|
2010-03-07 16:33:21 +01:00
|
|
|
});
|
|
|
|
|
2010-03-03 12:39:41 +01:00
|
|
|
process.addListener('exit', function() {
|
|
|
|
for (var k in callbacks) {
|
|
|
|
assert.equal(0, callbacks[k], k+' count off by '+callbacks[k]);
|
|
|
|
}
|
2010-03-20 03:22:04 +01:00
|
|
|
});
|