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

Tests instantiating models with relationships fail on ember-canary #5465

Closed
bendemboski opened this issue May 4, 2018 · 9 comments · Fixed by #5467
Closed

Tests instantiating models with relationships fail on ember-canary #5465

bendemboski opened this issue May 4, 2018 · 9 comments · Fixed by #5467

Comments

@bendemboski
Copy link

Here is an addon demonstrating the issue. It's just a vanilla addon with ember-data installed and a couple of models generated, user which belongsTo organization.

If you run ember try:one ember-canary (as of the filing time of this issue), it will fail because it hits this newly-added assertion:

not ok 12 Chrome 66.0 - Unit | Model | user: it exists
    ---
        actual: >
            null
        stack: >
            Error: Assertion Failed: expected container not to be destroyed
                at new EmberError (http://localhost:7357/assets/vendor.js:18994:25)
                at assert (http://localhost:7357/assets/vendor.js:16297:15)
                at Container.factoryFor (http://localhost:7357/assets/vendor.js:37787:58)
                at Class.factoryFor (http://localhost:7357/assets/vendor.js:59270:33)
                at Class.modelFactoryFor (http://localhost:7357/assets/vendor.js:86413:20)
                at Class._modelFactoryFor (http://localhost:7357/assets/vendor.js:86376:22)
                at Class._modelFor (http://localhost:7357/assets/vendor.js:86367:29)
                at Class.modelFor (http://localhost:7357/assets/vendor.js:86360:17)
                at Function.typeForRelationship (http://localhost:7357/assets/vendor.js:77253:34)
                at Function._findInverseFor (http://localhost:7357/assets/vendor.js:77311:28)
        message: >
            Promise rejected after "it exists": Assertion Failed: expected container not to be destroyed
        Log: |
    ...

This is happening because when the store is unloading the organization record (resulting from tearing down the test context), it looks at its relationships, which ultimately results in a modelFor call to look up the user model at the other end of the relationship, which looks it up in the container, which is already destroyed. It looks like this has been happening for a long time, but is just now failing because of the newly-added assertion. I'm not sure if ember-data's behavior is incorrect, or if the assertion is overly aggressive.

bendemboski referenced this issue in emberjs/ember.js May 4, 2018
noise when a container is leaked.

Add asserts if lookup and factoryFor are called after destroy.
@rwjblue
Copy link
Member

rwjblue commented May 4, 2018

I'm not sure if ember-data's behavior is incorrect, or if the assertion is overly aggressive.

Probably a bit of both. 😆

The goal of the assertion is to ensure that a destroyed container (which has released all of its instances and whatnot for GC) does not have additional lookup methods called on it (which would now leak memory because there is no way to run destroy again). Depending on how hard this is to fix in ember-data we could change the upstream assertion into a warning or a private API deprecation slated for 3.5 removal, but either way the underlying issue reported here (doing owner.lookup or owner.factoryFor after destruction) should be addressed.

Thank you for reporting!

@wagenet
Copy link
Member

wagenet commented Jun 15, 2018

I'm finding this happens in routes where I call controllerFor in a deactivate hook.

@wagenet
Copy link
Member

wagenet commented Jun 15, 2018

@rwjblue

@wagenet
Copy link
Member

wagenet commented Jun 16, 2018

I'm also seeing this happening when records are destroyed during teardown and it attempts to access the inverse meta.

@wagenet
Copy link
Member

wagenet commented Jun 20, 2018

Fixed in emberjs/ember.js#16754

@GreatWizard
Copy link

GreatWizard commented Aug 3, 2018

I just reproduce the problem on ember 3.3.1 with a generated model when I add a relationship.

The generated test fails with the same error Error: Assertion Failed: expected container not to be destroyed

EDIT: I rollback on ember 3.1 for now

@ryanto
Copy link
Contributor

ryanto commented Sep 10, 2018

I found this issue from Google. I'm running into this in an addon I'm writing tests for.

In my Ember try scenarios I have no container leak when using with Ember 3.1 and Ember Data 3.1.

However, In Ember 3.4 with Ember Data 3.4 this assertion pops up and there is a Container leak and the assertion causes my tests to fail.

The container leak/assertion failure only happens when I try to access Ember Data. For example, the failure happens when testing a route that calls store.findRecord, but the failure won't happen on tests that don't touch code that relies on data.

Right now my travis builds are failing for 3.4 (ember-release + data release) and I'm a little suck on how to get them working.

I'm unsure how to proceed or what I should be doing in this situation.

@runspired
Copy link
Contributor

In my Ember try scenarios I have no container leak when using with Ember 3.1 and Ember Data 3.1.

@ryanto I think the issues you want are #5554 and emberjs/ember.js#16860

@ryanto
Copy link
Contributor

ryanto commented Sep 11, 2018

Cool! I'll give those a read.

Also, I was getting hardcore trolled by npm dependencies earlier today. I think what I originally posted was incorrect and the result of bad dependency resolution. My final build was ending up with Ember 3.4 + ED 2.18... which causes that assertion error.

So if anyone comes across this error, double check that you're not using a data 2.x with Ember 3.4!

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

Successfully merging a pull request may close this issue.

6 participants