Tests for both: onTileErrorStrategy enabled and disabled

This commit is contained in:
Raul Ochoa 2015-04-06 18:44:57 +02:00
parent e3c6569302
commit 21072645a4
2 changed files with 203 additions and 115 deletions

View File

@ -88,132 +88,220 @@ describe('render limits', function() {
} }
it("layergroup creation fails if test tile is slow", function(done) { describe('with onTileErrorStrategy DISABLED', function() {
withRenderLimit(user, 50, function(err) { var onTileErrorStrategyEnabled;
if (err) { before(function() {
return done(err); onTileErrorStrategyEnabled = global.environment.enabledFeatures.onTileErrorStrategy;
} global.environment.enabledFeatures.onTileErrorStrategy = false;
var layergroup = singleLayergroupConfig(polygonSleepSql, polygonCartoCss);
assert.response(server,
createRequest(layergroup, user),
{
status: 400
},
function(res) {
var parsed = JSON.parse(res.body);
assert.deepEqual(parsed, { errors: [ 'Render timed out' ] });
done();
}
);
}); });
});
it("layergroup creation does not fail if user limit is high enough even if test tile is slow", function(done) { after(function() {
withRenderLimit(user, 5000, function(err) { global.environment.enabledFeatures.onTileErrorStrategy = onTileErrorStrategyEnabled;
if (err) { });
return done(err);
} it("layergroup creation fails if test tile is slow", function(done) {
withRenderLimit(user, 50, function(err) {
var layergroup = singleLayergroupConfig(polygonSleepSql, polygonCartoCss); if (err) {
assert.response(server, return done(err);
createRequest(layergroup, user), }
{
status: 200 var layergroup = singleLayergroupConfig(polygonSleepSql, polygonCartoCss);
}, assert.response(server,
function(res) { createRequest(layergroup, user),
var parsed = JSON.parse(res.body); {
assert.ok(parsed.layergroupid); status: 400
done(); },
} function(res) {
); var parsed = JSON.parse(res.body);
assert.deepEqual(parsed, { errors: [ 'Render timed out' ] });
done();
}
);
});
});
it("layergroup creation does not fail if user limit is high enough even if test tile is slow", function(done) {
withRenderLimit(user, 5000, function(err) {
if (err) {
return done(err);
}
var layergroup = singleLayergroupConfig(polygonSleepSql, polygonCartoCss);
assert.response(server,
createRequest(layergroup, user),
{
status: 200
},
function(res) {
var parsed = JSON.parse(res.body);
assert.ok(parsed.layergroupid);
done();
}
);
});
}); });
});
it("layergroup creation works if test tile is fast but tile request fails if they are slow", function(done) { it("layergroup creation works if test tile is fast but tile request fails if they are slow", function(done) {
withRenderLimit(user, 50, function(err) { withRenderLimit(user, 50, function(err) {
if (err) { if (err) {
return done(err); return done(err);
} }
var layergroup = singleLayergroupConfig(pointSleepSql, pointCartoCss); var layergroup = singleLayergroupConfig(pointSleepSql, pointCartoCss);
assert.response(server, assert.response(server,
createRequest(layergroup, user), createRequest(layergroup, user),
{ {
status: 200 status: 200
}, },
function(res) { function(res) {
assert.response(server, assert.response(server,
{ {
url: layergroupUrl + _.template('/<%= layergroupId %>/<%= z %>/<%= x %>/<%= y %>.png', { url: layergroupUrl + _.template('/<%= layergroupId %>/<%= z %>/<%= x %>/<%= y %>.png', {
layergroupId: JSON.parse(res.body).layergroupid, layergroupId: JSON.parse(res.body).layergroupid,
z: 0, z: 0,
x: 0, x: 0,
y: 0 y: 0
}), }),
method: 'GET', method: 'GET',
headers: { headers: {
host: 'localhost' host: 'localhost'
},
encoding: 'binary'
}, },
encoding: 'binary' {
}, status: 400
{
status: 400
},
function(res) {
var parsed = JSON.parse(res.body);
assert.deepEqual(parsed, { error: 'Render timed out' });
done();
}
);
}
);
});
});
it("tile request does not fail if user limit is high enough", function(done) {
withRenderLimit(user, 5000, function(err) {
if (err) {
return done(err);
}
var layergroup = singleLayergroupConfig(pointSleepSql, pointCartoCss);
assert.response(server,
createRequest(layergroup, user),
{
status: 200
},
function(res) {
assert.response(server,
{
url: layergroupUrl + _.template('/<%= layergroupId %>/<%= z %>/<%= x %>/<%= y %>.png', {
layergroupId: JSON.parse(res.body).layergroupid,
z: 0,
x: 0,
y: 0
}),
method: 'GET',
headers: {
host: 'localhost'
}, },
encoding: 'binary' function(res) {
}, var parsed = JSON.parse(res.body);
{ assert.deepEqual(parsed, { error: 'Render timed out' });
status: 200, done();
headers: {
'Content-Type': 'image/png'
} }
}, );
function(res, err) {
done(err);
}
);
} }
); );
});
}); });
it("tile request does not fail if user limit is high enough", function(done) {
withRenderLimit(user, 5000, function(err) {
if (err) {
return done(err);
}
var layergroup = singleLayergroupConfig(pointSleepSql, pointCartoCss);
assert.response(server,
createRequest(layergroup, user),
{
status: 200
},
function(res) {
assert.response(server,
{
url: layergroupUrl + _.template('/<%= layergroupId %>/<%= z %>/<%= x %>/<%= y %>.png', {
layergroupId: JSON.parse(res.body).layergroupid,
z: 0,
x: 0,
y: 0
}),
method: 'GET',
headers: {
host: 'localhost'
},
encoding: 'binary'
},
{
status: 200,
headers: {
'Content-Type': 'image/png'
}
},
function(res, err) {
done(err);
}
);
}
);
});
});
});
describe('with onTileErrorStrategy', function() {
it("layergroup creation works even if test tile is slow", function(done) {
withRenderLimit(user, 50, function(err) {
if (err) {
return done(err);
}
var layergroup = singleLayergroupConfig(polygonSleepSql, polygonCartoCss);
assert.response(server,
createRequest(layergroup, user),
{
status: 200
},
function(res) {
var parsed = JSON.parse(res.body);
assert.ok(parsed.layergroupid);
done();
}
);
});
});
it("layergroup creation and tile requests works even if they are slow but returns fallback", function(done) {
withRenderLimit(user, 50, function(err) {
if (err) {
return done(err);
}
var layergroup = singleLayergroupConfig(pointSleepSql, pointCartoCss);
assert.response(server,
createRequest(layergroup, user),
{
status: 200
},
function(res) {
assert.response(server,
{
url: layergroupUrl + _.template('/<%= layergroupId %>/<%= z %>/<%= x %>/<%= y %>.png', {
layergroupId: JSON.parse(res.body).layergroupid,
z: 0,
x: 0,
y: 0
}),
method: 'GET',
headers: {
host: 'localhost'
},
encoding: 'binary'
},
{
status: 200,
headers: {
'Content-Type': 'image/png'
}
},
function(res, err) {
if (err) {
done(err);
}
assert.imageEqualsFile(res.body, './test/fixtures/render-timeout-fallback.png', 25,
function(imgErr/*, similarity*/) {
done(imgErr);
}
);
}
);
}
);
});
});
}); });
}); });

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB