Skip to content

Commit

Permalink
trim_smoke_test
Browse files Browse the repository at this point in the history
  • Loading branch information
epompeii committed Jul 6, 2024
1 parent a6d8d2e commit 8be4539
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 26 deletions.
27 changes: 12 additions & 15 deletions .github/workflows/bencher.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,14 @@ jobs:
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo
key: ${{ runner.os }}-cargo-all-features
- uses: rui314/setup-mold@v1
with:
mold-version: ${{ env.MOLD_VERSION }}
- name: Add clippy
run: rustup component add clippy
- name: Run clippy
run: cargo clippy --no-deps -- -Dwarnings
run: cargo clippy --no-deps --all-features -- -Dwarnings

check_generated:
name: Check Generated
Expand Down Expand Up @@ -199,7 +199,7 @@ jobs:
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo
key: ${{ runner.os }}-cargo-all-features
- uses: rui314/setup-mold@v1
with:
mold-version: ${{ env.MOLD_VERSION }}
Expand Down Expand Up @@ -248,28 +248,29 @@ jobs:
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo
key: ${{ runner.os }}-cargo-api
- uses: rui314/setup-mold@v1
with:
mold-version: ${{ env.MOLD_VERSION }}
- name: Install `bencher` CLI
run: cargo install --debug --path services/cli --locked --force
- name: Run Smoke Test
run: cargo test-api smoke localhost
run: cargo test-api smoke ci

release_api_smoke_test:
name: Release API Smoke Test
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
- os: macos-latest
- os: windows-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Install `bencher` CLI
run: cargo install --debug --path services/cli --locked --force
- uses: rui314/setup-mold@v1
if: matrix.os == 'ubuntu-latest'
with:
mold-version: ${{ env.MOLD_VERSION }}
- name: Run Smoke Test
run: cargo test-api smoke localhost

Expand All @@ -294,8 +295,6 @@ jobs:
if: matrix.os == 'ubuntu-latest'
with:
mold-version: ${{ env.MOLD_VERSION }}
- name: Install `bencher` CLI
run: cargo install --debug --path services/cli --locked --force
- name: Run Smoke Test
run: cargo test-api smoke docker

Expand Down Expand Up @@ -342,7 +341,7 @@ jobs:
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-release
key: ${{ runner.os }}-cargo-cli
- uses: rui314/setup-mold@v1
with:
mold-version: ${{ env.MOLD_VERSION }}
Expand Down Expand Up @@ -378,7 +377,7 @@ jobs:
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo
key: ${{ runner.os }}-cargo-audit
- uses: rui314/setup-mold@v1
with:
mold-version: ${{ env.MOLD_VERSION }}
Expand Down Expand Up @@ -790,8 +789,6 @@ jobs:
- uses: rui314/setup-mold@v1
with:
mold-version: ${{ env.MOLD_VERSION }}
- name: Install `bencher` CLI
run: cargo install --debug --path services/cli --locked --force
- name: Run Smoke Test
run: cargo test-api smoke dev

Expand Down
4 changes: 3 additions & 1 deletion tasks/test_api/src/parser/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ pub struct TaskSmokeTest {
#[clap(rename_all = "snake_case")]
#[allow(clippy::doc_markdown)]
pub enum TaskTestEnvironment {
/// https://localhost:61016
#[default]
/// https://localhost:61016
Ci,
/// https://localhost:61016
Localhost,
/// Docker https://localhost:61016
Docker,
Expand Down
13 changes: 13 additions & 0 deletions tasks/test_api/src/task/test/examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ impl From<TaskExample> for Example {

impl Examples {
pub fn exec(&self) -> anyhow::Result<()> {
// Install `bencher` CLI
let status = Command::new("cargo")
.args([
"install",
"--debug",
"--path",
"services/cli",
"--locked",
"--force",
])
.status()?;
assert!(status.success(), "{status}");

if let Some(example) = self.example {
run_example(&self.url, &self.token, example)
} else {
Expand Down
34 changes: 24 additions & 10 deletions tasks/test_api/src/task/test/smoke_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub struct SmokeTest {

#[derive(Debug, Clone, Copy)]
pub enum Environment {
Ci,
Localhost,
Docker,
Dev,
Expand All @@ -49,6 +50,7 @@ impl TryFrom<TaskSmokeTest> for SmokeTest {
impl From<TaskTestEnvironment> for Environment {
fn from(environment: TaskTestEnvironment) -> Self {
match environment {
TaskTestEnvironment::Ci => Self::Ci,
TaskTestEnvironment::Localhost => Self::Localhost,
TaskTestEnvironment::Docker => Self::Docker,
TaskTestEnvironment::Dev => Self::Dev,
Expand All @@ -61,7 +63,7 @@ impl From<TaskTestEnvironment> for Environment {
impl SmokeTest {
pub fn exec(&self) -> anyhow::Result<()> {
let child = match self.environment {
Environment::Localhost => Some(api_run()?),
Environment::Ci | Environment::Localhost => Some(api_run()?),
Environment::Docker => bencher_up().map(|()| None)?,
Environment::Dev | Environment::Test | Environment::Prod => None,
};
Expand All @@ -70,15 +72,16 @@ impl SmokeTest {
test_api_version(&api_url)?;

match self.environment {
Environment::Ci => {
test(&api_url, None, false)?;
kill_child(child)?;
},
Environment::Localhost => {
test(&api_url, None)?;
child
.expect("Child process is expected for `localhost`")
.kill()
.ok();
test(&api_url, None, true)?;
kill_child(child)?;
},
Environment::Docker => bencher_down()?,
Environment::Dev => test(&api_url, Some(&DEV_BENCHER_API_TOKEN))?,
Environment::Dev => test(&api_url, Some(&DEV_BENCHER_API_TOKEN), false)?,
Environment::Test | Environment::Prod => {},
}

Expand All @@ -89,7 +92,7 @@ impl SmokeTest {
impl Environment {
fn as_url(self) -> Url {
match self {
Self::Localhost | Self::Docker => LOCALHOST_BENCHER_API_URL.clone(),
Self::Ci | Self::Localhost | Self::Docker => LOCALHOST_BENCHER_API_URL.clone(),
Self::Dev => DEV_BENCHER_API_URL.clone(),
Self::Test => TEST_BENCHER_API_URL.clone(),
Self::Prod => PROD_BENCHER_API_URL.clone(),
Expand Down Expand Up @@ -166,8 +169,12 @@ fn test_api_version(api_url: &Url) -> anyhow::Result<()> {
Ok(())
}

fn test(api_url: &Url, token: Option<&Jwt>) -> anyhow::Result<()> {
seed(api_url, token).and_then(|()| examples(api_url, token))
fn test(api_url: &Url, token: Option<&Jwt>, run_examples: bool) -> anyhow::Result<()> {
seed(api_url, token)?;
if run_examples {
examples(api_url, token)?;
}
Ok(())
}

fn seed(api_url: &Url, token: Option<&Jwt>) -> anyhow::Result<()> {
Expand All @@ -188,3 +195,10 @@ fn examples(api_url: &Url, token: Option<&Jwt>) -> anyhow::Result<()> {
})?;
examples.exec()
}

fn kill_child(child: Option<Child>) -> anyhow::Result<()> {
child
.expect("Child process is expected for `localhost`")
.kill()
.map_err(Into::into)
}

0 comments on commit 8be4539

Please sign in to comment.