<commit_before>#!/usr/bin/env node

var mdns   = require('../../lib/mdns')
  , assert = require('assert')
  , util   = require('util')
  ;

// XXX This test will break if two instances are run on the same network

var timeout = 5000;
var timeoutId = setTimeout(function() {
  assert.fail("test did not finish within " + (timeout / 1000) + " seconds.");
}, timeout)

var browser = mdns.createBrowser(mdns.tcp('node-mdns-test'));

function stopBrowserIfDone() {
  if (upCount > 0 &&
      downCount > 0 && 
      upCount == downCount && 
      changedCount == upCount + downCount)
  {
    browser.stop();
    clearTimeout(timeoutId);
  }
}

var changedCount = 0;
browser.on('serviceChanged', function(service, flags) {
  //console.log("changed:", service);
  assert.strictEqual(typeof service.flags, 'number');
  if (changedCount === 0) {
    assert.ok(service.flags & mdns.kDNSServiceFlagsAdd);
    assert.strictEqual(typeof service.fullname, 'string');
    assert.strictEqual(typeof service.host, 'string');
    assert.strictEqual(typeof service.port, 'number');
    assert.strictEqual(service.port, 4321);

    assert.ok('addresses' in service);
    assert.ok(Array.isArray(service.addresses));
    assert.ok(service.addresses.length > 0);
  }
  assert.strictEqual(typeof service.interfaceIndex, 'number');
  assert.strictEqual(typeof service.name, 'string');
  assert.ok(service.type instanceof mdns.ServiceType);
  assert.strictEqual('' + service.type, '_node-mdns-test._tcp.');
  assert.strictEqual(typeof service.replyDomain, 'string');
  assert.strictEqual(service.replyDomain, 'local.');

  changedCount += 1;
  stopBrowserIfDone();
});

var upCount = 0;
browser.on('serviceUp', function(service) {
  console.log("up:", service);
  assert.strictEqual(typeof service.flags, 'number');
  assert.strictEqual(typeof service.interfaceIndex, 'number');
  assert.strictEqual(typeof service.name, 'string');
  assert.ok(service.type instanceof mdns.ServiceType);
  assert.strictEqual('' + service.type, '_node-mdns-test._tcp.');
  assert.strictEqual(typeof service.replyDomain, 'string');
  assert.strictEqual(service.replyDomain, 'local.');
<commit_msg>disabled debug output<commit_after>#!/usr/bin/env node

var mdns   = require('../../lib/mdns')
  , assert = require('assert')
  , util   = require('util')
  ;

// XXX This test will break if two instances are run on the same network

var timeout = 5000;
var timeoutId = setTimeout(function() {
  assert.fail("test did not finish within " + (timeout / 1000) + " seconds.");
}, timeout)

var browser = mdns.createBrowser(mdns.tcp('node-mdns-test'));

function stopBrowserIfDone() {
  if (upCount > 0 &&
      downCount > 0 && 
      upCount == downCount && 
      changedCount == upCount + downCount)
  {
    browser.stop();
    clearTimeout(timeoutId);
  }
}

var changedCount = 0;
browser.on('serviceChanged', function(service, flags) {
  //console.log("changed:", service);
  assert.strictEqual(typeof service.flags, 'number');
  if (changedCount === 0) {
    assert.ok(service.flags & mdns.kDNSServiceFlagsAdd);
    assert.strictEqual(typeof service.fullname, 'string');
    assert.strictEqual(typeof service.host, 'string');
    assert.strictEqual(typeof service.port, 'number');
    assert.strictEqual(service.port, 4321);

    assert.ok('addresses' in service);
    assert.ok(Array.isArray(service.addresses));
    assert.ok(service.addresses.length > 0);
  }
  assert.strictEqual(typeof service.interfaceIndex, 'number');
  assert.strictEqual(typeof service.name, 'string');
  assert.ok(service.type instanceof mdns.ServiceType);
  assert.strictEqual('' + service.type, '_node-mdns-test._tcp.');
  assert.strictEqual(typeof service.replyDomain, 'string');
  assert.strictEqual(service.replyDomain, 'local.');

  changedCount += 1;
  stopBrowserIfDone();
});

var upCount = 0;
browser.on('serviceUp', function(service) {
  //console.log("up:", service);
  assert.strictEqual(typeof service.flags, 'number');
  assert.strictEqual(typeof service.interfaceIndex, 'number');
  assert.strictEqual(typeof service.name, 'string');
  assert.ok(service.type instanceof mdns.ServiceType);
  assert.strictEqual('' + service.type, '_node-mdns-test._tcp.');
  assert.strictEqual(typeof service.replyDomain, 'string');
  assert.strictEqual(service.replyDomain, 'local.');

{'fraction_non_alphanumeric': 0.1561631139944393, 'fraction_numerical': 0.008804448563484708, 'mean_word_length': 4.52752880921895, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '5307147', 'n_tokens_mistral': 1352, 'n_tokens_neox': 1317, 'n_words': 272}