feathers-plus / cli

FeathersJS CLI supporting both REST and GraphQL architectural concepts and their query languages.
https://generator.feathers-plus.com/
Other
43 stars 7 forks source link

Feathers Seed MongoDB Race Condition #31

Closed arranf closed 5 years ago

arranf commented 5 years ago

Steps to reproduce

  1. Generate a basic feathers app with MongoDB
  2. Seed data

Expected behavior

The data is seeded Tell us what should happen

Actual behavior

Data fails to seed. The MongoDB connection is not guaranteed to be active when the call to seed-data occurs causing feathers-mongodb to fail to perform any service calls.

This is fixed by using setTimeout() with a reasonable (~2-3 second) timeout.

System configuration

Module versions (especially the part that's not working):

{
  "engines": {
    "node": "^10.0.0",
    "yarn": ">= 0.18.0"
  },
  "scripts": {
    "test": "yarn run eslint && yarn run mocha",
    "test:all": "yarn run eslint && NODE_ENV=test npm run mocha",
    "eslint": "eslint src/. test/. --config .eslintrc.json",
    "dev": "nodemon src/",
    "start": "node src/",
    "start:seed": "NODE_ENV=test node src/ --seed",
    "mocha": "mocha test/ --recursive --exit --timeout 10000"
  },
  "dependencies": {
    "@feathers-plus/test-utils": "^0.3.5",
    "@feathersjs/authentication": "^2.1.7",
    "@feathersjs/authentication-jwt": "^2.0.1",
    "@feathersjs/authentication-local": "^1.2.1",
    "@feathersjs/configuration": "^2.0.0",
    "@feathersjs/errors": "^3.3.0",
    "@feathersjs/express": "^1.2.3",
    "@feathersjs/feathers": "^3.1.7",
    "@feathersjs/socketio": "^3.2.2",
    "ajv": "5.5.2",
    "compression": "^1.7.3",
    "cors": "^2.8.4",
    "cross-env": "^5.2.0",
    "feathers-hooks-common": "^4.16.3",
    "feathers-mongodb": "^3.3.0",
    "feathers-sequelize": "^3.1.2",
    "helmet": "^3.13.0",
    "lodash.merge": "^4.6.1",
    "mongodb": "^3.1.1",
    "mongodb-core": "^3.1.11",
    "pg": "^7.8.0",
    "sequelize": "^4.38.0",
    "sequelize-cli": "^5.4.0",
    "serve-favicon": "^2.5.0",
    "winston": "^3.0.0"
  },
  "devDependencies": {
    "eslint": "^5.3.0",
    "mocha": "^5.2.0",
    "nodemon": "^1.18.3",
    "request": "^2.88.0",
    "request-promise": "^4.2.2"
  }
}

MongoDB Version: 4.0.6

NodeJS version: 10

Operating System Ubuntu

eddyystop commented 5 years ago

This will soon be handled via PR https://github.com/feathers-plus/generator-feathers-plus/pull/233 .

People have settled on posting issues in f+/generator-feathers-plus rather than f+/cli so please post any followup comments there. Thanks.

arranf commented 5 years ago

Hey Eddy. Great news! It might be good to mark that in the repo somewhere.

Arran

On Wed, 27 Feb 2019, at 12:56 PM, Eddyystop wrote:

Closed #31 https://github.com/feathers-plus/cli/issues/31.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/feathers-plus/cli/issues/31#event-2167889293, or mute the thread https://github.com/notifications/unsubscribe-auth/AITM9luuwH092-u77KJb3RZJ8FI6_xd0ks5vRoB_gaJpZM4bT7n4.

eddyystop commented 5 years ago

The MongoDB promise is in app.get('mongoClient'), so the way people handled this was by adding await app.get('mongoClient') in src/index.js at // !code: listening // !end.

This PR is to generalize that so other services and custom code can use the same scaffolding.

eddyystop commented 5 years ago

Resolved with PR https://github.com/feathers-plus/generator-feathers-plus/pull/249 .

This inserts app.get('mongoClient') and app.get('sequelizeClient') in src/index.js. We did not go with PR https://github.com/feathers-plus/generator-feathers-plus/pull/233 as we did not want to add cognative load.

eddyystop commented 5 years ago

Published as f+/cli v0.8.8 which uses generator v0.8.8