0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-dgram-send-callback-recursive.js
Yosuke Furukawa d20f018dcf test: loosen condition to detect infinite loop
PR-URL: https://github.com/nodejs/io.js/pull/1857
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2015-06-03 01:46:23 +09:00

40 lines
807 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
const chunk = 'abc';
var recursiveCount = 0;
var received = 0;
const limit = 10;
const recursiveLimit = 100;
function onsend() {
if (recursiveCount > recursiveLimit) {
throw new Error('infinite loop detected');
}
if (received < limit) {
client.send(
chunk, 0, chunk.length, common.PORT, common.localhostIPv4, onsend);
}
recursiveCount++;
}
client.on('listening', function() {
onsend();
});
client.on('message', function(buf, info) {
received++;
if (received === limit) {
client.close();
}
});
client.on('close', common.mustCall(function() {
assert.equal(received, limit);
}));
client.bind(common.PORT);