node/test/parallel/test-dgram-send-queue-info.js
theanarkh 97e8bda5b2
dgram: add dgram send queue info
PR-URL: https://github.com/nodejs/node/pull/44149
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2022-08-17 16:08:58 +00:00

28 lines
828 B
JavaScript

// Flags: --test-udp-no-try-send
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const socket = dgram.createSocket('udp4');
assert.strictEqual(socket.getSendQueueSize(), 0);
assert.strictEqual(socket.getSendQueueCount(), 0);
socket.close();
const server = dgram.createSocket('udp4');
const client = dgram.createSocket('udp4');
server.bind(0, common.mustCall(() => {
client.connect(server.address().port, common.mustCall(() => {
const data = 'hello';
client.send(data);
client.send(data);
// See uv__send in win/udp.c
assert.strictEqual(client.getSendQueueSize(),
common.isWindows ? 0 : data.length * 2);
assert.strictEqual(client.getSendQueueCount(), 2);
client.close();
server.close();
}));
}));