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

changes in tests to work in docker-dev-env #1180

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion test/acceptance/multilayer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ var QueryTables = require('cartodb-query-tables').queryTables;
]
};
var statskey = 'user:localhost:mapviews';
var redisStatsClient = redis.createClient(global.environment.redis.port);
var redisStatsClient = redis.createClient(global.environment.redis.port, global.environment.redis.host);
var expectedToken; // will be set on first post and checked on second
var now = strftime('%Y%m%d', new Date());
step(
Expand Down
6 changes: 3 additions & 3 deletions test/acceptance/rate-limit-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ describe('rate limit', function () {
global.environment.enabledFeatures.rateLimitsEnabled = true;
global.environment.enabledFeatures.rateLimitsByEndpoint.anonymous = true;

redisClient = redis.createClient(global.environment.redis.port);
redisClient = redis.createClient(global.environment.redis.port, global.environment.redis.host);
testClient = new TestClient(createMapConfig(), 1234);
});

Expand Down Expand Up @@ -226,7 +226,7 @@ describe('rate limit middleware', function () {
});
rateLimit = rateLimitMiddleware(userLimitsApi, RATE_LIMIT_ENDPOINTS_GROUPS.ANONYMOUS);

redisClient = redis.createClient(global.environment.redis.port);
redisClient = redis.createClient(global.environment.redis.port, global.environment.redis.host);
testClient = new TestClient(createMapConfig(), 1234);

const count = 1;
Expand Down Expand Up @@ -290,7 +290,7 @@ function rateLimitAndVectorTilesTest (usePostGIS) {
global.environment.enabledFeatures.rateLimitsEnabled = true;
global.environment.enabledFeatures.rateLimitsByEndpoint.tile = true;

redisClient = redis.createClient(global.environment.redis.port);
redisClient = redis.createClient(global.environment.redis.port, global.environment.redis.host);
const count = 1;
const period = 1;
const burst = 0;
Expand Down
2 changes: 1 addition & 1 deletion test/acceptance/templates-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1506,7 +1506,7 @@ describe('template_api', function () {
layergroup: layergroup
};
var statskey = 'user:localhost:mapviews';
var redisStatsClient = redis.createClient(global.environment.redis.port);
var redisStatsClient = redis.createClient(global.environment.redis.port, global.environment.redis.host);
var templateId; // will be set on template post
var now = strftime('%Y%m%d', new Date());
var errors = [];
Expand Down
26 changes: 17 additions & 9 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ if (!process.env.NODE_ENV) {
}

const environment = require(`../config/environments/${process.env.NODE_ENV}.js`);
const REDIS_HOST = environment.redis.host;
const REDIS_PORT = environment.redis.port;
const DB_HOST = environment.postgres.host;
const REDIS_CELL_PATH = path.resolve(
process.platform === 'darwin'
? './test/support/libredis_cell.dylib'
Expand All @@ -24,28 +26,34 @@ const PUBLIC_USER = environment.postgres.user;
const PUBLIC_USER_PASSWORD = environment.postgres.password;
const TEST_DB = `${TEST_USER}_db`;

const REDIS_SERVER_IS_LOCAL = (['127.0.0.1', 'localhost'].includes(REDIS_HOST));

async function startRedis () {
await exec(`redis-server --port ${REDIS_PORT} --loadmodule ${REDIS_CELL_PATH} --logfile ${__dirname}/redis-server.log --daemonize yes`);
if (REDIS_SERVER_IS_LOCAL) {
await exec(`redis-server --port ${REDIS_PORT} --loadmodule ${REDIS_CELL_PATH} --logfile ${__dirname}/redis-server.log --daemonize yes`);
}
}

async function stopRedis () {
await exec(`redis-cli -p ${REDIS_PORT} shutdown`);
if (REDIS_SERVER_IS_LOCAL) {
await exec(`redis-cli -p ${REDIS_PORT} shutdown`);
}
}

async function dropDatabase () {
await exec(`dropdb --if-exists ${TEST_DB}`, {
await exec(`dropdb -h ${DB_HOST} --if-exists ${TEST_DB}`, {
env: Object.assign({ PGUSER: 'postgres' }, process.env)
});
}

async function createDatabase () {
await exec(`createdb -T template_postgis -EUTF8 "${TEST_DB}"`, {
await exec(`createdb -h ${DB_HOST} -T template_postgis -EUTF8 "${TEST_DB}"`, {
env: Object.assign({ PGUSER: 'postgres' }, process.env)
});
}

async function createDatabaseExtension () {
await exec(`psql -c "CREATE EXTENSION IF NOT EXISTS cartodb CASCADE;" ${TEST_DB}`, {
await exec(`psql -h ${DB_HOST} -c "CREATE EXTENSION IF NOT EXISTS cartodb CASCADE;" ${TEST_DB}`, {
env: Object.assign({ PGUSER: 'postgres' }, process.env)
});
}
Expand All @@ -67,7 +75,7 @@ async function populateDatabase () {
sed -e "s/:PUBLICPASS/${PUBLIC_USER_PASSWORD}/g" |
sed -e "s/:TESTUSER/${TEST_USER}/g" |
sed -e "s/:TESTPASS/${TEST_PASSWORD}/g" |
PGOPTIONS='--client-min-messages=WARNING' psql -q -v ON_ERROR_STOP=1 ${TEST_DB}
PGOPTIONS='--client-min-messages=WARNING' psql -h ${DB_HOST} -q -v ON_ERROR_STOP=1 ${TEST_DB}
`;

await exec(populateDatabaseCmd, {
Expand All @@ -82,13 +90,13 @@ async function populateRedis () {
HMSET rails:users:localhost \
id ${TEST_USER_ID} \
database_name "${TEST_DB}" \
database_host localhost \
database_host ${DB_HOST} \
map_key 1234

HMSET rails:users:cartodb250user \
id ${TEST_USER_ID} \
database_name "${TEST_DB}" \
database_host "localhost" \
database_host "${DB_HOST}" \
database_password "${TEST_PASSWORD}" \
map_key 4321

Expand Down Expand Up @@ -141,7 +149,7 @@ async function populateRedis () {
database_password "public"
`;

await exec(`echo "${commands}" | redis-cli -p ${REDIS_PORT} -n 5`);
await exec(`echo "${commands}" | redis-cli -h ${REDIS_HOST} -p ${REDIS_PORT} -n 5`);
}

async function main (args) {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/analysis-backend-limits-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('analysis-backend limits', function () {
var user = 'localhost';

beforeEach(function () {
redisClient = redis.createClient(global.environment.redis.port);
redisClient = redis.createClient(global.environment.redis.port, global.environment.redis.host);
keysToDelete = {};
var redisPool = new RedisPool(global.environment.redis);
this.metadataBackend = cartodbRedis({ pool: redisPool });
Expand Down
2 changes: 1 addition & 1 deletion test/integration/template-maps-limits-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('TemplateMaps limits', function () {
};
}

var redisClient = redis.createClient(global.environment.redis.port);
var redisClient = redis.createClient(global.environment.redis.port, global.environment.redis.host);
var redisPool = new RedisPool(global.environment.redis);

afterEach(function (done) {
Expand Down
4 changes: 2 additions & 2 deletions test/support/test-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ var redisClient;

beforeEach(function () {
if (!redisClient) {
redisClient = redis.createClient(global.environment.redis.port);
redisClient = redis.createClient(global.environment.redis.port, global.environment.redis.host);
}
});

Expand Down Expand Up @@ -157,7 +157,7 @@ function deleteRedisKeys (keysToDelete, callback) {
}

Object.keys(keysToDelete).forEach(function (k) {
var redisClient = redis.createClient(global.environment.redis.port);
var redisClient = redis.createClient(global.environment.redis.port, global.environment.redis.host);
redisClient.select(keysToDelete[k], function () {
redisClient.del(k, function (err, deletedKeysCount) {
assert.ifError(err);
Expand Down