mirror of
https://github.com/Diggsey/sqlxmq.git
synced 2024-05-31 23:48:12 +00:00
Refactoring
This commit is contained in:
parent
e1821655ba
commit
e5a9cf4ad7
23
src/lib.rs
23
src/lib.rs
|
@ -375,8 +375,16 @@ mod tests {
|
|||
std::env::var("GITHUB_ACTIONS").ok().is_some()
|
||||
}
|
||||
|
||||
fn default_pause() -> u64 {
|
||||
if is_github_actions() {
|
||||
1000
|
||||
} else {
|
||||
200
|
||||
}
|
||||
}
|
||||
|
||||
async fn pause() {
|
||||
pause_ms(200).await;
|
||||
pause_ms(default_pause()).await;
|
||||
}
|
||||
|
||||
async fn pause_ms(ms: u64) {
|
||||
|
@ -393,9 +401,6 @@ mod tests {
|
|||
assert_eq!(counter.load(Ordering::SeqCst), 0);
|
||||
JobBuilder::new("foo").spawn(pool).await.unwrap();
|
||||
pause().await;
|
||||
if is_github_actions() {
|
||||
pause_ms(1000).await;
|
||||
}
|
||||
assert_eq!(counter.load(Ordering::SeqCst), 1);
|
||||
}
|
||||
pause().await;
|
||||
|
@ -520,7 +525,7 @@ mod tests {
|
|||
let pool = &*test_pool().await;
|
||||
let (_runner, counter) = test_job_runner(pool, move |_| async {}).await;
|
||||
|
||||
let backoff = 500;
|
||||
let backoff = default_pause() + 300;
|
||||
|
||||
assert_eq!(counter.load(Ordering::SeqCst), 0);
|
||||
JobBuilder::new("foo")
|
||||
|
@ -568,7 +573,7 @@ mod tests {
|
|||
})
|
||||
.await;
|
||||
|
||||
let backoff = 200;
|
||||
let backoff = default_pause();
|
||||
|
||||
assert_eq!(counter.load(Ordering::SeqCst), 0);
|
||||
JobBuilder::new("foo")
|
||||
|
@ -586,16 +591,10 @@ mod tests {
|
|||
|
||||
// Second attempt
|
||||
pause_ms(backoff).await;
|
||||
if is_github_actions() {
|
||||
pause_ms(1000).await;
|
||||
}
|
||||
assert_eq!(counter.load(Ordering::SeqCst), 2);
|
||||
|
||||
// No more attempts
|
||||
pause_ms(backoff * 3).await;
|
||||
if is_github_actions() {
|
||||
pause_ms(1000).await;
|
||||
}
|
||||
assert_eq!(counter.load(Ordering::SeqCst), 2);
|
||||
}
|
||||
pause().await;
|
||||
|
|
Loading…
Reference in a new issue