orientjs icon indicating copy to clipboard operation
orientjs copied to clipboard

Migration.Manager.up() remains hanged after completion

Open georgiana-b opened this issue 8 years ago • 4 comments

I use Migration.Manager.up() 2 times in my app: in a migrate script, where I call process.exit() after it finishes, and in my tests, as a before hook. The problem is that this function remains hanged even after all the migrations have been executed and the then after it was called. I'm not so advanced in Node.js but I guess we could describe this as lacking an end event. This is not a problem in the migration script because of the process.exit() but it makes it impossible to use MigrationManagaer.up() in other circumstances.

Here is a demonstration in the node console:

> const OrientDB = require('orientjs');
undefined
> let attrs =  {
...   "host": "localhost",
...   "port": 2424,
...   "httpPort": 2480,
...   "username": "root",
...   "password": "root"
... }
> let ODBServer= new OrientDB.Server(attrs)
undefined
> ODBServer
Server {
  useToken: false,
  configuration: 
   { host: 'localhost',
     port: 2424,
     httpPort: 2480,
     username: 'root',
     password: 'root' },
  logger: 
   { error: [Function: bound bound consoleCall],
     log: [Function: bound bound consoleCall],
     debug: [Function] },
  transport: 
   BinaryTransport {
     domain: 
      Domain {
        domain: null,
        _events: [Object],
        _eventsCount: 1,
        _maxListeners: undefined,
        members: [] },
     _events: { reset: [Function: bound ] },
     _eventsCount: 1,
     _maxListeners: Infinity,
     connecting: false,
     closing: false,
     retries: 0,
     maxRetries: 5,
     host: 'localhost',
     port: 2424,
     username: 'root',
     password: 'root',
     servers: [ [Object] ],
     currentServer: 0,
     enableRIDBags: true,
     useToken: false,
     token: null,
     sessionId: -1,
     logger: 
      { error: [Function: bound bound consoleCall],
        log: [Function: bound bound consoleCall],
        debug: [Function] },
     connection: 
      Connection {
        domain: [Object],
        _events: [Object],
        _eventsCount: 3,
        _maxListeners: Infinity,
        host: 'localhost',
        port: 2424,
        socket: null,
        logger: [Object],
        enableRIDBags: true,
        closing: false,
        reconnectNow: false,
        protocol: null,
        queue: [],
        writes: [],
        remaining: null } },
  config: 
   { get: [Function: bound ],
     set: [Function: bound ],
     list: [Function: bound ] },
  domain: 
   Domain {
     domain: null,
     _events: { error: [Function: debugDomainError] },
     _eventsCount: 1,
     _maxListeners: undefined,
     members: [] },
  _events: {},
  _eventsCount: 0,
  _maxListeners: Infinity,
  connected: false }
> let ODB = ODBServer.use('elvis-testing')
undefined
> ODB
Db {
  sessionId: -1,
  forcePrepare: true,
  name: 'elvis-testing',
  server: 
   Server {
     useToken: false,
     configuration: 
      { host: 'localhost',
        port: 2424,
        httpPort: 2480,
        username: 'root',
        password: 'root' },
     logger: 
      { error: [Function: bound bound consoleCall],
        log: [Function: bound bound consoleCall],
        debug: [Function] },
     transport: 
      BinaryTransport {
        domain: [Object],
        _events: [Object],
        _eventsCount: 1,
        _maxListeners: Infinity,
        connecting: false,
        closing: false,
        retries: 0,
        maxRetries: 5,
        host: 'localhost',
        port: 2424,
        username: 'root',
        password: 'root',
        servers: [Array],
        currentServer: 0,
        enableRIDBags: true,
        useToken: false,
        token: null,
        sessionId: -1,
        logger: [Object],
        connection: [Object] },
     config: 
      { get: [Function: bound ],
        set: [Function: bound ],
        list: [Function: bound ] },
     domain: 
      Domain {
        domain: null,
        _events: [Object],
        _eventsCount: 1,
        _maxListeners: undefined,
        members: [] },
     _events: { reset: [Function: bound ] },
     _eventsCount: 1,
     _maxListeners: Infinity,
     connected: false },
  type: 'graph',
  storage: 'plocal',
  token: null,
  useToken: false,
  username: 'admin',
  password: 'admin',
  dataSegments: [],
  transactionId: 0,
  transformers: {},
  transformerFunctions: {},
  cluster: 
   { cached: false,
     list: [Function: bound ],
     create: [Function: bound ],
     get: [Function: bound ],
     getByName: [Function: bound ],
     getById: [Function: bound ],
     drop: [Function: bound ],
     count: [Function: bound ],
     range: [Function: bound ],
     cacheData: [Function: bound ] },
  class: 
   { cached: false,
     list: [Function: bound ],
     create: [Function: bound ],
     update: [Function: bound ],
     drop: [Function: bound ],
     get: [Function: bound ],
     cacheData: [Function: bound ] },
  record: 
   { create: [Function: bound ],
     get: [Function: bound ],
     resolveReferences: [Function: bound ],
     meta: [Function: bound ],
     update: [Function: bound ],
     delete: [Function: bound ] },
  vertex: [Getter],
  edge: [Getter],
  index: 
   { cached: false,
     list: [Function: bound ],
     create: [Function: bound ],
     drop: [Function: bound ],
     get: [Function: bound ],
     cacheData: [Function: bound ] } }
