<commit_before>var io = require('socket.io-client');
var util = require('../test/utils');
var faker = require('faker');
var async = require('async');


var device = process.argv[2] || 'dev1';

var address = '127.0.0.1:8888';


var _host = address.substr(0, address.indexOf(':'));
var _port = Number(address.substr(address.indexOf(':') + 1));

var _app = 'LISK:STALK_IO';

var _channel = 'channel_12345';

var user = {
  'A': _app,
  'D': device,
  'U': 'james',
  'PW': 'password',
  'DT': {'name': '<NAME>', 'tel': '010-1234-5678'}
};

var GLOBAL_SOCKET;
var CHANNEL_SOCKET;

async.series([

  function (callback) { // 사용자 정보 UPDATE

    util.post(_host, _port, '/user/update', user, function (err, data) {

      if (data.status == 'ok') {
        callback(null, data);
      } else {

        util.post(_host, _port, '/user/register', user, function (err, data) {
          if (data.status == 'ok') {
            callback(null, data);
          } else {
            callback(data.status, data.message);
          }
        });

      }
    });

  },
  function (callback) { // Global Socket 연결
    util.get(_host, _port, '/node/' + _app + '/' + user.U, function (err, data) {
      var query = 'A=' + user.A + '&U=' + user.U + '&D=' + user.D;
      GLOBAL_SOCKET = io.connect(data.result.server.url + '/global?' + query, util.socketOptions);
      GLOBAL_SOCKET.on('connect', function (data) {
        console.log('Glocal Socket 연결 ! ');
        callback(null);
      });
    });
  },
  function (callback) {

    util.get(_host, _port, '/node/' + _app + '/' + _channel, function (err, data) {

      var query = 'A=' + user.A + '&U=' + user.U + '&D=' + user.D + '&C=' + _channel + '&S=' + data.result.server.name;
      CHANNEL_SOCKET = io.connect(data.result.server.url + '/channel?' + query, util.socketOptions);

      CHANNEL_SOCKET.on('message', function (data) {
        console.info(' ** MESSAGE ** ', data);
      });

      CHANNEL_SOCKET.on('connect', function (data) {

        // channel 에 연결된 이후 john 을 추가 한다.
        CHANNEL_SOCKET.emit('channel.create', {U: 'james', DT: {text: 'ABCDE'}}, function (result) {

          setTimeout(function () {
            CHANNEL_SOCKET.emit('send', {'NM': 'message', 'DT': {'NO': 1, 'MG': faker.lorem.sentence()}});<commit_msg>fix test codes for relocating channel.create to global socket handler.<commit_after>var io = require('socket.io-client');
var util = require('../test/utils');
var faker = require('faker');
var async = require('async');


var device = process.argv[2] || 'dev1';

var address = '127.0.0.1:8888';


var _host = address.substr(0, address.indexOf(':'));
var _port = Number(address.substr(address.indexOf(':') + 1));

var _app = 'LISK:STALK_IO';

var _channel = 'channel_12345';

var user = {
  'A': _app,
  'D': device,
  'U': 'james',
  'PW': 'password',
  'DT': {'name': '<NAME>', 'tel': '010-1234-5678'}
};

var GLOBAL_SOCKET;
var CHANNEL_SOCKET;

async.series([

  function (callback) { // 사용자 정보 UPDATE

    util.post(_host, _port, '/user/update', user, function (err, data) {

      if (data.status == 'ok') {
        callback(null, data);
      } else {

        util.post(_host, _port, '/user/register', user, function (err, data) {
          if (data.status == 'ok') {
            callback(null, data);
          } else {
            callback(data.status, data.message);
          }
        });

      }
    });

  },
  function (callback) { // Global Socket 연결
    util.get(_host, _port, '/node/' + _app + '/' + user.U, function (err, data) {
      var query = 'A=' + user.A + '&U=' + user.U + '&D=' + user.D;
      GLOBAL_SOCKET = io.connect(data.result.server.url + '/global?' + query, util.socketOptions);
      GLOBAL_SOCKET.on('connect', function (data) {
        console.log('Glocal Socket 연결 ! ');
        callback(null);
      });
    });
  },
  function (callback) {

    util.get(_host, _port, '/node/' + _app + '/' + _channel, function (err, data) {

      var query = 'A=' + user.A + '&U=' + user.U + '&D=' + user.D + '&C=' + _channel + '&S=' + data.result.server.name;
      CHANNEL_SOCKET = io.connect(data.result.server.url + '/channel?' + query, util.socketOptions);

      CHANNEL_SOCKET.on('message', function (data) {
        console.info(' ** MESSAGE ** ', data);
      });

      CHANNEL_SOCKET.on('connect', function (data) {

        // channel 에 연결된 이후 john 을 추가 한다.
        GLOBAL_SOCKET.emit('channel.create', {U: 'james', DT: {text: 'ABCDE'}}, function (result) {

          setTimeout(function () {
            CHANNEL_SOCKET.emit('send', {'NM': 'message', 'DT': {'NO': 1, 'MG': faker.lorem.sentence()}});
{'fraction_non_alphanumeric': 0.20086580086580086, 'fraction_numerical': 0.01341991341991342, 'mean_word_length': 2.750811688311688, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7449364', 'n_tokens_mistral': 1717, 'n_tokens_neox': 1656, 'n_words': 368}