Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
(error, connection) => {
test.assertNot(error, 'must connect to server and perform handshake');
connection.on('error', () => {
// dismiss
});
server.kill('SIGTERM');
connection.on('reconnectAttempt', () => {
test.pass('must attempt to reconnect');
});
setTimeout(() => {
connection.close();
}, WAITING_TIME);
}
);
(err, connection) => {
test.assertNot(err, 'must connect successfully');
test.assert(
net.isIP(connection.remoteAddress),
'remoteAddress must be an IP address'
);
connection.close();
server.close();
}
);
(error, connection) => {
tap.assertNot(error, 'client must connect successfully');
connection.close();
setTimeout(() => {
server.close();
}, HANDSHAKE_TIMEOUT + 100);
}
);
(error, conn) => {
test.assertNot(error, 'must connect to server and perform handshake');
connection = conn;
done();
}
);
'use strict';
const test = require('tap');
const jstp = require('../..');
const app = new jstp.Application('name', {});
const server = jstp.net.createServer([app]);
test.assertNot(
server.address(),
'must return null address if server is not listening'
);
server.listen(() => {
const port = server.address().port;
test.ok(
port > 0 && port < 65536,
'must return correct port number upon listening'
);
server.close();
});
jstp.net.connect(appName, client, port, 'localhost', (error, connection) => {
test.assertNot(error, 'must connect to server');
const serverConnection = server.getClientsArray()[0];
connection.close();
serverConnection.callMethodWithResend('iface', 'method', [], error => {
test.assertNot(error, 'must not return an error');
connection.close();
server.close();
test.end();
});
const port = server.address().port;
client.session = connection.session;
jstp.net.reconnect(connection, port, 'localhost', (error, conn) => {
test.assertNot(error, 'must reconnect to server');
let triedToUnlink = false;
server.on('close', () => {
fs.unlink(config.path, () => {
triedToUnlink = true;
});
});
process.on('exit', () => {
if (!triedToUnlink) {
fs.unlinkSync(config.path);
}
});
test.assertNot(
server.address(),
'must return null address if server is not listening'
);
server.listen(config.path, () => {
test.strictEqual(
server.address(),
config.path,
'must return correct path address upon listening'
);
server.close();
});
jstp.net.reconnect(connection, port, 'localhost', (error, conn) => {
test.assertNot(error, 'must reconnect to server');
connection = conn;
});
});
(error, connection, api) => {
test.assertNot(error, 'must connect to server');
connection.close();
api.iface.method(error => {
test.assertNot(error, 'must not return an error');
connection.close();
server.close();
}, true);
const port = server.address().port;
jstp.net.reconnect(connection, port, 'localhost', (error, conn) => {
test.assertNot(error, 'must reconnect to server');
connection = conn;
});
}
);
(error, conn) => {
test.assertNot(error, 'must connect to server and perform handshake');
connection = conn;
done();
}
);