> let migrationMan = new OrientDB.Migration.Manager({db: ODB, dir: '/home/g/Documents/elvis-backend-node/migrations'})
undefined
> migrationMan
MigrationManager {
  name: '',
  db: 
   Db {
     sessionId: -1,
     forcePrepare: true,
     name: 'elvis-testing',
     server: 
      Server {
        useToken: false,
        configuration: [Object],
        logger: [Object],
        transport: [Object],
        config: [Object],
        domain: [Object],
        _events: [Object],
        _eventsCount: 1,
        _maxListeners: Infinity,
        connected: false },
     type: 'graph',
     storage: 'plocal',
     token: null,
     useToken: false,
     username: 'admin',
     password: 'admin',
     dataSegments: [],
     transactionId: 0,
     transformers: {},
     transformerFunctions: {},
     cluster: 
      { cached: false,
        list: [Function: bound ],
        create: [Function: bound ],
        get: [Function: bound ],
        getByName: [Function: bound ],
        getById: [Function: bound ],
        drop: [Function: bound ],
        count: [Function: bound ],
        range: [Function: bound ],
        cacheData: [Function: bound ] },
     class: 
      { cached: false,
        list: [Function: bound ],
        create: [Function: bound ],
        update: [Function: bound ],
        drop: [Function: bound ],
        get: [Function: bound ],
        cacheData: [Function: bound ] },
     record: 
      { create: [Function: bound ],
        get: [Function: bound ],
        resolveReferences: [Function: bound ],
        meta: [Function: bound ],
        update: [Function: bound ],
        delete: [Function: bound ] },
     vertex: [Getter],
     edge: [Getter],
     index: 
      { cached: false,
        list: [Function: bound ],
        create: [Function: bound ],
        drop: [Function: bound ],
        get: [Function: bound ],
        cacheData: [Function: bound ] } },
  dir: '/home/g/Documents/elvis-backend-node/migrations',
  className: 'Migration' }
migrationMan.up().then((migrated) => console.log(migrated))
Promise {
  _bitField: 131072,
  _fulfillmentHandler0: undefined,
  _rejectionHandler0: undefined,
  _progressHandler0: undefined,
  _promise0: undefined,
  _receiver0: undefined,
  _settledValue: undefined,
  _boundTo: 
   MigrationManager {
     name: '',
     db: 
      Db {
        sessionId: -1,
        forcePrepare: true,
        name: 'elvis-testing',
        server: [Object],
        type: 'graph',
        storage: 'plocal',
        token: null,
        useToken: false,
        username: 'admin',
        password: 'admin',
        dataSegments: [],
        transactionId: 0,
        transformers: {},
        transformerFunctions: {},
        cluster: [Object],
        class: [Object],
        record: [Object],
        vertex: [Getter],
        edge: [Getter],
        index: [Object] },
     dir: '/home/g/Documents/elvis-backend-node/migrations',
     className: 'Migration' } }
> [ 'm20171024_180820_create_price_class',
  'm20171024_180923_create_tender_vertex',
  'm20171024_184102_create_address_class']

// And then it just hangs here until I stop it

I'm using Node.js 8.0.0, OrientDB 2.2.26 and Orientjs 2.2.7.

georgiana-b avatar Nov 16 '17 12:11 georgiana-b

Hi @georgiana-b

does the migrationMan.up().then((migrated) => console.log(migrated))

console.log get called?

wolf4ood avatar Nov 16 '17 13:11 wolf4ood

does the migrationMan.up().then((migrated) => console.log(migrated)) console.log get called?

@maggiolo00 Yes, that's what outputs that last array. But then the process remains hanged.
For example if I have a before hook like:

function createDB() {
  return config.migrationManager.up();
}

my tests execute but once they are all done the test process remain hanged. This phenomenon doesn't happen if I return other promises in that hook. With a hook like the one below tests run predictably and the process ends after all tests have been run.

function createDB() {
  return Promise.resolve(2);
}

georgiana-b avatar Nov 16 '17 15:11 georgiana-b

You can find the whole example here.

georgiana-b avatar Nov 16 '17 15:11 georgiana-b

For anyone interested, I couldn't avoid this problem with Mocha and I ended up switching to Ava.js.

In Ava I use the same strategy of migrating up in a before hook but the process doesn't remain hanged. So, this issue might in fact be caused by how Mocha handles the Migration.Manager.up() promise not with the promise itself.

Feel free to close this if you don't want to look more into it.

georgiana-b avatar Dec 02 '17 17:12 georgiana-b