Skip to content

Commit

Permalink
Simple e2e testing framework, passthrough and corner case tests
Browse files Browse the repository at this point in the history
Signed-off-by: Eloi DEMOLIS <eloi.demolis@clever-cloud.com>

make tests.rs to a test module, allow unused code in e2e
exclude e2e tests from tarpaulin
use serial-test to run tests sequentially
Repeated tests, to run the same function multiple times

zombie crash test for #806
tests for #808 and #810
Invalid HTTP content-length test
test for #810, HTTP variant of TCP crash on missing listeners
Upgrade test (not working)
test_issue_806 can yield an Undecided
  • Loading branch information
Wonshtrum authored and Keksoj committed Jan 10, 2023
1 parent 4974d4f commit b5fb1d9
Show file tree
Hide file tree
Showing 21 changed files with 1,797 additions and 13 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ jobs:
runs-on: ubuntu-latest

strategy:
max-parallel: 1 # because concurrent testing bring certain time-based tests to fail
matrix:
rust:
- stable
Expand All @@ -30,7 +29,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: build
args: --verbose ${{ matrix.features }}
args: ${{ matrix.features }}

- name: Test
uses: actions-rs/cargo@v1
Expand Down Expand Up @@ -78,15 +77,15 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: install
args: cargo-tarpaulin --version 0.18.0-alpha3 # @TODO restore to normal (https://github.com/xd009642/tarpaulin/issues/756#issuecomment-838769320)
args: cargo-tarpaulin

- name: Run cargo tarpaulin
uses: actions-rs/cargo@v1
env:
TOKEN: ${{ secrets.COVERALLS_TOKEN }}
with:
command: tarpaulin
args: --coveralls $TOKEN --avoid-cfg-tarpaulin # @TODO restore to normal (https://github.com/xd009642/tarpaulin/issues/756#issuecomment-838769320)
args: --coveralls $TOKEN

dockerhub:
name: Docker build and push to Docker Hub
Expand Down
108 changes: 106 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["lib/", "command/", "bin/"]
members = ["lib/", "command/", "bin/", "e2e/"]

[profile.release]
lto = true
Expand Down
1 change: 0 additions & 1 deletion bin/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use std::{
process::Command,
};

use std::env;
use anyhow::{bail, Context};
use libc::{self, pid_t};
#[cfg(target_os = "macos")]
Expand Down
14 changes: 14 additions & 0 deletions e2e/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "sozu-e2e"
version = "0.1.0"
edition = "2021"

[dependencies]
sozu-lib = { path = "../lib" }
sozu-command-lib = { path = "../command" }
slab = "^0.4.7"
mio = "^0.8.4"
time = "^0.3.14"
futures = "^0.3.24"
libc = "^0.2.138"
serial_test = "^0.10.0"
38 changes: 38 additions & 0 deletions e2e/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# End to end tests

We want to check Sōzu's behavior in all corner cases for the CI.

## Principles

This crate contains thin wrappers around the Sōzu lib, that create:

- a Sōzu worker with a very simple config, able to run a detached thread
- mocked clients that send simple HTTP requests
- mocked backends, sync and async, that reply dummy 200 OK responses (for instance)

This crate provides the `Aggregator` trait, that allows to create simple aggregators.
The aggregators keep track, for instance, of how many requests were received,
and how many were sent, by a backend (just an example).

These elements are instantiated in test functions. They aim at both normal behaviour
(traffic passthrough) but also tackle corner cases, such as:

- smooth soft stop
- immediate hard stop
- behaviour of the zombie checker
- reconnection to a backend

# How to run

The tests are flagged with the usual macros, so they will run with all other tests when you do:

cargo test

All tests are run one at a time with the `#[serial]` macro. You can run just one using

cargo test test_issue_810_timeout

If you want to run all e2e tests at once, do:

cd e2e
cargo test
26 changes: 26 additions & 0 deletions e2e/src/http_utils/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
pub fn http_ok_response<S: Into<String>>(content: S) -> String {
let content = content.into();
let status_line = "HTTP/1.1 200 OK";
let length = content.len();
format!(
"{}\r\nContent-Length: {}\r\n\r\n{}",
status_line, length, content
)
}

/// Creates an HTTP/1 raw request
pub fn http_request<S1: Into<String>, S2: Into<String>, S3: Into<String>>(
method: S1,
uri: S2,
content: S3,
) -> String {
let content = content.into();
let length = content.len();
format!(
"{} {} HTTP/1.1\r\nHost: localhost\r\nConnection: keep-alive\r\nContent-Length: {}\r\n\r\n{}",
method.into(),
uri.into(),
length,
content,
)
}
11 changes: 11 additions & 0 deletions e2e/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

#![allow(dead_code)]

mod http_utils;
mod mock;
mod sozu;
#[cfg(test)]
#[cfg(not(tarpaulin))]
mod tests;

const BUFFER_SIZE: usize = 4096;
10 changes: 10 additions & 0 deletions e2e/src/mock/aggregator.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/// Used to hold and accumulate any data on an asynchronous task
pub trait Aggregator {}

/// Gathers only data on sent and received requests
#[derive(Debug, Clone)]
pub struct SimpleAggregator {
pub requests_received: usize,
pub responses_sent: usize,
}
impl Aggregator for SimpleAggregator {}

0 comments on commit b5fb1d9

Please sign in to comment.