-
Notifications
You must be signed in to change notification settings - Fork 29
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
Fix "redefining module" warnings in test suite #12
Comments
FYI I'm getting similar warnings in the app that uses apartmentex, when I call |
Yeah I think this will be something we see since we are defining the same module twice by loading it with ecto migrator. I'm not sure if there are any performance implications of reloading a module for each tenant migration, but I'd guess they are small. for the tests, this ignores the warnings: |
so changing the Ok, so the above doesn't work since when a file is already loaded, require_file returns nil which is not enumerable. Really what migrate/4 should be enumerating is the loaded migration modules, rather than the actual file migrations. Having said that, we'd need an agent to keep track of the loaded migration modules across migrations that may happen during app runtime, and it should start with ecto or the app. We aren't able to use the runner process from /lib/ecto/migration/runner.ex either, since it only calls start_link at the time it is invoked by the migrator loading the files, and is transient to each time migrate is called. I'm thinking to hang onto already loaded migration modules in a long running, supervised process so we don't load them again, but this is probably outside the scope of ecto itself. I can't see another way to do this without bringing back Apartmentex.Migration. What do you think? |
@Dania02525 @iancanderson Did you guys figure this out a way to suppress these warnings? I'm getting the same. |
@brandonparsons you should be able to ignore the warnings by putting this: |
Thanks - yes this does stop the warnings in test. I'm not seeing any of these errors cropping up when poking around in iEx (that's as close as I have to a dev application at the moment). |
Actually I take that back - I do see these in the iEx console when adding new tenants and it tries to migrate their respective schemas. I did not set |
@Dania02525 I believe this is probably related, but under certain configurations, I think this is causing errors to be thrown.
If it helps - I'm creating two separate tenants inside the |
Stacktrace:
|
I also got this issue, and another one talking about deadlocks. It seems to be because of the migration beeing executed in parallel in the tests. I set But wouldn't it be possible that we get these errors again in dev or production if multiple tenants are created at the same time? |
I can confirm with a small code:
That creating a tenant cannot be done asynchronously :( |
Are you seeing a Postgres error, meaning a table is locked, or an elixir/erlang error? The migrators are separate processes, and the actual migrations should happen in separate schemas (obviously), so maybe we're getting a lock on writing to the tenants table in the public schema? |
I don't remember exactly and I totally changed my code :( |
This is from Ecto when it loads the file: https://github.com/elixir-ecto/ecto_sql/blob/master/lib/ecto/migrator.ex#L443 As we can see, each time the migrator runs, it executes Link to the doc: https://hexdocs.pm/elixir/1.6.6/Code.html#load_file/2 |
Actually, now that I think of it, Ecto could use |
I noticed that there are a bunch of warnings when running the test suite like this:
I think this has to do with the way the
Ecto.Migrator
is loading the code in the migration files, but I'm not sure if the fix should be within Ecto or within Apartmentex. Thoughts?Here's where the migrator loads the code in the migration files:
https://github.com/elixir-ecto/ecto/blob/master/lib/ecto/migrator.ex#L239
The text was updated successfully, but these errors were encountered: