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

144 lines
5.1 KiB
JavaScript
Raw Normal View History

2016-01-10 23:32:46 +11:00
/*global describe, expect, it*/
2016-01-10 20:03:05 +11:00
'use strict';
const ipc = require('../../../../node-ipc');
const os = require('os').platform();
2016-01-10 18:23:40 +11:00
describe('TCP Socket verification of client',
2016-01-10 22:02:36 +11:00
function TCPClientSpec(){
var windows_delay = 0;
if(os === "win32") {
windows_delay = 4000;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
}
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 23:57:08 +11:00
function testIt(done){
ipc.config.id ='testClient';
2016-09-30 23:00:28 +10:00
ipc.config.retry = 60;
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,
2016-01-10 23:18:14 +11:00
function open(){
2016-01-10 22:02:36 +11:00
ipc.of.tcpFakeServer.on(
'error',
function gotError(err){
errorCount++;
expect(ipc.of.tcpFakeServer.retriesRemaining).toBe(
ipc.config.maxRetries-errorCount
);
2016-01-10 23:37:52 +11:00
expect(err).toBeDefined();
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 + windows_delay
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);
2016-01-10 23:37:52 +11:00
expect(err).toBeDefined();
2016-01-10 22:02:36 +11:00
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 + windows_delay
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',
2016-01-10 23:57:08 +11:00
function gotMessage(data){
2016-01-10 21:46:09 +11:00
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
}
);