Skip to content

Add generic c++ integration test for uniform extension behavior. #533

Merged
mum4k merged 19 commits intoenvoyproxy:masterfrom
oschaaf:extension-refactor-prelude-3
Sep 23, 2020
Merged

Add generic c++ integration test for uniform extension behavior. #533
mum4k merged 19 commits intoenvoyproxy:masterfrom
oschaaf:extension-refactor-prelude-3

Conversation

@oschaaf
Copy link
Copy Markdown
Member

@oschaaf oschaaf commented Sep 14, 2020

Test basic behavioural properties of all test-server extensions. Any new extensions
may piggy-back on this by enlisting themselves. In a follow up we'll purge code
from the pre-existing tests that can now be deprecated.

Split out from #512

Signed-off-by: Otto van der Schaaf oschaaf@we-amp.com


Prerequisite:

- Extracts shared needs between tested extensions.
- Sanitized api, better naming.
- Doc comments.
- Support for testing POST request methods and entity bodies
  to check the alternative flow that will trigger in extensions
  when using that.

Prelude to envoyproxy#512, which includes it and provides a means to
see the end goal.

Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
…r-prelude

Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
…r-prelude

Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
…r-prelude

Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Split out from envoyproxy#512

Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>

------

Prerequisite:

- [ ] Land envoyproxy#517
@oschaaf oschaaf added the waiting-for-review A PR waiting for a review. label Sep 14, 2020
@oschaaf oschaaf marked this pull request as draft September 14, 2020 08:54
@oschaaf oschaaf removed the waiting-for-review A PR waiting for a review. label Sep 14, 2020
…r-prelude

Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
…lude-3

Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
@oschaaf oschaaf force-pushed the extension-refactor-prelude-3 branch from 2900d37 to 97322d8 Compare September 15, 2020 12:16
…r-prelude

Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
…lude-3

Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
…r-prelude-3

Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
@oschaaf oschaaf added the waiting-for-review A PR waiting for a review. label Sep 17, 2020
@oschaaf oschaaf marked this pull request as ready for review September 17, 2020 06:51
oschaaf added a commit to oschaaf/nighthawk that referenced this pull request Sep 17, 2020
Switch tests for these extensions to use the recent shared test
facilities. Eliminate tests we generalized in envoyproxy#533.

Split out from envoyproxy#512

Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
@mum4k mum4k requested a review from wjuan-AFK September 17, 2020 19:10
@mum4k
Copy link
Copy Markdown
Collaborator

mum4k commented Sep 17, 2020

@wjuan-AFK please review and assign back to me once done.

…r-prelude-3

Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
@oschaaf
Copy link
Copy Markdown
Member Author

oschaaf commented Sep 18, 2020

Can't reproduce the clang-tidy failure locally, and in CI it doesn't state a specific complaint.
/retest

@repokitteh-read-only
Copy link
Copy Markdown

🔨 rebuilding ci/circleci: clang_tidy (failed build)

🐱

Caused by: a #533 (comment) was created by @oschaaf.

see: more, trace.

@oschaaf oschaaf mentioned this pull request Sep 18, 2020
@oschaaf
Copy link
Copy Markdown
Member Author

oschaaf commented Sep 18, 2020

Yup, clang-tidy flaked in CI for this PR, which is unusual :-( Filed #546 to put in on the radar.

// - Bad request-level json configuration.
// We will be low on functional expectations for the extensions, but this will catch hangs and
// ensure that bad configuration handling is in-place.
TEST_P(HttpFilterBaseIntegrationTest, BasicExtensionFlows) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we split these into separate tests? I'm not sure what the preference in the code base is, but it seems like each chunk is testing a different behaviour and might deserve a separate test?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I can see your point, and in general I agree that the clearer test names that arise out of more finely grained separate tests are better.
But in this case, when splitting this, up we would have to duplicate the parameter unpacking for the TEST_P params across the newly split up tests and/or add facilities to help with that.
This was also sort of pre-existing (as we can eliminate three different instances of similar code in the test code for three extensions).

So personally I lean towards the compact version as is is now. With the context above, are you comfortable with leaving this as-is?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah, makes sense to me.

EXPECT_EQ("200", response->headers().Status()->value().getStringView());
EXPECT_TRUE(response->body().empty());

const std::string kBadConfigErrorSentinel =
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not use status instead of doing this substring check?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We do check the http response code, but then also look for this substring in the response body because we know it should look like that if the extension under test is using the shared configuration handling code. Does that sound good?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes. That also makes sense.

wjuan-AFK
wjuan-AFK previously approved these changes Sep 22, 2020

namespace Nighthawk {

using namespace testing;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do we need this, since most symbols from the namespace are qualified? E.g. ::testing::Combine.

If you do prefer to shorten them, can we list them explicitly instead of subscribing to the entire testing namespace which could cause a conflict and confuse someone in the future?

E.g. for symbols that repeat a lot we can:

using ::testing::Combine;
using ::testing::ValuesIn;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done; added an anonymous namespace as well based on that it can only benefit us.

// - Bad request-level json configuration.
// We will be low on functional expectations for the extensions, but this will catch hangs and
// ensure that bad configuration handling is in-place.
TEST_P(HttpFilterBaseIntegrationTest, BasicExtensionFlows) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Adding to what @wjuan-AFK commented on - it would really help if we can separate these into individual test cases - one per behavior. Such approach simplifies future code changes, because it ensures that the tests won't be affected when a new behavior is added or that less tests are affected when a behavior is changed. Additionally when a behavior breaks, we get a clear signal which behavior broke, rather than a generic failure saying "the BasicExtensionFlows no longer works".

I see your point about duplicating the parameter unpacking. I wonder if we could place that into a separate helper function. If we figure out we can't, I think we should prefer more instances of smaller independent tests for individual behavior to shorter code that uses parametrised tests. In other words, if we need to drop the parametrised test approach and write few more test cases, I think that is a worthwhile price to pay for shorter and easier to maintain test cases.

Can we burn another cycle on this and see if we can find a win-win solution?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I will take a look. Hopefully a convenient helper will suffice to support this, and then I can split these out into different tests. I'd like to avoid the need to drop parameterized testing here if we can: we would not only have to duplicate the test(s) for our three current extensions, but also require that for future extensions that would want to piggy back on this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done in 5ff6d56.
@wjuan-AFK sorry, this was actually straight forward, and looking at the results, I rather like it better compared to what it was.

@mum4k mum4k added waiting-for-changes A PR waiting for comments to be resolved and changes to be applied. and removed waiting-for-review A PR waiting for a review. labels Sep 22, 2020
…r-prelude-3

Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
@oschaaf oschaaf added waiting-for-review A PR waiting for a review. and removed waiting-for-changes A PR waiting for comments to be resolved and changes to be applied. labels Sep 22, 2020
Copy link
Copy Markdown
Collaborator

@mum4k mum4k left a comment

Choose a reason for hiding this comment

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

Looks great, thank you for splitting them up.

@mum4k mum4k merged commit 164d98b into envoyproxy:master Sep 23, 2020
mum4k pushed a commit that referenced this pull request Sep 24, 2020
Switch tests for these extensions to use the recent shared test
facilities. Eliminate tests we generalize in #533.

Split out from #512

Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-for-review A PR waiting for a review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants