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(server): fix ERR_SERVER_ALREADY_LISTEN issue with Node v9.0.0 #1549

Merged
merged 1 commit into from
Nov 2, 2017
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
20 changes: 8 additions & 12 deletions test/plugins/query.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,10 @@ describe('query parser', function() {
res.send(req.params);
});

SERVER.listen(8080, function() {
CLIENT.get('/hello/foo/?bar=baz', function(err, _, __, obj) {
assert.ifError(err);
assert.deepEqual(obj, { name: 'foo', bar: 'baz' });
done();
});
CLIENT.get('/hello/foo/?bar=baz', function(err, _, __, obj) {
assert.ifError(err);
assert.deepEqual(obj, { name: 'foo', bar: 'baz' });
done();
});
});

Expand All @@ -245,12 +243,10 @@ describe('query parser', function() {
res.send(req.params);
});

SERVER.listen(8080, function() {
CLIENT.get('/?bar=baz', function(err, _, __, obj) {
assert.ifError(err);
assert.deepEqual(obj, { bar: 'baz' });
done();
});
CLIENT.get('/?bar=baz', function(err, _, __, obj) {
assert.ifError(err);
assert.deepEqual(obj, { bar: 'baz' });
done();
});
});
});
98 changes: 46 additions & 52 deletions test/server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1229,18 +1229,16 @@ test('GH-652 throw InvalidVersion on version mismatch', function(t) {
return res.send(req.route.version);
}
SERVER.get({ path: '/ping', version: '1.0.1' }, response);
SERVER.listen(0, '127.0.0.1', function() {
var opts = {
path: '/ping',
headers: {
'accept-version': '1.0.2'
}
};
CLIENT.get(opts, function(err, req, res, data) {
t.equal(res.statusCode, 400);
t.equal(data.code, 'InvalidVersion');
t.done();
});
var opts = {
path: '/ping',
headers: {
'accept-version': '1.0.2'
}
};
CLIENT.get(opts, function(err, req, res, data) {
t.equal(res.statusCode, 400);
t.equal(data.code, 'InvalidVersion');
t.done();
});
});

Expand All @@ -1249,18 +1247,16 @@ test('GH-652 throw InvalidVersion on non-versioned route', function(t) {
return res.send(req.route.version);
}
SERVER.get({ path: '/ping' }, response);
SERVER.listen(0, '127.0.0.1', function() {
var opts = {
path: '/ping',
headers: {
'accept-version': '1.0.1'
}
};
CLIENT.get(opts, function(err, req, res, data) {
t.equal(res.statusCode, 400);
t.equal(data.code, 'InvalidVersion');
t.done();
});
var opts = {
path: '/ping',
headers: {
'accept-version': '1.0.1'
}
};
CLIENT.get(opts, function(err, req, res, data) {
t.equal(res.statusCode, 400);
t.equal(data.code, 'InvalidVersion');
t.done();
});
});

Expand Down Expand Up @@ -1380,38 +1376,36 @@ test('content-type routing vendor', function(t) {
}
);

SERVER.listen(8080, function() {
var _done = 0;
var _done = 0;

function done() {
if (++_done === 2) {
t.end();
}
function done() {
if (++_done === 2) {
t.end();
}
}

var opts = {
path: '/',
headers: {
'content-type': 'application/vnd.joyent.com.foo+json'
}
};
CLIENT.post(opts, {}, function(err, _, res) {
t.ifError(err);
t.equal(res.statusCode, 201);
done();
});
var opts = {
path: '/',
headers: {
'content-type': 'application/vnd.joyent.com.foo+json'
}
};
CLIENT.post(opts, {}, function(err, _, res) {
t.ifError(err);
t.equal(res.statusCode, 201);
done();
});

var opts2 = {
path: '/',
headers: {
'content-type': 'application/vnd.joyent.com.bar+json'
}
};
CLIENT.post(opts2, {}, function(err, _, res) {
t.ifError(err);
t.equal(res.statusCode, 202);
done();
});
var opts2 = {
path: '/',
headers: {
'content-type': 'application/vnd.joyent.com.bar+json'
}
};
CLIENT.post(opts2, {}, function(err, _, res) {
t.ifError(err);
t.equal(res.statusCode, 202);
done();
});
});

Expand Down