1

New to node and making a generic express application that connects to MySQL db using sequelize. Doing some unit tests on the db connection with jasmine-node and I keep getting timeouts when i try to connect with sequelize.

// Test the MySQL connection
describe("MySQL", function() {
  it("is connectable", function(next) {
    var mysql = require('mysql');
      var dbconfig = require('../config/database');
      var connection = mysql.createConnection(dbconfig.connection);
      connection.connect( 
        function(err, db) {
            expect(err).toBe(null);
            connection.end();
            next();
        }
    );
  });
  it("is connectable using sequelize", function(next){
    var dbconfig = require('../config/database');
    var Sequelize = require('sequelize');
        var sequelize = new Sequelize(dbconfig.connection.database, dbconfig.connection.user, null,
        function(err, db){
        expect(err).toBe(null);
        sequelize.close();
        next();
      }
    );
  });
});

Of the two tests above, the first passes fine, but the test for sequelize times out. Here is the what I get on the console.

Failures:

  1) MySQL is connectable using sequelize
   Message:
     timeout: timed out after 5000 msec waiting for spec to complete
   Stacktrace:
     undefined

Finished in 6.267 seconds

Here is the database config file.

// config/database.js
module.exports = {
    'connection': {
        'dialect': 'mysql',
        'user': 'root',
        'password': '',
        'host': 'localhost',
        'port' : '3306',
        'database': 'my_node_db'
    }

};
WhyAyala
  • 647
  • 7
  • 29
  • You are using dbconfig.connection.username in your connection string. The object uses user... – Gary Dec 10 '15 at 18:26
  • @Gary that's a typo, however not the issue. I've passed it in as user, I still get a time out. I've also tried passing it as a uri and get a time out. – WhyAyala Dec 10 '15 at 18:36
  • It does not look like the constructor for Sequelize provides a callback like you have defined. Check for connection with var sequelize = new Sequelize("db", "user", "pass"); sequelize.authenticate().then(function(errors) { console.log(errors) }); – Gary Dec 10 '15 at 18:48
  • @Gary it spits out an error of 'undefined' to the console before timing out again. – WhyAyala Dec 10 '15 at 19:28

0 Answers0