-
Notifications
You must be signed in to change notification settings - Fork 3
/
test-large-files.js
95 lines (89 loc) · 2.14 KB
/
test-large-files.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
require('should');
var async = require('async');
var Vagrant = require('node-vagrant-bin');
var pwd = {};
if( process.env['TRAVIS'] )
pwd = require('./test/travis-ssh.json');
else
pwd = require('./test/vagrant-ssh.json');
var SSH2Utils = require('./index.js');
var ssh = new SSH2Utils();
var hostPwd = {
'host':'127.0.0.1',
port: pwd.localhostpwd.port || 22,
username: pwd.localhostpwd.user,
password: pwd.localhostpwd.pwd || undefined
};
var prepareBox = function(done){
var cmds = [
'rm -fr /home/vagrant/sample.txt',
//'dd if=/dev/urandom of=/home/vagrant/sample.txt bs=1M count=1',
'yes 123456789 | head -1677772 > /home/vagrant/sample.txt',
'echo end >> /home/vagrant/sample.txt',
'ls -alh /home/vagrant/sample.txt'
];
ssh.exec(hostPwd, cmds, function(err,stdout,stderr,server,conn){
if(err) console.error(err);
conn.end();
done();
});
};
var readUsingAStream = function(done){
ssh.streamReadFile(hostPwd, '/home/vagrant/sample.txt', function(err, stream,server,conn){
if(err) console.error(err);
stream.on('data', function(){});
stream.on('close', function(){
conn.end();
done();
});
});
};
var readUsingExec = function(done){
ssh.streamReadFileSudo(hostPwd, '/home/vagrant/sample.txt', function(err, stream,server,conn){
if(err) console.error(err);
stream.on('close', function(){
conn.end();
done();
});
});
};
var t0;
var t1;
var t2;
var t3;
async.series([
function(next){
var vagrant = new Vagrant();
vagrant.isRunning(function(running){
if(running===false){
vagrant.up('precise64',function(err,booted){
next();
});
}else{
next();
}
});
},
function(next){
t0 = Date.now();
prepareBox(function(){
t1 = Date.now();
console.log('boot %s ms', t1-t0);
next();
});
},
function(next){
readUsingAStream(function(){
t2 = Date.now();
console.log('readUsingAStream %s ms', t2-t1);
next();
});
},
function(next){
readUsingExec(function(){
t3 = Date.now();
console.log('readUsingExec %s ms', t3-t2);
next();
});
}
]);