Skip to content

Commit

Permalink
ci: Fix wasm unit test (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xuanwo authored Nov 22, 2024
1 parent 7afbfcd commit 3e59ed3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: latest
- name: Install
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- run: wasm-pack test --node --all-features -- --skip blocking
working-directory: backon
env:
RUST_LOG: DEBUG
RUST_BACKTRACE: full
15 changes: 5 additions & 10 deletions backon/src/retry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,18 +341,17 @@ mod default_sleeper_tests {
}

#[test]
async fn test_retry() -> anyhow::Result<()> {
async fn test_retry() {
let result = always_error
.retry(ExponentialBuilder::default().with_min_delay(Duration::from_millis(1)))
.await;

assert!(result.is_err());
assert_eq!("test_query meets error", result.unwrap_err().to_string());
Ok(())
}

#[test]
async fn test_retry_with_not_retryable_error() -> anyhow::Result<()> {
async fn test_retry_with_not_retryable_error() {
let error_times = Mutex::new(0);

let f = || async {
Expand All @@ -373,11 +372,10 @@ mod default_sleeper_tests {
// `f` always returns error "not retryable", so it should be executed
// only once.
assert_eq!(*error_times.lock().await, 1);
Ok(())
}

#[test]
async fn test_retry_with_retryable_error() -> anyhow::Result<()> {
async fn test_retry_with_retryable_error() {
let error_times = Mutex::new(0);

let f = || async {
Expand All @@ -398,11 +396,10 @@ mod default_sleeper_tests {
// `f` always returns error "retryable", so it should be executed
// 4 times (retry 3 times).
assert_eq!(*error_times.lock().await, 4);
Ok(())
}

#[test]
async fn test_fn_mut_when_and_notify() -> anyhow::Result<()> {
async fn test_fn_mut_when_and_notify() {
let mut calls_retryable: Vec<()> = vec![];
let mut calls_notify: Vec<()> = vec![];

Expand All @@ -426,7 +423,6 @@ mod default_sleeper_tests {
// 4 times (retry 3 times).
assert_eq!(calls_retryable.len(), 4);
assert_eq!(calls_notify.len(), 3);
Ok(())
}
}

Expand All @@ -449,14 +445,13 @@ mod custom_sleeper_tests {
}

#[test]
async fn test_retry_with_sleep() -> anyhow::Result<()> {
async fn test_retry_with_sleep() {
let result = always_error
.retry(ExponentialBuilder::default().with_min_delay(Duration::from_millis(1)))
.sleep(|_| ready(()))
.await;

assert!(result.is_err());
assert_eq!("test_query meets error", result.unwrap_err().to_string());
Ok(())
}
}
3 changes: 1 addition & 2 deletions backon/src/retry_with_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ mod tests {
}

#[test]
async fn test_retry_with_not_retryable_error() -> Result<()> {
async fn test_retry_with_not_retryable_error() {
let error_times = Mutex::new(0);

let test = Test;
Expand All @@ -414,6 +414,5 @@ mod tests {
// `f` always returns error "not retryable", so it should be executed
// only once.
assert_eq!(*error_times.lock().await, 1);
Ok(())
}
}

0 comments on commit 3e59ed3

Please sign in to comment.