From 406e6ba4ce3b0f35d648d9f0eb6f39ad4ae237dd Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Thu, 14 Apr 2022 14:25:01 +0800 Subject: [PATCH 1/3] ci: Add github actions for CI Signed-off-by: Xuanwo --- .github/FUNDING.yml | 1 + .github/actions/check/action.yml | 35 +++++++++++++++++++++ .github/dependabot.yml | 13 ++++++++ .github/workflows/ci.yml | 52 ++++++++++++++++++++++++++++++++ 4 files changed, 101 insertions(+) create mode 100644 .github/FUNDING.yml create mode 100644 .github/actions/check/action.yml create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/ci.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..01c631a --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: [Xuanwo] diff --git a/.github/actions/check/action.yml b/.github/actions/check/action.yml new file mode 100644 index 0000000..4e1d0ae --- /dev/null +++ b/.github/actions/check/action.yml @@ -0,0 +1,35 @@ +name: 'Check' +description: 'Check will do all essential checks' +inputs: + github_token: + description: "Github Token" + required: true +runs: + using: "composite" + steps: + - uses: Swatinem/rust-cache@v1 + with: + sharedKey: base-v1 + + - name: Format + uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check + + - name: Install cargo-audit + uses: actions-rs/cargo@v1 + with: + command: install + args: cargo-audit + + - name: Audit dependencies + uses: actions-rs/cargo@v1 + with: + command: audit + + - name: Clippy + uses: actions-rs/cargo@v1 + with: + command: clippy + args: --all-targets -- -D warnings diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..5de1e1c --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,13 @@ +version: 2 +updates: + # Maintain dependencies for GitHub Actions + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" + + # Maintain dependencies for rust + - package-ecosystem: "cargo" + directory: "/" + schedule: + interval: "daily" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..3cd8023 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,52 @@ +name: CI + +on: [push, pull_request] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }} + cancel-in-progress: true + +jobs: + check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: ./.github/actions/check + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + + build: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: + - ubuntu-latest + - macos-11 + - windows-latest + steps: + - uses: actions/checkout@v3 + - uses: Swatinem/rust-cache@v1 + - name: Build + uses: actions-rs/cargo@v1 + with: + command: build + + unit: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: + - ubuntu-latest + - macos-11 + - windows-latest + steps: + - uses: actions/checkout@v3 + - uses: Swatinem/rust-cache@v1 + - name: Test + uses: actions-rs/cargo@v1 + with: + command: test + args: -- --nocapture + env: + RUST_LOG: DEBUG + RUST_BACKTRACE: full From c503691eb8e388239cfbcc2f6c820b4c0a1f8987 Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Thu, 14 Apr 2022 14:29:32 +0800 Subject: [PATCH 2/3] Fix CI Signed-off-by: Xuanwo --- src/constant.rs | 1 + src/retry.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/constant.rs b/src/constant.rs index 9016888..58f410c 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -26,6 +26,7 @@ use std::time::Duration; /// Ok(()) /// } /// ``` +#[derive(Debug, Clone)] pub struct ConstantBackoff { delay: Duration, max_times: Option, diff --git a/src/retry.rs b/src/retry.rs index 802cb53..3119499 100644 --- a/src/retry.rs +++ b/src/retry.rs @@ -167,7 +167,7 @@ mod tests { } #[tokio::test] - async fn test_retry_x() -> anyhow::Result<()> { + async fn test_retry() -> anyhow::Result<()> { let result = always_error .retry(ExponentialBackoff::default().with_min_delay(Duration::from_millis(1))) .await; From d9e2c0ea913ea96b2bbb516ecef4825ea25d568c Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Thu, 14 Apr 2022 14:32:58 +0800 Subject: [PATCH 3/3] Fix docs Signed-off-by: Xuanwo --- src/retry.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/retry.rs b/src/retry.rs index 3119499..2b42242 100644 --- a/src/retry.rs +++ b/src/retry.rs @@ -97,10 +97,15 @@ pub struct Retry< state: State, } +/// State maintains internal state of retry. +/// +/// # Notes +/// +/// `tokio::time::Sleep` is a very struct that occupy 640B, so we wrap it +/// into a `Pin>` to avoid this enum too large. #[pin_project(project = StateProject)] enum State>> { Idle, - Polling(#[pin] Fut), // TODO: we need to support other sleeper Sleeping(#[pin] Pin>), @@ -130,7 +135,6 @@ where match state { StateProject::Idle => { let fut = (this.future_fn)(); - // this.state = State::Polling(fut); this.state.set(State::Polling(fut)); continue; }