{"action":"created","issue":{"url":"https://api.github.com/repos/wallabyjs/public/issues/256","labels_url":"https://api.github.com/repos/wallabyjs/public/issues/256/labels{/name}","comments_url":"https://api.github.com/repos/wallabyjs/public/issues/256/comments","events_url":"https://api.github.com/repos/wallabyjs/public/issues/256/events","html_url":"https://github.com/wallabyjs/public/issues/256","id":105951655,"number":256,"title":"Add \"teardown\" option (counterpart to \"bootstrap\")","user":{"login":"pigulla","id":592561,"avatar_url":"https://avatars.githubusercontent.com/u/592561?v=3","gravatar_id":"","url":"https://api.github.com/users/pigulla","html_url":"https://github.com/pigulla","followers_url":"https://api.github.com/users/pigulla/followers","following_url":"https://api.github.com/users/pigulla/following{/other_user}","gists_url":"https://api.github.com/users/pigulla/gists{/gist_id}","starred_url":"https://api.github.com/users/pigulla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pigulla/subscriptions","organizations_url":"https://api.github.com/users/pigulla/orgs","repos_url":"https://api.github.com/users/pigulla/repos","events_url":"https://api.github.com/users/pigulla/events{/privacy}","received_events_url":"https://api.github.com/users/pigulla/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/wallabyjs/public/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-09-11T06:20:42Z","updated_at":"2015-09-11T07:09:07Z","closed_at":null,"body":"I'm using Wallaby to run tests in parallel, so in my integration tests I need to use a different Mongo database per worker. This is achieved easily enough by appending `process.pid` to the default database name in Wallaby's `bootstrap` function.\r\n\r\nHowever, it is not clear to me how to drop that database when the test run is complete. If I don't, my Mongo will end up being cluttered by countless \"dead\" databases.\r\n\r\nIdeally, one would use the test framework's global `after` hook. But unfortunately, popular frameworks like [Mocha](https://mochajs.org/) do not support this (there are proposed workarounds, but in this case they are [no good](https://github.com/mochajs/mocha/issues/764#issuecomment-139460239)).\r\n\r\nI could do the database setup and teardown each testcase's `before` and `after` hooks, but not only is this unnecessary, it will also have a notable performance impact and potentially cause other issues like having to manually recreate Mongo indices.\r\n\r\nAlso, since Mocha doesn't support parallel execution natively, one could argue that handling this sort of setup and teardown is best located in Wallaby.\r\n\r\nIt seems to me that adding a (asynchronous) `teardown` option to Wallaby's config would be fairly simple to implement and solve this issue very elegantly.\r\n\r\nAlternatively, a \"less perfect\" but probably easier to implement solution could be to expose some sort of \"worker id\" (e.g., its number between 1 and `workers.initial`). If that number was available it could be used instead of the process id to create a database specific to that process and those databases could be reused, essentially rendering the cleanup step above unnecessary.\r\n\r\nThoughts?"},"comment":{"url":"https://api.github.com/repos/wallabyjs/public/issues/comments/139469448","html_url":"https://github.com/wallabyjs/public/issues/256#issuecomment-139469448","issue_url":"https://api.github.com/repos/wallabyjs/public/issues/256","id":139469448,"user":{"login":"pigulla","id":592561,"avatar_url":"https://avatars.githubusercontent.com/u/592561?v=3","gravatar_id":"","url":"https://api.github.com/users/pigulla","html_url":"https://github.com/pigulla","followers_url":"https://api.github.com/users/pigulla/followers","following_url":"https://api.github.com/users/pigulla/following{/other_user}","gists_url":"https://api.github.com/users/pigulla/gists{/gist_id}","starred_url":"https://api.github.com/users/pigulla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pigulla/subscriptions","organizations_url":"https://api.github.com/users/pigulla/orgs","repos_url":"https://api.github.com/users/pigulla/repos","events_url":"https://api.github.com/users/pigulla/events{/privacy}","received_events_url":"https://api.github.com/users/pigulla/received_events","type":"User","site_admin":false},"created_at":"2015-09-11T07:09:07Z","updated_at":"2015-09-11T07:09:07Z","body":"Indeed it does, my apologies. Is suppose having {{afterAll}} documented on Mocha's website would have been helpful.\r\n\r\nThanks for the help, feel free to close this."}}