Sunday, 30 April 2017

Test ssh2 client with jasmine it is completed

I'm trying to run ssh2 client using the ssh2 node package and test it with jasmine but seems the connection is opened, the command is executed on the target but the test is finished with timeout. What could be wrong in the following code:

it("connect ssh", function(done) {
    var Client = require('ssh2').Client;
    var conn = new Client();
    conn.on('ready', function() {
        console.log('Client :: ready');
        conn.exec('uptime', function(err, stream) {
            if (err) throw err;
            stream.on('close', function(code, signal) {
                console.log('Stream :: close :: code: ' + code + ', signal: ' + signal);
                conn.end();
            }).on('data', function(data) {
                console.log('STDOUT: ' + data);
            }).stderr.on('data', function(data) {
                console.log('STDERR: ' + data);
                done()
            });
        });
    }).on('close', function() {
        done(); 
        console.log("outer close") 
    }).connect({
        host: '10.100.102.102',
        port: 22,
        username: 'aaa',
        password: 'bbb',
        algorithms: {hmac: ['hmac-sha2-256', 'hmac-sha2-512', 'hmac-sha1', 'hmac-sha1-96']}
    });
}, 20000);

I'm running it under grunt environment and got the error:

Client :: ready
STDOUT:  07:47:27 up 3 days,  9:22,  1 users,  load average: 0.00, 0.03, 0.04

Stream :: close :: code: 0, signal: undefined
outer close
   √ connect ssh

>> Done!


Summary:

Suites:  1 of 1
Specs:   1 of 1
Expects: 1 (0 failures)
Finished in 6.449 seconds


>> An error was thrown in an afterAll
   Error: Timeout - Async callback was not invoked within timeout specified by j
asmine.DEFAULT_TIMEOUT_INTERVAL.
       at Timer.listOnTimeout timers.js:92:15

Warning: Task "jasmine_nodejs:testapi" failed. Use --force to continue.

Aborted due to warnings.



via Moti

No comments:

Post a Comment