<commit_before>#!/usr/bin/env node
var mdns   = require('../../lib/mdns'),
    util   = require('util'),
    assert = require('assert');

var ad =  mdns.createAdvertisement(mdns.tcp('node-mdns-test', 'a', 'b'), 4321, function(err, info, flags) {
  if (err) {
    assert.fail(err)
  } else {
    assert.equal(info['regtype'], '_node-mdns-test._tcp.');
    //util.puts('Advertising', util.inspect(info));
  }
});
var browser = mdns.createBrowser(mdns.tcp('node-mdns-test', 'b'));

timeout_id = setTimeout(function() { assert.fail('time out'); }, 10000);

browser.on('serviceUp', function(info) {
  //util.puts('Up', util.inspect(info));
  assert.equal('_node-mdns-test._tcp.', info['regtype']);
  assert.equal(4321, info['port']);
  ad.stop();
});

browser.on('serviceDown', function(info) {
  //util.puts('Down', util.inspect(info));
  assert.equal('_node-mdns-test._tcp.', info['regtype']);
  browser.stop();
  clearTimeout(timeout_id);
});

browser.start();
ad.start();

//==============================================================================

assert.throws(function() { mdns.createAdvertisement()});
assert.throws(function() { mdns.createAdvertisement('narf')});
assert.throws(function() { mdns.createAdvertisement(function(){})});
assert.throws(function() { mdns.createAdvertisement('narf', function(){})});

var test_ad = mdns.createAdvertisement(mdns.tcp('node-mdns-test'), 4321);
test_ad.start();
assert.throws(function() { test_ad.start()});
test_ad.stop();

<commit_msg>fixed bugs in tests<commit_after>#!/usr/bin/env node
var mdns   = require('../../lib/mdns'),
    util   = require('util'),
    assert = require('assert');

var ad =  mdns.createAdvertisement(mdns.tcp('node-mdns-test', 'a', 'b'), 4321, function(err, info, flags) {
  if (err) {
    assert.fail(err)
  } else {
    assert.strictEqual('' + info.regtype, '_node-mdns-test._tcp.');
    //util.puts('Advertising', util.inspect(info));
  }
});
var browser = mdns.createBrowser(mdns.tcp('node-mdns-test', 'b'));

timeout_id = setTimeout(function() { assert.fail('time out'); }, 10000);

browser.on('serviceUp', function(info) {
  //util.puts('Up', util.inspect(info));
  assert.strictEqual('_node-mdns-test._tcp.', '' + info.regtype);
  assert.strictEqual(4321, info.port);
  ad.stop();
});

browser.on('serviceDown', function(info) {
  //util.puts('Down', util.inspect(info));
  assert.strictEqual('_node-mdns-test._tcp.', '' + info.regtype);
  browser.stop();
  clearTimeout(timeout_id);
});

browser.start();
ad.start();

//==============================================================================

assert.throws(function() { mdns.createAdvertisement()});
assert.throws(function() { mdns.createAdvertisement('narf')});
assert.throws(function() { mdns.createAdvertisement(function(){})});
assert.throws(function() { mdns.createAdvertisement('narf', function(){})});

var test_ad = mdns.createAdvertisement(mdns.tcp('node-mdns-test'), 4321);
test_ad.start();
assert.throws(function() { test_ad.start()});
test_ad.stop();


{'fraction_non_alphanumeric': 0.2637179913535085, 'fraction_numerical': 0.011306950448952444, 'mean_word_length': 5.510822510822511, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6808242', 'n_tokens_mistral': 1066, 'n_tokens_neox': 996, 'n_words': 146}