Skip to content

Commit

Permalink
refactor: remove unnecessary closure
Browse files Browse the repository at this point in the history
  • Loading branch information
anchpop committed Jan 6, 2025
1 parent 07c9931 commit febda61
Showing 1 changed file with 24 additions and 32 deletions.
56 changes: 24 additions & 32 deletions rs/pocket_ic_server/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,35 +291,32 @@ async fn test_gateway(server_url: Url, https: bool) {
assert_eq!(http_gateway_details.https_config, https_config);

// create a non-blocking reqwest client resolving localhost/example.com and <canister-id>.(raw.)localhost/example.com to 127.0.0.1
let create_client = || {
let mut builder = NonblockingClient::builder();
for domain in [
localhost,
sub_localhost,
sub_raw_localhost,
alt_domain,
sub_alt_domain,
sub_raw_alt_domain,
] {
builder = builder.resolve(
domain,
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), port),
);
}
// add a custom root certificate
if https {
builder = builder.add_root_certificate(
reqwest::Certificate::from_pem(root_cert.pem().as_bytes()).unwrap(),
);
}
builder.build().unwrap()
};
let client = create_client();
let mut builder = NonblockingClient::builder();
for domain in [
localhost,
sub_localhost,
sub_raw_localhost,
alt_domain,
sub_alt_domain,
sub_raw_alt_domain,
] {
builder = builder.resolve(
domain,
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), port),
);
}
// add a custom root certificate
if https {
builder = builder.add_root_certificate(
reqwest::Certificate::from_pem(root_cert.pem().as_bytes()).unwrap(),
);
}
let client = builder.build().unwrap();

// create agent
let agent = ic_agent::Agent::builder()
.with_url(format!("{}://{}:{}", proto, localhost, port))
.with_http_client(client)
.with_http_client(client.clone())
.build()
.unwrap();
agent.fetch_root_key().await.unwrap();
Expand Down Expand Up @@ -379,7 +376,7 @@ async fn test_gateway(server_url: Url, https: bool) {
test_urls.push(canister_url.clone());

for url in test_urls {
let res = create_client().get(url).send().await.unwrap();
let res = client.get(url).send().await.unwrap();
let page = String::from_utf8(res.bytes().await.unwrap().to_vec()).unwrap();
assert!(page.contains("<title>Internet Identity</title>"));
}
Expand All @@ -389,12 +386,7 @@ async fn test_gateway(server_url: Url, https: bool) {

// HTTP gateway should eventually stop and requests to it fail
loop {
if create_client()
.get(canister_url.clone())
.send()
.await
.is_err()
{
if client.get(canister_url.clone()).send().await.is_err() {
break;
}
std::thread::sleep(Duration::from_millis(20));
Expand Down

0 comments on commit febda61

Please sign in to comment.