From 2d8d234c57e7d1dfac89fe703604bfdbe3b2f9e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 16 Oct 2018 18:44:03 -0400 Subject: [PATCH] test mongodb again --- .travis.yml | 1 + src/database/mongo/pubsub.js | 6 ++++-- test/mocks/databasemock.js | 2 +- test/pubsub.js | 4 ---- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2bae948ca7..7e7303fb9d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,7 @@ before_install: - cp install/package.json package.json before_script: - sleep 15 # wait for mongodb to be ready + - mongo mydb_test --eval 'db.addUser("travis", "test");' - sh -c "if [ '$DB' = 'mongodb' ]; then node app --setup=\"{\\\"url\\\":\\\"http://127.0.0.1:4567\\\",\\\"secret\\\":\\\"abcdef\\\",\\\"database\\\":\\\"mongo\\\",\\\"mongo:host\\\":\\\"127.0.0.1\\\",\\\"mongo:port\\\":27017,\\\"mongo:username\\\":\\\"\\\",\\\"mongo:password\\\":\\\"\\\",\\\"mongo:database\\\":0,\\\"admin:username\\\":\\\"admin\\\",\\\"admin:email\\\":\\\"test@example.org\\\",\\\"admin:password\\\":\\\"abcdef\\\",\\\"admin:password:confirm\\\":\\\"abcdef\\\"}\" --ci=\"{\\\"host\\\":\\\"127.0.0.1\\\",\\\"port\\\":27017,\\\"database\\\":0}\"; fi" - sh -c "if [ '$DB' = 'redis' ]; then node app --setup=\"{\\\"url\\\":\\\"http://127.0.0.1:4567\\\",\\\"secret\\\":\\\"abcdef\\\",\\\"database\\\":\\\"redis\\\",\\\"redis:host\\\":\\\"127.0.0.1\\\",\\\"redis:port\\\":6379,\\\"redis:password\\\":\\\"\\\",\\\"redis:database\\\":0,\\\"admin:username\\\":\\\"admin\\\",\\\"admin:email\\\":\\\"test@example.org\\\",\\\"admin:password\\\":\\\"abcdef\\\",\\\"admin:password:confirm\\\":\\\"abcdef\\\"}\" --ci=\"{\\\"host\\\":\\\"127.0.0.1\\\",\\\"port\\\":6379,\\\"database\\\":0}\"; fi" - sh -c "if [ '$DB' = 'postgres' ]; then psql -c 'create database nodebb;' -U postgres; psql -c 'create database travis_ci_test;' -U postgres; node app --setup=\"{\\\"url\\\":\\\"http://127.0.0.1:4567\\\",\\\"secret\\\":\\\"abcdef\\\",\\\"database\\\":\\\"postgres\\\",\\\"postgres:host\\\":\\\"127.0.0.1\\\",\\\"postgres:port\\\":5432,\\\"postgres:password\\\":\\\"\\\",\\\"postgres:database\\\":\\\"nodebb\\\",\\\"admin:username\\\":\\\"admin\\\",\\\"admin:email\\\":\\\"test@example.org\\\",\\\"admin:password\\\":\\\"abcdef\\\",\\\"admin:password:confirm\\\":\\\"abcdef\\\"}\" --ci=\"{\\\"host\\\":\\\"127.0.0.1\\\",\\\"port\\\":5432,\\\"username\\\":\\\"postgres\\\",\\\"database\\\":\\\"travis_ci_test\\\"}\"; fi" diff --git a/src/database/mongo/pubsub.js b/src/database/mongo/pubsub.js index 7a4e7080d6..9d09784afb 100644 --- a/src/database/mongo/pubsub.js +++ b/src/database/mongo/pubsub.js @@ -1,8 +1,10 @@ 'use strict'; var mubsub = require('mubsub-nbb'); - var db = require('../mongo'); -var client = mubsub(db.getConnectionString(), db.getConnectionOptions()); +var client = mubsub(db.getConnectionString(), db.getConnectionOptions()); +client.on('error', function (err) { + console.error('mongo pubsub error', err); +}); module.exports = client.channel('pubsub'); diff --git a/test/mocks/databasemock.js b/test/mocks/databasemock.js index ded9280644..bf9416ae62 100644 --- a/test/mocks/databasemock.js +++ b/test/mocks/databasemock.js @@ -35,7 +35,7 @@ nconf.defaults({ if (!nconf.get('isCluster')) { nconf.set('isPrimary', 'true'); - nconf.set('isCluster', 'false'); + nconf.set('isCluster', 'true'); } var dbType = nconf.get('database'); diff --git a/test/pubsub.js b/test/pubsub.js index 72586f4b2b..1ae3eb5f4f 100644 --- a/test/pubsub.js +++ b/test/pubsub.js @@ -10,11 +10,9 @@ describe('pubsub', function () { it('should use singleHostCluster', function (done) { var oldValue = nconf.get('singleHostCluster'); nconf.set('singleHostCluster', true); - nconf.set('isCluster', true); pubsub.on('testEvent', function (message) { assert.equal(message.foo, 1); nconf.set('singleHostCluster', oldValue); - nconf.set('isCluster', 'false'); pubsub.removeAllListeners('testEvent'); done(); }); @@ -24,11 +22,9 @@ describe('pubsub', function () { it('should use the current database\'s pubsub', function (done) { var oldValue = nconf.get('singleHostCluster'); nconf.set('singleHostCluster', false); - nconf.set('isCluster', true); pubsub.on('testEvent', function (message) { assert.equal(message.foo, 1); nconf.set('singleHostCluster', oldValue); - nconf.set('isCluster', 'false'); pubsub.removeAllListeners('testEvent'); done(); });