Skip to content

test: Add timeouts to methods that could wait forever in test/integration/fake_upstream.h.#3936

Merged
mattklein123 merged 12 commits intoenvoyproxy:masterfrom
mkbehr:fake-upstream-timeout
Jul 31, 2018
Merged

test: Add timeouts to methods that could wait forever in test/integration/fake_upstream.h.#3936
mattklein123 merged 12 commits intoenvoyproxy:masterfrom
mkbehr:fake-upstream-timeout

Conversation

@mkbehr
Copy link
Contributor

@mkbehr mkbehr commented Jul 23, 2018

Description: Part of work for #3809. This changes methods that wait for something to happen, in FakeUpstream and related classes, so that they take an optional timeout arg. Timeouts default to 10 seconds. The methods now all return AssertionResults, marked with ABSL_MUST_USE_RESULT to require tests to check for failure. Methods that used to return something else now use an output argument.
Risk Level: Low (test-only, will break builds)
Testing: bazel test //test/...
Docs Changes: n/a
Release Notes: n/a

mkbehr added 2 commits July 23, 2018 17:53
Signed-off-by: Michael Behr <mkbehr@google.com>
Signed-off-by: Michael Behr <mkbehr@google.com>
@mkbehr mkbehr requested review from lizan and zuercher as code owners July 23, 2018 23:07
public:
void expectExtraHeaders(FakeStream& fake_stream) override {
fake_stream.waitForHeadersComplete();
ASSERT(fake_stream.waitForHeadersComplete());
Copy link
Member

Choose a reason for hiding this comment

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

This will be compiled out in release builds, which is not your intention, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, yeah. Changed these to use RELEASE_ASSERT. Do you think it's worth adding a macro for this use? (RELEASE_ASSERT on an AssertionResult, using the AssertionResult's message as the RELEASE_ASSERT's message)

Copy link
Member

Choose a reason for hiding this comment

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

Why not use ASSERT_TRUE?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ASSERT_TRUE will return from the helper function but keep the test running, so the test will probably crash anyway but in a more confusing way. (And for helpers that return things, like SquashFilterIntegrationTest::sendSquash, it won't compile.)

mkbehr added 2 commits July 24, 2018 13:26
…rors.

Signed-off-by: Michael Behr <mkbehr@google.com>
…eout

Signed-off-by: Michael Behr <mkbehr@google.com>
@mkbehr
Copy link
Contributor Author

mkbehr commented Jul 24, 2018

Having some trouble figuring out why tests are passing on my machine but failing on circleci.

@zuercher
Copy link
Member

zuercher commented Jul 24, 2018

The error for all those builds is:

external/envoy/test/integration/autonomous_upstream.cc:76:3: error: ignoring return value of function declared with 'warn_unused_result' attribute [-Werror,-Wunused-result]
  http_connection->initialize();
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

On line 345 of fake_upstream.h you add ABSL_MUST_USE_RESULT to the FakeConnectionBase::initialize() method (which returns a testing::AssertionResult). Because of the annotation, you must now do something with that AssertionResult at every call site.

If it doesn't fail locally, perhaps your compiler doesn't support the annotation?

mkbehr added 2 commits July 25, 2018 12:48
RELEASE_ASSERT in AutonomousUpstream::createNetworkFilterChain;
ABSL_MUST_USE_RESULT on FakeRawConnection::initialize

Signed-off-by: Michael Behr <mkbehr@google.com>
…eout

Signed-off-by: Michael Behr <mkbehr@google.com>
@mkbehr
Copy link
Contributor Author

mkbehr commented Jul 25, 2018

It's strange that the release build passes even though it ignores that value from autonomous_upstream.cc. It also builds fine on my machine, even though my compiler will complain about dropping results from ABSL_MUST_USE_RESULT in other places. But since the CI caught it I won't beat my head against this too long.

@zuercher
Copy link
Member

zuercher commented Jul 25, 2018

There's at least one more instance of that problem, unfortunately. The ASAN, TSAN, Mac and (unexpectedly to me) IPv6 builds all use clang. Release and coverage use gcc. So that's why it only happens in those builds.

@mkbehr
Copy link
Contributor Author

mkbehr commented Jul 25, 2018

I'll get the ci builds running on my machine so I can test with them directly.

mkbehr added 3 commits July 26, 2018 14:57
Signed-off-by: Michael Behr <mkbehr@google.com>
…eout

Signed-off-by: Michael Behr <mkbehr@google.com>
…e-upstream-timeout

Signed-off-by: Michael Behr <mkbehr@google.com>
Copy link
Member

@zuercher zuercher left a comment

Choose a reason for hiding this comment

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

Looks good! Some minor changes I'd like to see.

void waitForReset();
ABSL_MUST_USE_RESULT
testing::AssertionResult
waitForHeadersComplete(std::chrono::milliseconds timeout = std::chrono::milliseconds(10000));
Copy link
Member

Choose a reason for hiding this comment

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

Consider replacing std::chrono::milliseconds(10000) with a static constant.

Also I think it would be easier to read these 3-line declarations if they had a blank line between them.

Copy link
Contributor Author

@mkbehr mkbehr Jul 31, 2018

Choose a reason for hiding this comment

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

Done (and the rest of these too).

} while (false)

#define VERIFY_ASSERTION(statement) \
{ \
Copy link
Member

Choose a reason for hiding this comment

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

do { ... } while(false) as in the other macros. (This will force VERIFY_ASSERTION() to be followed by a semicolon in all cases, which I think we want.)

// wishes to wait for a new stream, set ignore_spurious_events = true.
ABSL_MUST_USE_RESULT
testing::AssertionResult
waitForNewStream(Event::Dispatcher& client_dispatcher, FakeStreamPtr* stream,
Copy link
Member

Choose a reason for hiding this comment

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

Our style guide prefers using a reference for connection here, since it can't be nullptr. Also add a comment indicating that the connection is returned via the reference. (Likewise for waitForRawConnection and waitForHttpConnection.)

mkbehr added 3 commits July 30, 2018 17:13
…e-upstream-timeout

Signed-off-by: Michael Behr <mkbehr@google.com>
- Static constant for default timeouts
- do while false for VERIFY_ASSERTION
- Reference for output arguments in waitForNewStream et al.

Signed-off-by: Michael Behr <mkbehr@google.com>
…e-upstream-timeout

Signed-off-by: Michael Behr <mkbehr@google.com>
Copy link
Member

@zuercher zuercher left a comment

Choose a reason for hiding this comment

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

Looks good. Thanks for taking this on.

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Super cool, thank you!

@mattklein123 mattklein123 merged commit 6a8b843 into envoyproxy:master Jul 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants