Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postgres database connections are jumbled up after running tests and restarting the application #292

Closed
priornix opened this issue Jun 19, 2017 · 3 comments

Comments

@priornix
Copy link
Contributor

priornix commented Jun 19, 2017

Postgres database connections are jumbled up after running lein repl and lein test consecutively, reloading the database namespace and restarting the application.

Luminus version: 2.9.11.60
Clojure version: 1.8.0
Java version: 1.8.0_131

Steps to reproduce

  1. Create a new luminus project with +postgres profile
  2. Modify profiles.clj to point to the dev and test databases.
  3. Run lein repl and (start) the application.
  4. Load the database namespace and create a new user:
=> (require '[foobar.db.core :as db])
=> (db/create-user! {:id "ha" :first_name "ha" :last_name "ha" :email "ha" :pass "ha" })`
  1. Verify that the user exists:
=> (db/get-user {:id "ha"})
{:admin nil :email "ha" :first_name "ha" :id "ha" :is_active nil :last_login nil :last_name "ha" :pass "ha"}
  1. On another terminal window, start lein test and wait till the test is completed.
  2. Reload the database namespace and restart the application
=> (require '[foobar.db.core :as db] :reload)
=> (restart)
  1. The created user can no longer be found:
=> (db/get-user {:id "ha"})
nil
  1. The database connection is now pointing to the one specified in the test profile instead of dev. To verify, add a new user using create-user!, the new user now appears in the test database, which is incorrect.

luminus bug

@priornix priornix changed the title Postgres database connections are jumbled up after running tests and restarting the app Postgres database connections are jumbled up after running tests and restarting the application Jun 19, 2017
@yogthos
Copy link
Member

yogthos commented Jun 21, 2017

I think the issue might be caused by the fact that the .lein-env file is regenerated when the test profile is run and the changes are picked up from there.

@yogthos
Copy link
Member

yogthos commented Jun 21, 2017

One solution would be to not restart env in the restart function:

(defn start []
  (mount/start-without #'app.core/repl-server
                       #'app.config/env))

(defn stop []
  (mount/stop-except #'app.core/repl-server
                     #'app.config/env))

@yogthos
Copy link
Member

yogthos commented Jan 1, 2018

I finally got around to resolving this. The new template no longer uses profiles.clj to track environment variables. Instead, there are two separate files called dev-config.edn and test-config.edn for tracking dev and test configurations respectively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants