-
Notifications
You must be signed in to change notification settings - Fork 58
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
Enable windows and macos builds in CI #660
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bffcb61
github: run CI on windows
cbgbt 55a40cc
tough: always use unix-style paths in clean_name
cbgbt 967e02d
Refrain from using docker for integration testing
cbgbt c4bfd0d
github: run CI on macos
cbgbt a18164b
integ: use retries when applying toxics
cbgbt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[package] | ||
name = "failure-server" | ||
version = "0.1.0" | ||
edition = "2021" | ||
license = "MIT OR Apache-2.0" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
axum = "0.6" | ||
anyhow = "1.0" | ||
noxious-client = "1.0" | ||
rand = "0.8" | ||
serde_json = "1.0" | ||
tempfile = "3.8" | ||
tokio = "1.0" | ||
tower = { version = "0.4", features = ["util"] } | ||
tower-fault = "0.0.5" | ||
tower-http = { version = "0.4", features = ["fs"] } |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
//! This module sets up 2 HTTP servers. | ||
//! * ToxicStaticHttpServer: serves TUF repo files on port 10101, with occasional random 503s. | ||
//! * ToxicTcpProxy: proxies to the TUF repo on port 10102, with occasional toxic behavior. | ||
use anyhow::Result; | ||
use noxious_client::{StreamDirection, Toxic, ToxicKind}; | ||
use std::path::Path; | ||
use std::thread::sleep; | ||
use std::time::Duration; | ||
use toxic::{ToxicStaticHttpServer, ToxicTcpProxy}; | ||
|
||
mod toxic; | ||
|
||
const STATIC_HTTP_SERVER_LISTEN: &str = "127.0.0.1:10101"; | ||
const TCP_PROXY_LISTEN: &str = "127.0.0.1:10102"; | ||
const TCP_PROXY_CONFIG_API_LISTEN: &str = "127.0.0.1:8472"; | ||
|
||
pub struct IntegServers { | ||
toxic_tcp_proxy: ToxicTcpProxy, | ||
toxic_static_http_server: ToxicStaticHttpServer, | ||
} | ||
|
||
impl IntegServers { | ||
pub fn new<P: AsRef<Path>>(tuf_reference_repo: P) -> Result<Self> { | ||
let tuf_reference_repo = tuf_reference_repo.as_ref().to_owned(); | ||
|
||
let toxic_tcp_proxy = ToxicTcpProxy::new( | ||
"toxictuf".to_string(), | ||
TCP_PROXY_LISTEN, | ||
STATIC_HTTP_SERVER_LISTEN, | ||
TCP_PROXY_CONFIG_API_LISTEN, | ||
)? | ||
.with_toxic(Toxic { | ||
name: "slowclose".to_string(), | ||
kind: ToxicKind::SlowClose { delay: 500 }, | ||
toxicity: 0.75, | ||
direction: StreamDirection::Downstream, | ||
}) | ||
.with_toxic(Toxic { | ||
name: "timeout".to_string(), | ||
kind: ToxicKind::Timeout { timeout: 100 }, | ||
toxicity: 0.5, | ||
direction: StreamDirection::Downstream, | ||
}); | ||
|
||
let toxic_static_http_server = | ||
ToxicStaticHttpServer::new(STATIC_HTTP_SERVER_LISTEN, tuf_reference_repo)?; | ||
|
||
Ok(Self { | ||
toxic_tcp_proxy, | ||
toxic_static_http_server, | ||
}) | ||
} | ||
|
||
pub async fn run(&mut self) -> Result<()> { | ||
// Make sure we're starting from scratch | ||
self.teardown()?; | ||
|
||
self.toxic_static_http_server.start()?; | ||
self.toxic_tcp_proxy.start().await?; | ||
sleep(Duration::from_secs(1)); // give the servers a chance to start | ||
|
||
println!("**********************************************************************"); | ||
println!("the toxic tuf repo is available at {TCP_PROXY_LISTEN}"); | ||
|
||
Ok(()) | ||
} | ||
|
||
pub fn teardown(&mut self) -> Result<()> { | ||
self.toxic_tcp_proxy.stop()?; | ||
self.toxic_static_http_server.stop()?; | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
impl Drop for IntegServers { | ||
fn drop(&mut self) { | ||
self.teardown().ok(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
//! A simple filesystem HTTP server that introduces chaos at the HTTP layer. | ||
//! | ||
//! Chaos includes: | ||
//! * Occasional additional request latency | ||
//! * Occasional 503 responses | ||
use super::ToSocketAddrsExt; | ||
use anyhow::{Context, Result}; | ||
use axum::{ | ||
http::{Request, StatusCode}, | ||
middleware::{self, Next}, | ||
response::Response, | ||
Router, | ||
}; | ||
use std::fmt::Debug; | ||
use std::net::{SocketAddr, ToSocketAddrs}; | ||
use std::path::{Path, PathBuf}; | ||
use tower_fault::latency::LatencyLayer; | ||
use tower_http::services::ServeDir; | ||
|
||
const ERR_503_PROBABILITY: f64 = 0.5; | ||
const LATENCY_PROBABILITY: f64 = 0.1; | ||
|
||
/// An HTTP server which serves static files from a directory. | ||
/// | ||
/// The server implementation is "toxic" in that it introduces artificial faults at the HTTP layer. | ||
#[derive(Debug)] | ||
pub(crate) struct ToxicStaticHttpServer { | ||
/// The proxy's listen address. Written to `ProxyConfig`. | ||
listen: SocketAddr, | ||
|
||
/// The path to serve static content from. | ||
serve_dir: PathBuf, | ||
|
||
/// Running server, if any | ||
running_server: Option<tokio::task::JoinHandle<Result<()>>>, | ||
} | ||
|
||
impl ToxicStaticHttpServer { | ||
pub(crate) fn new<T, P>(listen: T, serve_dir: P) -> Result<Self> | ||
where | ||
T: ToSocketAddrs + Debug, | ||
P: AsRef<Path>, | ||
{ | ||
let listen = listen.parse_only_one_address()?; | ||
let serve_dir = serve_dir.as_ref().to_owned(); | ||
let running_server = None; | ||
|
||
Ok(Self { | ||
listen, | ||
serve_dir, | ||
running_server, | ||
}) | ||
} | ||
|
||
/// Starts the HTTP server. | ||
pub(crate) fn start(&mut self) -> Result<()> { | ||
// Stop any existing server | ||
self.stop().ok(); | ||
|
||
// Chance to inject 50 to 200 milliseconds of latency | ||
let latency_layer = LatencyLayer::new(LATENCY_PROBABILITY, 50..200); | ||
// Chance to return an HTTP 503 error | ||
let error_layer = middleware::from_fn(maybe_return_error); | ||
|
||
let app = Router::new() | ||
.nest_service("/", ServeDir::new(&self.serve_dir)) | ||
.layer(error_layer) | ||
.layer(latency_layer); | ||
let server = axum::Server::bind(&self.listen).serve(app.into_make_service()); | ||
|
||
self.running_server = Some(tokio::spawn(async { | ||
server.await.context("Failed to run ToxicStaticHttpServer") | ||
})); | ||
|
||
Ok(()) | ||
} | ||
|
||
/// Attempts to kill the running server, if there is one. | ||
/// | ||
/// Succeeds if the server is killed successfully or if it isn't/was never running. | ||
pub(crate) fn stop(&mut self) -> Result<()> { | ||
if let Some(server) = self.running_server.take() { | ||
server.abort(); | ||
} | ||
Ok(()) | ||
} | ||
} | ||
|
||
/// Middleware for chaotically returning a 503 error. | ||
async fn maybe_return_error<B>(req: Request<B>, next: Next<B>) -> Result<Response, StatusCode> { | ||
if rand::random::<f64>() < ERR_503_PROBABILITY { | ||
Err(StatusCode::SERVICE_UNAVAILABLE) | ||
} else { | ||
Ok(next.run(req).await) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use anyhow::{Context, Result}; | ||
use std::fmt::Debug; | ||
use std::net::{SocketAddr, ToSocketAddrs}; | ||
|
||
pub(crate) use http_server::ToxicStaticHttpServer; | ||
pub(crate) use tcp_proxy::ToxicTcpProxy; | ||
|
||
mod http_server; | ||
mod tcp_proxy; | ||
|
||
/// Attempts to read exactly one `SocketAddr` from a `ToSocketAddrs`. | ||
/// | ||
/// Returns an error if more than one SocketAddr is present. | ||
trait ToSocketAddrsExt { | ||
fn parse_only_one_address(self) -> Result<SocketAddr>; | ||
} | ||
|
||
impl<T: ToSocketAddrs + Debug> ToSocketAddrsExt for T { | ||
fn parse_only_one_address(self) -> Result<SocketAddr> { | ||
let mut addresses = self | ||
.to_socket_addrs() | ||
.context(format!("Failed to parse {self:?} as socket address"))?; | ||
|
||
let address = addresses | ||
.next() | ||
.context(format!("Did not parse any addresses from {self:?}"))?; | ||
|
||
anyhow::ensure!( | ||
addresses.next().is_none(), | ||
format!("Listen address ({:?}) must parse to one address.", address) | ||
); | ||
|
||
Ok(address) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a tracking issue to make sure we don't forget about this fork.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I opened one here: #671