node-ipc/spec/support/jasmineTest/TCP/tcpSocketClient.spec.js

132 lines
4.7 KiB
JavaScript
Raw Normal View History

2016-01-10 20:03:05 +11:00
'use strict';
const ipc = require('../../../../node-ipc');
2016-01-10 18:23:40 +11:00
describe('TCP Socket verification of client',
2016-01-10 22:02:36 +11:00
function TCPClientSpec(){
2016-01-10 21:46:09 +11:00
it(
'Verify retry attempts by TCP client to connect to the server as per the value set in "maxRetries" parameter.',
2016-01-10 21:46:09 +11:00
function(done){
ipc.config.id ='testClient';
ipc.config.retry = 600;
2016-01-10 21:46:09 +11:00
ipc.config.maxRetries = 3;
ipc.config.stopRetrying = false;
2016-01-10 18:23:40 +11:00
2016-01-10 22:02:36 +11:00
//set to -1 because there is an error on the first fail
//before retrying
let errorCount=-1;
2016-01-10 21:46:09 +11:00
ipc.connectToNet(
'tcpFakeServer',
2016-01-10 22:02:36 +11:00
8002,
function(){
ipc.of.tcpFakeServer.on(
'error',
function gotError(err){
errorCount++;
expect(ipc.of.tcpFakeServer.retriesRemaining).toBe(
ipc.config.maxRetries-errorCount
);
2016-01-10 21:46:09 +11:00
}
);
2016-01-10 22:02:36 +11:00
}
2016-01-10 21:46:09 +11:00
);
setTimeout(
2016-01-10 22:02:36 +11:00
function testDelay(){
expect(errorCount).toBe(ipc.config.maxRetries);
ipc.disconnect('tcpFakeServer');
done();
},
ipc.config.retry*ipc.config.maxRetries +
ipc.config.retry+ipc.config.retry
2016-01-10 21:46:09 +11:00
);
2016-01-10 22:02:36 +11:00
2016-01-10 21:46:09 +11:00
}
);
2016-01-10 21:46:09 +11:00
it(
'Verify TCP client does not connect to the TCPserver when "stopRetrying" value is set to true.',
2016-01-10 22:02:36 +11:00
function testIt(done){
2016-01-10 21:46:09 +11:00
ipc.config.maxRetries = 3;
ipc.config.stopRetrying = true;
2016-01-10 22:02:36 +11:00
ipc.silent=true;
//set to -1 because there is an error on the first fail
//before retrying
let errorCount=-1;
2016-01-10 21:46:09 +11:00
ipc.connectToNet(
'tcpFakeServer',
2016-01-10 22:02:36 +11:00
8002,
function open(){
ipc.of.tcpFakeServer.on(
'error',
function gotError(err){
expect(ipc.of.tcpFakeServer.retriesRemaining).toBe(ipc.config.maxRetries);
errorCount++;
2016-01-10 21:46:09 +11:00
}
);
2016-01-10 22:02:36 +11:00
}
2016-01-10 21:46:09 +11:00
);
setTimeout(
2016-01-10 22:02:36 +11:00
function testDelay(){
expect(errorCount).toBe(0);
expect(ipc.of.tcpFakeServer.retriesRemaining).toBe(ipc.config.maxRetries);
ipc.disconnect('tcpFakeServer');
done();
},
ipc.config.retry*ipc.config.maxRetries
2016-01-10 21:46:09 +11:00
);
}
);
2016-01-10 18:23:40 +11:00
2016-01-10 21:46:09 +11:00
it(
'Verify TCP client connects to server named "tcpServer" and receives message.',
2016-01-10 22:02:36 +11:00
function testIt(done){
2016-01-10 21:46:09 +11:00
ipc.connectToNet(
'tcpServer',
8300,
2016-01-10 22:02:36 +11:00
function open(){
2016-01-10 21:46:09 +11:00
ipc.of.tcpServer.on(
'connect',
2016-01-10 22:02:36 +11:00
function connected(){
ipc.of.tcpServer.on(
2016-01-10 21:46:09 +11:00
'message',
function(data,socket){
expect(data.id).toBe('tcpServer');
expect(data.message).toBe('I am TCP server!');
2016-01-10 22:02:36 +11:00
testDone();
}
);
2016-01-10 18:23:40 +11:00
2016-01-10 22:02:36 +11:00
ipc.of.tcpServer.emit(
2016-01-10 21:46:09 +11:00
'message',
2016-01-10 22:02:36 +11:00
{
id : ipc.config.id,
message : 'Hello from testClient.'
2016-01-10 21:46:09 +11:00
}
);
2016-01-10 22:02:36 +11:00
}
);
2016-01-10 18:23:40 +11:00
2016-01-10 22:02:36 +11:00
ipc.of.tcpServer.on(
'error',
function testError(err){
expect(err).toBe(false);
testDone();
2016-01-10 21:46:09 +11:00
}
);
2016-01-10 22:02:36 +11:00
}
2016-01-10 21:46:09 +11:00
);
2016-01-10 22:02:36 +11:00
function testDone(){
ipc.disconnect('tcpServer');
done();
}
2016-01-10 21:46:09 +11:00
}
);
2016-01-10 22:02:36 +11:00
}
);