Skip to content

Commit 1831073

Browse files
authored
Fix weird bug in checking stuff (#59)
2 parents b23ff53 + fdd9f90 commit 1831073

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

src/checking.rs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ async fn mark_server_as_online() {
7474
*ping_info = (at, true);
7575
}
7676

77-
/// Check if the server is online by either getting a cached value (cached for `ONLINE_CHECK_TTL_MS`), or by pinging `8.8.8.8`.
77+
/// Check if the server is online by either getting a cached value (cached for `ONLINE_CHECK_TTL_MS`), or by requesting our repository.
7878
async fn is_online() -> bool {
7979
{
8080
// Has it been checked within the TTL?
@@ -95,20 +95,12 @@ async fn is_online() -> bool {
9595
}
9696

9797
// Head-request our repository to make sure we're online.
98-
// Pings don't work in GitHub Actions runners, so if we're running tests, just pretend
99-
// our ping succeeded.
100-
let ping_successful = if cfg!(debug_assertions)
101-
&& std::env::var("GITHUB_ACTIONS").is_ok_and(|val| val == "true")
102-
{
103-
true
104-
} else {
105-
let result = CLIENT
106-
.head(env!("CARGO_PKG_REPOSITORY"))
107-
.send()
108-
.await
109-
.and_then(Response::error_for_status);
110-
result.is_ok()
111-
};
98+
let result = CLIENT
99+
.head(env!("CARGO_PKG_REPOSITORY"))
100+
.send()
101+
.await
102+
.and_then(Response::error_for_status);
103+
let ping_successful = result.is_ok();
112104

113105
// Write the info
114106
let now = Utc::now().timestamp_millis();
@@ -190,7 +182,9 @@ async fn check_impl(
190182

191183
retry_limit -= 1;
192184

193-
tokio::time::sleep(RETRY_TIMEOUT).await;
185+
if !cfg!(test) {
186+
tokio::time::sleep(RETRY_TIMEOUT).await;
187+
}
194188
}
195189

196190
let response = match response {
@@ -880,7 +874,7 @@ mod tests {
880874
assert_eq!(expected, links.to_message());
881875
}
882876

883-
#[tokio::test(start_paused = true)]
877+
#[tokio::test]
884878
async fn check_failure_types() {
885879
// Start a web server so we can do each kinds of checks
886880
let server_addr = ("127.0.0.1", 32750);
@@ -961,7 +955,7 @@ mod tests {
961955
}
962956
}
963957

964-
#[tokio::test(start_paused = true)]
958+
#[tokio::test]
965959
async fn test_retrying() {
966960
// Start a web server that fails only the first request
967961
let server_addr = ("127.0.0.1", 32752);
@@ -986,7 +980,14 @@ mod tests {
986980
} else {
987981
err_hits_for_server.fetch_add(1, Ordering::Relaxed);
988982
// Trigger the request timeout
989-
tokio::time::sleep(Duration::from_secs(1) + REQUEST_TIMEOUT).await;
983+
let sleep = tokio::time::sleep(Duration::from_secs(1) + REQUEST_TIMEOUT);
984+
985+
// we don't want to wait for realsies
986+
tokio::time::pause();
987+
tokio::time::advance(REQUEST_TIMEOUT - Duration::from_millis(100)).await;
988+
tokio::time::resume();
989+
990+
sleep.await;
990991
Response::builder()
991992
.status(500)
992993
.body(Body::from("Retry plz!"))

src/webring.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ mod tests {
734734
}
735735

736736
#[expect(clippy::too_many_lines)]
737-
#[tokio::test(start_paused = true)]
737+
#[tokio::test]
738738
async fn test_webring() {
739739
let config = make_config();
740740
let webring = Webring::new(&config);

0 commit comments

Comments
 (0)