usage-meter-poll: pin what the production client is built with (finding new-client-timeout-unpinned)
UsageClient carries its timeout and url; UsageClient::production() is what start() builds, and the test asserts that client's url and 10 s timeout as spec r2 says, replacing a 1..=60 s bound no rule names. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
481428a7ce
commit
f242290ca5
1 changed files with 16 additions and 5 deletions
|
|
@ -141,13 +141,20 @@ fn parse_usage(body: &str) -> Option<Vec<PlanQuota>> {
|
||||||
|
|
||||||
/// The blocking HTTPS client: 10 s end to end, no redirects (the token must
|
/// The blocking HTTPS client: 10 s end to end, no redirects (the token must
|
||||||
/// not follow one anywhere).
|
/// not follow one anywhere).
|
||||||
struct UsageClient {
|
pub(crate) struct UsageClient {
|
||||||
agent: ureq::Agent,
|
agent: ureq::Agent,
|
||||||
url: String,
|
url: String,
|
||||||
|
timeout: Duration,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UsageClient {
|
impl UsageClient {
|
||||||
fn new(url: impl Into<String>) -> Self {
|
/// The client that asks the provider's usage endpoint.
|
||||||
|
pub(crate) fn production() -> Self {
|
||||||
|
Self::new(ENDPOINT)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A client for another endpoint: a test's fake server.
|
||||||
|
pub(crate) fn new(url: impl Into<String>) -> Self {
|
||||||
Self::with_timeout(url, TIMEOUT)
|
Self::with_timeout(url, TIMEOUT)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -158,6 +165,7 @@ impl UsageClient {
|
||||||
.redirects(0)
|
.redirects(0)
|
||||||
.build(),
|
.build(),
|
||||||
url: url.into(),
|
url: url.into(),
|
||||||
|
timeout,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -392,7 +400,7 @@ pub fn start(
|
||||||
let poller = Poller::new(
|
let poller = Poller::new(
|
||||||
cell,
|
cell,
|
||||||
tokens,
|
tokens,
|
||||||
UsageClient::new(ENDPOINT),
|
UsageClient::production(),
|
||||||
Box::new(|line| eprintln!("claude-connector: {line}")),
|
Box::new(|line| eprintln!("claude-connector: {line}")),
|
||||||
);
|
);
|
||||||
std::thread::Builder::new()
|
std::thread::Builder::new()
|
||||||
|
|
@ -962,8 +970,11 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn the_real_timeout_frees_the_thread_within_a_minute() {
|
fn the_production_client_asks_the_provider_and_gives_up_after_ten_seconds() {
|
||||||
assert!(TIMEOUT >= secs(1) && TIMEOUT <= secs(60), "{TIMEOUT:?}");
|
let client = UsageClient::production();
|
||||||
|
assert_eq!(client.url, "https://api.anthropic.com/api/oauth/usage");
|
||||||
|
assert_eq!(client.timeout, secs(10));
|
||||||
|
assert_eq!(TIMEOUT, secs(10));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Answers one connection after `delay`, as a slow endpoint does.
|
/// Answers one connection after `delay`, as a slow endpoint does.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue