Skip to content

introduce tests for isolated services#655

Merged
hawkw merged 19 commits intomainfrom
eliza/tcp-lb-tests
Sep 16, 2020
Merged

introduce tests for isolated services#655
hawkw merged 19 commits intomainfrom
eliza/tcp-lb-tests

Conversation

@hawkw
Copy link
Contributor

@hawkw hawkw commented Sep 11, 2020

This branch introduces a new style of tests to the proxy codebase, and
an initial implementation of new test support code for writing tests in
this style. Rather than running an entire proxy alongside a simulated
control plane, and binding actual network socket, as the present
integration tests do, the new tests run individual proxy components in
isolation, using simpler mock implementations of components like name
resolution and IO.

This approach has a few advantages. It should reduce flakiness
significantly, since we don't perform any IO and don't need to
synchronize events between multiple threads running test support
servers/controllers (the new mocks all just synchronously provide values
immediately). We can run everything in a single thread using Tokio's
basic scheduler. Additionally, since we are testing individual
components in isolation, these tests can live within the crate for the
part of the proxy being tested. This means we have access to more
internal state to make assertions on, rather than having to make
assertions on side effects like metrics.

I've added a new linkerd2-app-test crate that adds some initial mocks
for this kind of testing, including a simple mock resolver and a mock
connector using tokio-test's mock IO. I've also added a simple "hello
world" test for the outbound TCP stack written in this style. The
intention is to use the new test support code for testing the recent
changes adding TCP mTLS and load-balancing.

In order to make this code more testable, it was necessary to move a few
things around. In particular, the outbound TCP balancer stack is now
constructed in a separate method, rather than in Config::build_server,
so that it can be tested without requiring all the dependencies of the
full HTTP server stack. A few other similar changes were also necessary.

Signed-off-by: Eliza Weisman [email protected]

@hawkw hawkw requested review from a team and olix0r September 11, 2020 18:31
@hawkw hawkw changed the title Eliza/tcp lb tests introduce tests for isolated services Sep 11, 2020
Signed-off-by: Eliza Weisman <[email protected]>
@hawkw hawkw requested a review from olix0r September 15, 2020 18:25
Copy link
Member

@olix0r olix0r left a comment

Choose a reason for hiding this comment

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

Tests look great. Some superficial feedback


pub use futures::{future, FutureExt, TryFuture, TryFutureExt};

pub use linkerd2_app_core::{self as app_core, Addr, Error};
Copy link
Member

Choose a reason for hiding this comment

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

just call this core? or are there other cores we should be aware of?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IIRC it clashed with libcore. will double check if this is the case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup:

error[E0659]: `core` is ambiguous (name vs any other name during import resolution)
  --> linkerd/app/outbound/src/tests.rs:12:9
   |
12 |     use core::{
   |         ^^^^ ambiguous name
   |
   = note: `core` could refer to a built-in crate
   = help: use `::core` to refer to this crate unambiguously
note: `core` could also refer to the crate imported here
  --> linkerd/app/outbound/src/tests.rs:3:25
   |
3  | use linkerd2_app_core::{self as core, metrics::Metrics, Addr};
   |                         ^^^^^^^^^^^^
   = help: use `self::core` to refer to this crate unambiguously

error: aborting due to previous error

hawkw and others added 3 commits September 16, 2020 10:17
Signed-off-by: Eliza Weisman <[email protected]>
Signed-off-by: Eliza Weisman <[email protected]>
@hawkw hawkw requested a review from olix0r September 16, 2020 17:24
Copy link
Contributor

@kleimkuhler kleimkuhler 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!

atomic::{AtomicBool, Ordering},
Arc, Mutex,
};
// use std::future::Future;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can remove this

use std::net::SocketAddr;
use std::task::{Context, Poll};
use tokio::sync::mpsc;
// use tower::Service;
Copy link
Contributor

Choose a reason for hiding this comment

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

And this

Signed-off-by: Eliza Weisman <[email protected]>
@hawkw hawkw merged commit 445e7dc into main Sep 16, 2020
@hawkw hawkw deleted the eliza/tcp-lb-tests branch September 16, 2020 20:08
olix0r added a commit to linkerd/linkerd2 that referenced this pull request Sep 18, 2020
This release fixes a recent regression in multicluster gateway
configurations that would forbid inbound gateway traffic. It also fixes
URI normalization for orig-proto-upgrade requests that do not include a
`Host` header.

---

* http: Simplify stacks and target types (linkerd/linkerd2-proxy#656)
* Make SkipDetect more generic as stack::MakeSwitch (linkerd/linkerd2-proxy#657)
* introduce tests for isolated services (linkerd/linkerd2-proxy#655)
* http: Put normalize_uri back on the stack (linkerd/linkerd2-proxy#659)
* inbound: Apply loop detection on the connect stack (linkerd/linkerd2-proxy#660)
* tracing: Elide redundant info in tracing contexts (linkerd/linkerd2-proxy#661)
* outbound: Reorganize outbound stacks (linkerd/linkerd2-proxy#662)
* app: Decouple stacks from listeners (linkerd/linkerd2-proxy#663)
* inbound: Split HTTP detection stack from TLS (linkerd/linkerd2-proxy#664)
* integration: Bundle tests in src (linkerd/linkerd2-proxy#665)
olix0r added a commit to linkerd/linkerd2 that referenced this pull request Sep 19, 2020
This release fixes a recent regression in multicluster gateway
configurations that would forbid inbound gateway traffic. It also fixes
URI normalization for orig-proto-upgrade requests that do not include a
`Host` header.

---

* http: Simplify stacks and target types (linkerd/linkerd2-proxy#656)
* Make SkipDetect more generic as stack::MakeSwitch (linkerd/linkerd2-proxy#657)
* introduce tests for isolated services (linkerd/linkerd2-proxy#655)
* http: Put normalize_uri back on the stack (linkerd/linkerd2-proxy#659)
* inbound: Apply loop detection on the connect stack (linkerd/linkerd2-proxy#660)
* tracing: Elide redundant info in tracing contexts (linkerd/linkerd2-proxy#661)
* outbound: Reorganize outbound stacks (linkerd/linkerd2-proxy#662)
* app: Decouple stacks from listeners (linkerd/linkerd2-proxy#663)
* inbound: Split HTTP detection stack from TLS (linkerd/linkerd2-proxy#664)
* integration: Bundle tests in src (linkerd/linkerd2-proxy#665)
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.

3 participants