-
Notifications
You must be signed in to change notification settings - Fork 198
[proposal] Always reset all test fixtures #3499
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
base: master
Are you sure you want to change the base?
[proposal] Always reset all test fixtures #3499
Conversation
44aa21a to
cb9baba
Compare
adrw
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, going to wait for one more review and then merge.
I might be misunderstanding this, but Curious though, are you leveraging misk test injector reuse to speed up your tests? |
@mmollaverdi I think if you use instance bindings then it'll have an effect. For instance if I have object FakeFoo : Foo, TestFixture
multibind<TestFixtures>().toInstance(FakeFoo)You're right that the binding itself is scoped to the injector, but the actual thing it's injecting (FakeFoo) is not. So in this case, injecting a
We do not — I'm not sure exactly why as I wasn't around for our initial setup but IMO it's confusing regardless that object test fixtures don't properly get reset |
|
Makes sense |
|
@adrw or @mmollaverdi either of you able to approve the workflow so we can merge this thing? much appreciated for your help with this PR! 🙏 |
|
@mgulbronson Apologies for the delay, I thought this had already merged, I'll try and shepherd it through today. |
|
@mgulbronson Not sure why but some test seems to keep timing out in the testShardNonHibernate, I've triggered a rebuild a few times so it might not be a test flake but a regression from your code change. Do you mind taking a look? |
@adrw I think I see the issue — will try to get a fix up today but may wait until after the holidays |
Description
Currently if the injector is not reused no test fixtures are reset, presumably because it's assumed the test fixtures are scoped to the injector and will therefore be reconstructed for each test when the injector is created. But test fixtures that are Kotlin objects aren't scoped to the injector, they're scoped to the JVM classloader and therefore persist across tests/injectors. So if the injector is not reused, those test fixtures never get reset.
Practically this means that binding a test fixture doesn't do anything. This PR makes it so all test fixtures are always reset, making it possible to implement test fixtures as objects.
Alternative approach that I did originally was to reflect on the test fixtures to check if they're an object or not. For test fixtures that aren't objects no change from the current behaviour is needed. For test fixtures that are objects they need to be reset every time (regardless of whether the injector is being reused). But realistically the cost of reflecting over the test fixtures is more expensive than just resetting all test fixtures.