-
-
Notifications
You must be signed in to change notification settings - Fork 910
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 intermittent test failures #1274
Fix intermittent test failures #1274
Conversation
I am happy to have discovered a possible solution:
So, we know that this method was returning a record from the first test and because of that it was missing the new columns created on the second test. A quick fix for this is to execute reload on this instance. To test this solution, run this command on the master and then on this branch:
PS: Remember to change What do you guys think about this? Or should I take a second look at this? |
Yeah, so it's really weird to me that this bug is happening. It's easy enough to see that data is somehow leaking to other tests, but what's not easy to see is how. The fact that in one test you see an instance of Example being represented one way vs. another tells me that the model is caching the schema for that table per test. This makes sense because 1) both tests are defining an So in terms of your solution, conceptually, it gets close to the underlying problem, I think, but I'm still kind of confused as to why it works. Checking the source of self.class.connection.clear_query_cache So I wonder what would happen if after this line you inserted: DevelopmentRecord.connection.clear_query_cache
ProductionRecord.connection.clear_query_cache |
Thank you for all this information! Unfortunately, your suggestion didn't work. The error continues. But If I add this line:
inside define_model also fixes the tests. In this case, we are resetting the cached information about columns when a define_model occurs. We are already using this method right here:
But is not as effective as inside the define_model. So, what do you think about moving this piece of code to define_model? Another positive point for this change is that the interaction will no longer be necessary. |
Aha! So now that you mention it, resetting the column information for a model after defining it (and right before removing it from the object space) isn't very helpful. Your solution makes perfect sense. |
Reset all cached information about columns after defining the model to prevent old columns from leaking for other tests. e.g.: https://travis-ci.org/thoughtbot/shoulda-matchers/jobs/622356910
EDIT 1: Done! 👍 |
Hi, @mcmire, I was wondering if something is missing here or maybe you're waiting to check if the error will happen ever again. Sorry, I'm just curious if this PR is useful or needs any changes. |
Hey @vsppedro, sorry about that and thanks for reminding me about this. Everything looks good here so I'll merge it in! |
No problem, thanks! |
Hi, this pull request is a draft for now.
I'm looking for a solution to the issue #1262.
Below are some notes about the problem.
How to recreate the error locally?
The smallest possible scenario for this error to happen:
If we try to run only the test that failed:
It pass:
So what it's happening in the first test to make the second test to go wrong?
If we run these tests separetely will we see that the first test creates this record:
#<Example:0x000055aa97f1c010 id: 1, attr: "some valuf">
And when we try to run other alone it creates this:
#<Example:0x00007fbb0404c128 id: 1, attr: "dummy value", scope1: true, scope2: true>
Both pass!
But when we run both the second test creates this:
#<Example:0x000055aa9a305828 id: 1, attr: "dummy value">
Look, it's missing the scope1 and scope2. That's why the error missing attribute: :scope1. This error is happening right here after receive the scope1 as
attribute_name
.One easy fix for this is to change the model name used in the second test, after that the record created in the second test has all his fields (including scope1 and scope2), but I'm don't think this is a good idea. I think I need to understand more about this feature to make a proper fix.
I'll keep digging! 😄
PS: My sincere thanks to thoughbot for this video, rspec-bisect, it helped a lot to isolate the smallest possible scenario. Great video! 👍 👍 👍