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

Specify heartbeat with object configuration #304

Merged
merged 1 commit into from
Dec 4, 2016
Merged
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion lib/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,14 @@ function connect(url, socketOptions, openCallback) {
pass = url.password;
}

fields = openFrames(url.vhost, null, sockopts.credentials || credentials.plain(user, pass), extraClientProperties);
var config = {
locale: url.locale,
channelMax: url.channelMax,
frameMax: url.frameMax,
heartbeat: url.heartbeat,
};

fields = openFrames(url.vhost, config, sockopts.credentials || credentials.plain(user, pass), extraClientProperties);
} else {
var parts = URL.parse(url, true); // yes, parse the query string
protocol = parts.protocol;
Expand Down
21 changes: 19 additions & 2 deletions test/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ var assert = require('assert');
var util = require('./util');
var net = require('net');
var fail = util.fail, succeed = util.succeed,
kCallback = util.kCallback;
kCallback = util.kCallback,
succeedIfAttributeEquals = util.succeedIfAttributeEquals;

var URL = process.env.URL || 'amqp://localhost';

Expand All @@ -15,7 +16,7 @@ suite("Connect API", function() {
connect('amqp://localhost:23450', {},
kCallback(fail(done), succeed(done)));
});

// %% this ought to fail the promise, rather than throwing an error
test("bad URL", function() {
assert.throws(function() {
Expand All @@ -33,6 +34,22 @@ suite("Connect API", function() {
connect(u, {}, kCallback(fail(done), succeed(done)));
});

test("using custom heartbeat option", function(done) {
var url = require('url');
var parts = url.parse(URL, true);
var config = parts.query || {};
config.heartbeat = 20;
connect(config, {}, kCallback(succeedIfAttributeEquals('heartbeat', 20, done), fail(done)));
});

test("wrongly typed heartbeat option", function(done) {
var url = require('url');
var parts = url.parse(URL, true);
var config = parts.query || {};
config.heartbeat = 'NOT A NUMBER';
connect(config, {}, kCallback(fail(done), succeed(done)));
});

test("using plain credentials", function(done) {
var url = require('url');
var parts = url.parse(URL, true);
Expand Down
14 changes: 14 additions & 0 deletions test/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,19 @@ function succeed(done) {
return function() { done(); }
}

// Produce a callback that will complete the test successfully
// only if the value is an object, it has the specified
// attribute, and its value is equals to the expected value
function succeedIfAttributeEquals(attribute, value, done) {
return function(object) {
if (object && !(object instanceof Error) && value === object[attribute]) {
return done();
}

done(new Error(attribute + " is not equal to " + value));
};
}

// Produce a callback that will fail the test, given either an error
// (to be used as a failure continuation) or any other value (to be
// used as a success continuation when failure is expected)
Expand Down Expand Up @@ -196,6 +209,7 @@ module.exports = {
socketPair: socketPair,
runServer: runServer,
succeed: succeed,
succeedIfAttributeEquals: succeedIfAttributeEquals,
fail: fail,
latch: latch,
completes: completes,
Expand Down