Skip to content

Commit

Permalink
ZAPI-660 Requests to /vms hang forever which have a "fields" param an…
Browse files Browse the repository at this point in the history
…d match no VMs

Reviewed by: Josh Wilsdon <jwilsdon@joyent.com>
  • Loading branch information
arekinath committed Aug 20, 2015
1 parent 79d616c commit cff6bd4
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/endpoints/vms.js
Expand Up @@ -64,7 +64,9 @@ function renderVms(req, res, next) {

// Take any vm to get all its default rendered fields
var aVm = (req.vms ? req.vms[0] : req.vm);
var vmFields = Object.keys(aVm);
// If we have an empty vms array though, just use an empty list
// (we won't have anything to iterate over anyway)
var vmFields = (typeof(aVm) === 'object') ? Object.keys(aVm) : [];

// See if '*' was passed and remove duplicates
for (var i = 0; i < fieldsParam.length; i++) {
Expand Down
82 changes: 82 additions & 0 deletions test/vms.test.js
Expand Up @@ -24,6 +24,7 @@ var muuid;
var newUuid;
var jobLocation;
var vmLocation;
var vmCount;
var pkgId;

var IMAGE = 'fd2cc906-8938-11e3-beab-4359c665ac99';
Expand Down Expand Up @@ -375,6 +376,87 @@ exports.head_vms_ok = function (t) {
t.equal(res.statusCode, 200);
common.checkHeaders(t, res.headers);
t.ok(res.headers['x-joyent-resource-count']);
vmCount = res.headers['x-joyent-resource-count'];
t.done();
});
};


exports.offset_vms_ok = function(t) {
var path = '/vms?ram=' + 128 + '&owner_uuid=' + CUSTOMER + '&offset=2';

client.get(path, function (err, req, res, body) {
t.ifError(err);
t.equal(res.statusCode, 200);
common.checkHeaders(t, res.headers);
t.ok(res.headers['x-joyent-resource-count']);
t.ok(body);
t.ok(Array.isArray(body));
t.equal(body.length, vmCount - 2);
t.done();
});
};


exports.offset_vms_at_end = function(t) {
var path = '/vms?ram=' + 128 + '&owner_uuid=' + CUSTOMER + '&offset=' + vmCount;

client.get(path, function (err, req, res, body) {
t.ifError(err);
t.equal(res.statusCode, 200);
common.checkHeaders(t, res.headers);
t.ok(body);
t.ok(Array.isArray(body));
t.equal(body.length, 0);
t.done();
});
};


exports.offset_vms_beyond = function(t) {
var path = '/vms?ram=' + 128 + '&owner_uuid=' + CUSTOMER + '&offset=' + vmCount + 5;

client.get(path, function (err, req, res, body) {
t.ifError(err);
t.equal(res.statusCode, 200);
common.checkHeaders(t, res.headers);
t.ok(body);
t.ok(Array.isArray(body));
t.equal(body.length, 0);
t.done();
});
};


exports.offset_fields_vms_ok = function(t) {
var path = '/vms?ram=' + 128 + '&owner_uuid=' + CUSTOMER + '&fields=uuid,alias&offset=2';

client.get(path, function (err, req, res, body) {
t.ifError(err);
t.equal(res.statusCode, 200);
common.checkHeaders(t, res.headers);
t.ok(res.headers['x-joyent-resource-count']);
t.ok(body);
t.ok(Array.isArray(body));
t.equal(body.length, vmCount - 2);
t.notStrictEqual(body[0].uuid, undefined);
t.notStrictEqual(body[0].alias, undefined);
t.strictEqual(body[0].ram, undefined);
t.done();
});
};


exports.offset_fields_vms_beyond = function(t) {
var path = '/vms?ram=' + 128 + '&owner_uuid=' + CUSTOMER + '&fields=uuid,alias&offset=' + vmCount + 5;

client.get(path, function (err, req, res, body) {
t.ifError(err);
t.equal(res.statusCode, 200);
common.checkHeaders(t, res.headers);
t.ok(body);
t.ok(Array.isArray(body));
t.equal(body.length, 0);
t.done();
});
};
Expand Down

0 comments on commit cff6bd4

Please sign in to comment.