Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add test for dgram.setTTL #2121

Merged
merged 1 commit into from
Jul 10, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions test/parallel/test-dgram-setTTL.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const socket = dgram.createSocket('udp4');

socket.bind(common.PORT);
socket.on('listening', function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the entire test is in the callback, we can wrap it with common.mustCall. It will make sure that the test fails if the callback is not invoked.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe it would make a difference if the callback is not invoked, since the bind will keep the process alive (or throw if it fails). I believe common.mustCall is called in the exit event, which wouldn't happen either if the callback isn't called.

var result = socket.setTTL(16);
assert.strictEqual(result, 16);

assert.throws(function() {
socket.setTTL('foo');
}, /Argument must be a number/);

socket.close();
});