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

Ensure storage objects are destroyed on application teardown in tests #377

Merged
merged 2 commits into from
Feb 6, 2024

Conversation

Mikek2252
Copy link
Contributor

Resolves #376
This is to ensure that storage objects are destroyed when the app is torn down in tests, currently objects created by storageFor are not destroyed after the test is torn down, i think this is because the class is returned by a computed property so is not destroyed by the parent that calls storageFor

Storage instances of adapters are destroyed but i have added owner injection to ensure that associateDestroyableChild does not error with a missing owner.

to ensure backward compatibility i have also added the destroyable polyfill

@Mikek2252 Mikek2252 changed the title ass add associateDestroyableChild to ensure storage objects are destroyed of application teardown in tests Feb 2, 2024
Copy link
Member

@fsmanuel fsmanuel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you Michael! That looks great.
I added a small suggestion to add this.isDestroyed to the guard for _save.

@@ -86,6 +91,7 @@ export default Mixin.create({
},

_save() {
if (this.isDestroying) return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (this.isDestroying) return;
if (this.isDestroying || this.isDestroyed) return;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks updated the guard.

@@ -43,7 +43,8 @@
"ember-cli-babel": "^7.26.11",
"ember-cli-string-utils": "^1.1.0",
"ember-cli-version-checker": "^5.1.2",
"ember-copy": "^2.0.1"
"ember-copy": "^2.0.1",
"ember-destroyable-polyfill": "^2.0.3"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good thinking! ❤️

@fsmanuel fsmanuel added the bug label Feb 4, 2024
@fsmanuel fsmanuel changed the title add associateDestroyableChild to ensure storage objects are destroyed of application teardown in tests Ensure storage objects are destroyed on application teardown in tests Feb 6, 2024
@fsmanuel fsmanuel merged commit c8f9856 into funkensturm:master Feb 6, 2024
13 of 14 checks passed
@fsmanuel
Copy link
Member

fsmanuel commented Feb 6, 2024

@Mikek2252 released as v2.0.7. Thanks again for the fix!

@Pixelik
Copy link

Pixelik commented Feb 13, 2024

All of my tests are now failing because of this change.

We have an instance-initializer that uses ember-local-storage and tries to update it and now it fails on every test saying something along the lines "..tried to set the property of a destroyed object" meaning the ember-local-storage is now destroyed when my instance-initializer tries to use it.

@fsmanuel
Copy link
Member

@Pixelik oh no! Can you share the initializer?

@Pixelik
Copy link

Pixelik commented Feb 13, 2024

I will try to find some time and provide you with the code - for now I've downgraded it's ok 🙏

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

Successfully merging this pull request may close these issues.

Memory leak due to objects created in storageFor not being destroyed.
3 participants