test: Use test-listener rather than TestBase to assure quiescence after each method.#5833
Conversation
Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
|
Can you open a tracking issue and document why we need this and why it's a good idea? I think I could use a bit more context Unit tests are supposed to be standalone - by default I'm not a big fan of anything changing global state on them |
|
Please merge master to pick up #5827. |
|
Also have we looked into alternates? AFIK internal gtest has built in flagsavers - not sure if there's hooks for one off registration like you want or if they hard-coded in-house Also on alternates, I'm a heavy user of gtest_filter/gunit_filter and losing TestSuite.Test is sad. would it be a pain to have our own macro function which called your function before test code rather than losing the standard gtest naming? |
|
RE test-naming: let's call that a blocker for this PR; I was wondering how critical that was. I have an alternate approach to interpose a new test-class. This transformation is more complicated (but tractable) to apply at scale. However, frequently in the codebase, we test class Foo with I'm also fine with defining a macro to replace |
In this implementation, we need to put the test-body as a third macro arg, so we can wrap it in a scoped object. This is more syntactically invasive, but avoids altering any names of tests or fixtures. Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
|
@alyssawilk PTAL at the latest commits, in particular the new macro TEST_E (suggestions welcome on name) and the one file I reworked in that style, test/common/runtime/uuid_util_test.cc This avoids changing any test or fixture names, but requires a broad syntactic change by putting the entire test-body in a macro arg. Suggestions also welcome on how better to do this. |
Signed-off-by: Joshua Marantz <jmarantz@google.com>
Worth maybe talking to the googletest folks? I wonder if an upstream change might be the better way to do this? Some hook where we can use a custom base class for a TEST? |
|
+1 to what Matt said. We've managed to make changes to gmock for Envoy-specific asks, and I think this is a generically useful feature (which we either do use inside with a one-off or could). If we're not in a desperate hurry and gtest is amenable I think we could do this cleanly in O(weeks) and it seems better than updating every test name and/or custom closure semantics. |
|
Also on the other PR do we have checks in the fix_format script to not use the normal test-base? If not I strongly encourage adding them both for the last change and for whatever we do here. |
|
RE "check_format" checks for avoiding "TEST(" -- yes, in this PR. For deriving test-classes from testing::Test? Yes, already in master. RE "change gtest" -- that sounds reasonable. Just one other quick taste-test on something we could do with the current technology. WDYT of this transform: old: new: This would work most of the time, and be achievable with automation. FooTest might collide here or there and would need to be resolved manually in the context of the PR. Would that be a decent outcome? If not I'll contact the gtest team. |
|
How would you automate? Or you mean you could script the one time change? FWIW I think you can also get away with aliasing FooTest to TestBase rather than declaring a new class and still have gtest filter work. I think I'd take that over the current macro though, so good call. |
|
by aliasing do you mean Automation would be via one-time script. |
|
Yeah, I had concerns about that for the protocol integration test and turns out it works fine. I don't think creating a test class is bad though, so if you're more comfortable with that it's fine too. I still think global test hooks would be better, but if it looks like it'll take more than a day or two I can buy the workaround described. |
Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
|
Also since I'm a bit behind on reviews and annotations are nice :-) |
Signed-off-by: Joshua Marantz <jmarantz@google.com>
…t run without ASAN need it too. Signed-off-by: Joshua Marantz <jmarantz@google.com>
|
Apologies for the size of the PR. You can see the pattern from the first visible file in it. This was all done semi-automatically, requiring manual-fixes where the test-fixture name matched an existing class name. My fix was to append 'Test' to the test fixture name, and I probably had to do this a few dozen times. Also in this PR is a check_format addition to flag "TEST(" going forward. This check_format.py change is the last file in the PR so you can find the diff by going to the Files view and scrolling to the bottom. |
Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
|
/retest |
|
🔨 rebuilding |
|
/retest |
|
🔨 rebuilding |
Signed-off-by: Joshua Marantz <jmarantz@google.com>
|
@alyssawilk any further comments or discussion? This PR has the property that it probably won't be prone to automatically detected merge conflicts, but the longer it sits, the more new unchecked 'TEST(' macros will be added to the codebase. So if you let me know when you start reviewing I will do another quick merge and fix newly added 'TEST(' instances. |
Signed-off-by: Joshua Marantz <jmarantz@google.com>
|
Sorry, I started reviewing, paused to do some digging, and got distracted. So digging |
Signed-off-by: Joshua Marantz <jmarantz@google.com>
…t listener. Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
|
@alyssawilk yes done. Thank you very much for finding this...I had looked in some gtest header files for something like this and managed to miss it. |
alyssawilk
left a comment
There was a problem hiding this comment.
Awesome - glad this worked out.
Both comments optional so I'll give you my LGTM now but I'm happy to do another pass if you fix either or both.
| public: | ||
| ~TestBaseWithParam() { TestBase::checkSingletonQuiescensce(); } | ||
| }; | ||
| // TODO(jmarantz): Before Alyssa found this TestListener hook for me, we had |
There was a problem hiding this comment.
Optional: think it's worth removing the check_format checks in this PR, just so folks can create new testing::Test classes while we get around to clean up?
| public: | ||
| static void checkSingletonQuiescensce(); | ||
| ~TestBase() override; | ||
| class TestListener : public ::testing::EmptyTestEventListener { |
There was a problem hiding this comment.
bonus points if you can think of a more descriptive name - I currently can't :-P
|
Thanks -- I think TestListener is the best I can do at the moment and I'll follow up this morning with the rollback of the existing check_format and other tests, so I'll go ahead and merge and get rid of that stuff :) |
…er each method. (envoyproxy#5833) * Back out the TEST( -> TEST_F( changes in favor of establishing a gtest listener. Signed-off-by: Joshua Marantz <jmarantz@google.com> Signed-off-by: Fred Douglas <fredlas@google.com>
Description: Follow-up to #5811 -- use ::testing::TestEventListeners to add the singleton-quiescence hook. This is significantly cleaner than what I previously checked in which is to add a new TestBase class to every test-class, and covers TEST(fixture, name) tests too.
After this the TestBase class can be removed as it's now just an alias for ::testing:::Test.
Risk Level: low
Testing: //test/...
Docs Changes: n/a
Release Notes: n/a