Skip to content
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

test(subscriber): add initial integration tests #452

Merged
merged 21 commits into from
Sep 6, 2023
Merged

Commits on Aug 1, 2023

  1. test(subscriber): add initial integration tests

    The `console-subscriber` crate has no integration tests. There are some
    unit tests, but without very high coverage of features.
    
    Recently, we've found or fixed a few errors which probably could have
    been caught by a medium level of integration testing.
    
    However, testing `console-subscriber` isn't straight forward. It is
    effectively a tracing subscriber (or layer) on one end, and a gRPC
    server on the other end.
    
    This change adds enough of a testing framework to write some initial
    integration tests. It is the first step towards closing #450.
    
    Each test comprises 2 parts:
    - One or more "expcted tasks"
    - A future which will be driven to completion on a dedicated Tokio runtime.
    
    Behind the scenes, a console subscriber layer is created and it's server
    part is connected to a duplex stream. The client of the duplex stream
    then records incoming updates and reconstructs "actual tasks". The layer
    itself is set as the default subscriber for the duration of `block_on`
    which is used to drive the provided future to completioin.
    
    The expected tasks have a set of "matches", which is how we find the
    actual task that we want to validate against. Currently, the only value
    we match on is the task's name.
    
    The expected tasks also have a set of expectations. These are other
    fields on the actual task which are validated once a matching task is
    found. Currently, the two fields which can have expectations set on them
    are the `wakes` and `self_wakes` fields.
    
    So, to construct an expected task, which will match a task with the name
    `"my-task"` and then validate that the matched task gets woken once, the
    code would be:
    
    ```rust
    ExpectedTask::default()
        .match_name("my-task")
        .expect_wakes(1);
    ```
    
    A future which passes this test could be:
    
    ```rust
    async {
        task::Builder::new()
            .name("my-task")
            .spawn(async {
                tokio::time::sleep(std::time::Duration::ZERO).await
            })
    }
    ```
    
    The full test would then look like:
    
    ```rust
    fn wakes_once() {
        let expected_task = ExpectedTask::default()
            .match_name("my-task")
            .expect_wakes(1);
    
        let future = async {
            task::Builder::new()
                .name("my-task")
                .spawn(async {
                    tokio::time::sleep(std::time::Duration::ZERO).await
                })
        };
    
        assert_task(expected_task, future);
    }
    ```
    
    The PR depends on 2 others:
     - #447 which fixes an error in the logic that determines whether a task
       is retained in the aggregator or not.
     - #451 which exposes the server parts and is necessary to allow us to
       connect the instrument server and client via a duplex channel.
    
    This change contains some initial tests for wakes and self wakes which
    would have caught the error fixed in #430. Additionally there are tests
    for the functionality of the testing framework itself.
    hds committed Aug 1, 2023
    Configuration menu
    Copy the full SHA
    42fb829 View commit details
    Browse the repository at this point in the history
  2. fixed warning (unneeded mut)

    hds committed Aug 1, 2023
    Configuration menu
    Copy the full SHA
    813d020 View commit details
    Browse the repository at this point in the history

Commits on Aug 17, 2023

  1. wait for additional update from subscriber

    After the test ends, we were waiting for a single further update before
    evaluating the actual tasks (vs. the expected tasks). Now we wait for 2
    updates.
    hds committed Aug 17, 2023
    Configuration menu
    Copy the full SHA
    82abe73 View commit details
    Browse the repository at this point in the history
  2. single threaded tests to debug

    hds committed Aug 17, 2023
    Configuration menu
    Copy the full SHA
    5d3245d View commit details
    Browse the repository at this point in the history

Commits on Aug 22, 2023

  1. some more debugging stuff

    hds committed Aug 22, 2023
    Configuration menu
    Copy the full SHA
    c1a2565 View commit details
    Browse the repository at this point in the history

Commits on Aug 23, 2023

  1. Trace to stdout for CI debugging

    sigh.
    hds committed Aug 23, 2023
    Configuration menu
    Copy the full SHA
    b56c123 View commit details
    Browse the repository at this point in the history
  2. enable all OSes

    hds committed Aug 23, 2023
    Configuration menu
    Copy the full SHA
    380345a View commit details
    Browse the repository at this point in the history
  3. bit more tracing

    hds committed Aug 23, 2023
    Configuration menu
    Copy the full SHA
    695644e View commit details
    Browse the repository at this point in the history

Commits on Aug 24, 2023

  1. Configuration menu
    Copy the full SHA
    bd9c315 View commit details
    Browse the repository at this point in the history
  2. confirming a suspicion

    hds committed Aug 24, 2023
    Configuration menu
    Copy the full SHA
    a61bdd6 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    76bb061 View commit details
    Browse the repository at this point in the history
  4. maybe avoid a data race

    hds committed Aug 24, 2023
    Configuration menu
    Copy the full SHA
    7b32fdc View commit details
    Browse the repository at this point in the history

Commits on Aug 25, 2023

  1. undo all testing changes

    This commit has the same changeset as the original commit.
    hds committed Aug 25, 2023
    Configuration menu
    Copy the full SHA
    3057541 View commit details
    Browse the repository at this point in the history
  2. Apply suggestions from code review

    Co-authored-by: Eliza Weisman <eliza@buoyant.io>
    hds and hawkw committed Aug 25, 2023
    Configuration menu
    Copy the full SHA
    d774483 View commit details
    Browse the repository at this point in the history
  3. add signal task at end of test

    Rather than relying on all the tasks becoming visible N update
    iterations after the test ends, we spawn a signal task which we then
    look for. Once the test has completed (which will almost certainly
    happen first) and the signal task has been read, we finish parsing the
    current update and then finish immediately.
    hds committed Aug 25, 2023
    Configuration menu
    Copy the full SHA
    4dac412 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    e24d484 View commit details
    Browse the repository at this point in the history
  5. improved rightward drift in update loop

    The one in the instrumentation client.
    hds committed Aug 25, 2023
    Configuration menu
    Copy the full SHA
    fee7b0a View commit details
    Browse the repository at this point in the history

Commits on Sep 6, 2023

  1. Apply suggestions from code review

    Co-authored-by: Eliza Weisman <eliza@buoyant.io>
    hds and hawkw committed Sep 6, 2023
    Configuration menu
    Copy the full SHA
    514aba1 View commit details
    Browse the repository at this point in the history
  2. Apply suggestions from code review (part 2)

    Co-authored-by: Eliza Weisman <eliza@buoyant.io>
    hds and hawkw committed Sep 6, 2023
    Configuration menu
    Copy the full SHA
    4af221a View commit details
    Browse the repository at this point in the history
  3. Update console-subscriber/tests/support/subscriber.rs

    Co-authored-by: Eliza Weisman <eliza@buoyant.io>
    hds and hawkw committed Sep 6, 2023
    Configuration menu
    Copy the full SHA
    7619741 View commit details
    Browse the repository at this point in the history
  4. Suggestions from code review

    Thanks!
    hds committed Sep 6, 2023
    Configuration menu
    Copy the full SHA
    6fce209 View commit details
    Browse the repository at this point in the history