Skip to content

Commit

Permalink
Use async requwest Client in test playground
Browse files Browse the repository at this point in the history
  • Loading branch information
Westwooo committed Jul 16, 2024
1 parent eeb0217 commit bbca3e8
Showing 1 changed file with 16 additions and 29 deletions.
45 changes: 16 additions & 29 deletions tests/common/playground.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::common::{utils, TestConfig, TestResult};
use log::debug;
use nu_test_support::pipeline;
use nu_test_support::playground::{Dirs, Playground};
use reqwest::blocking::{Client, ClientBuilder};
use reqwest::{Client, ClientBuilder};
use serde_json::{Error, Value};
use std::collections::HashMap;
use std::ops::Add;
Expand Down Expand Up @@ -401,17 +401,13 @@ impl CBPlayground {

let uri = build_uri(conn_string.clone(), bucket, None).await;

// Send creates it's own runtime so need to spwn a thread where blocking is allowed to do this in an async fn
let res = task::spawn_blocking(move || {
client
.post(uri)
.form(&params)
.basic_auth(username, Some(password))
.send()
.unwrap()
})
.await
.unwrap();
let res = client
.post(uri)
.form(&params)
.basic_auth(username, Some(password))
.send()
.await
.unwrap();

if !res.status().is_success() {
panic!("Create scope failed: {}", res.status())
Expand All @@ -437,17 +433,13 @@ impl CBPlayground {

let uri = build_uri(conn_string.clone(), bucket, scope).await;

// Send creates it's own runtime so need to spwn a thread where blocking is allowed to do this in an async fn
let res = task::spawn_blocking(move || {
client
.post(uri)
.form(&params)
.basic_auth(username, Some(password))
.send()
.unwrap()
})
.await
.unwrap();
let res = client
.post(uri)
.form(&params)
.basic_auth(username, Some(password))
.send()
.await
.unwrap();

if !res.status().is_success() {
panic!("Create collection failed: {}", res.status())
Expand Down Expand Up @@ -476,12 +468,7 @@ async fn build_client(conn_string: String) -> Client {
.with_no_client_auth();
client_builder = client_builder.use_preconfigured_tls(config);
};

// Build creates it's own runtime, so we need to spawn a thread where blocking is allowed so that this can be called
// in an async function
task::spawn_blocking(move || client_builder.build().unwrap())
.await
.unwrap()
client_builder.build().unwrap()
}

async fn build_uri(
Expand Down

0 comments on commit bbca3e8

Please sign in to comment.