{"action":"created","issue":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/8918","repository_url":"https://api.github.com/repos/sequelize/sequelize","labels_url":"https://api.github.com/repos/sequelize/sequelize/issues/8918/labels{/name}","comments_url":"https://api.github.com/repos/sequelize/sequelize/issues/8918/comments","events_url":"https://api.github.com/repos/sequelize/sequelize/issues/8918/events","html_url":"https://github.com/sequelize/sequelize/issues/8918","id":290032999,"number":8918,"title":"sequelize.sync not completed when resolving","user":{"login":"tgroutars","id":7382760,"avatar_url":"https://avatars1.githubusercontent.com/u/7382760?v=4","gravatar_id":"","url":"https://api.github.com/users/tgroutars","html_url":"https://github.com/tgroutars","followers_url":"https://api.github.com/users/tgroutars/followers","following_url":"https://api.github.com/users/tgroutars/following{/other_user}","gists_url":"https://api.github.com/users/tgroutars/gists{/gist_id}","starred_url":"https://api.github.com/users/tgroutars/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tgroutars/subscriptions","organizations_url":"https://api.github.com/users/tgroutars/orgs","repos_url":"https://api.github.com/users/tgroutars/repos","events_url":"https://api.github.com/users/tgroutars/events{/privacy}","received_events_url":"https://api.github.com/users/tgroutars/received_events","type":"User","site_admin":false},"labels":[{"id":801281127,"url":"https://api.github.com/repos/sequelize/sequelize/labels/support","name":"support","color":"a5ffa0","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-01-19T16:30:15Z","updated_at":"2018-02-23T05:37:29Z","closed_at":null,"author_association":"NONE","body":"## What are you doing?\r\nI'm using Jest to test my code. I use a setup script with the following code\r\n\r\n```js\r\nconst { sequelize } = require('/path/to/models');\r\n\r\nbeforeAll(async () => {\r\n  await sequelize.sync();\r\n});\r\n```\r\nHowever, everytime I add a new model, my tests fail once on circleci, then get fixed when I rebuild. I'm pretty sure sequelize.sync hasn't finished at the time it resolves.\r\n\r\nAs a workaround, I instantiate a new instance of Sequelize to perform the sync and close it before running my tests\r\n\r\n```js\r\nconst { \r\n  sequelize, \r\n  newSequelize /* instantiates a new instance with the same config */ \r\n} = require('/path/to/models');\r\n\r\nbeforeAll(async () => {\r\n  const setupSequelize = newSequelize();\r\n  await setupSequelize.sync();\r\n  await setupSequelize.close();\r\n});\r\n```\r\nBut it seems hacky\r\n\r\n## What do you expect to happen?\r\nI expect sequelize.sync to have completed at the time it resolves\r\n\r\n## What is actually happening?\r\nsequelize.sync resolves before having completed\r\n\r\n__Dialect:__ postgres\r\n__Dialect version:__ pg@6.4.2\r\n__Database version:__ PostgreSQL 10.1\r\n__Sequelize version:__ sequelize@4.31.0\r\n__Tested with latest release:__ No, but it's not easy to reproduce as the error doesn't happen all the time, only when the tests start before sequelize.sync having completed\r\n"},"comment":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/comments/367915100","html_url":"https://github.com/sequelize/sequelize/issues/8918#issuecomment-367915100","issue_url":"https://api.github.com/repos/sequelize/sequelize/issues/8918","id":367915100,"user":{"login":"Jadex1","id":1895412,"avatar_url":"https://avatars2.githubusercontent.com/u/1895412?v=4","gravatar_id":"","url":"https://api.github.com/users/Jadex1","html_url":"https://github.com/Jadex1","followers_url":"https://api.github.com/users/Jadex1/followers","following_url":"https://api.github.com/users/Jadex1/following{/other_user}","gists_url":"https://api.github.com/users/Jadex1/gists{/gist_id}","starred_url":"https://api.github.com/users/Jadex1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jadex1/subscriptions","organizations_url":"https://api.github.com/users/Jadex1/orgs","repos_url":"https://api.github.com/users/Jadex1/repos","events_url":"https://api.github.com/users/Jadex1/events{/privacy}","received_events_url":"https://api.github.com/users/Jadex1/received_events","type":"User","site_admin":false},"created_at":"2018-02-23T05:37:29Z","updated_at":"2018-02-23T05:37:29Z","author_association":"NONE","body":"I'm currently using Jest. I don't have this exact setup(I haven't put it on CircleCI yet), but I am using jest. I have noticed that despite having sync and alter on, when jest re runs the tests it doesn't seem to rebuild the db correctly. If I restart the tests and run my whole script it again, everything runs correctly. "}}
{"actor":{"display_login":"Jadex1"}}