Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mehulmathur16 committed Jun 15, 2024
1 parent 7242223 commit 04aab0c
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 39 deletions.
3 changes: 1 addition & 2 deletions benches/data_loader_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ use criterion::Criterion;
use hyper::body::Bytes;
use reqwest::Request;
use tailcall::core::config::Batch;
use tailcall::core::error::file;
use tailcall::core::error::http;
use tailcall::core::error::{file, http};
use tailcall::core::http::{DataLoaderRequest, HttpDataLoader, Response};
use tailcall::core::ir::IoId;
use tailcall::core::runtime::TargetRuntime;
Expand Down
3 changes: 1 addition & 2 deletions benches/impl_path_string_for_evaluation_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ use reqwest::{Client, Request};
use reqwest_middleware::{ClientBuilder, ClientWithMiddleware};
use tailcall::core::blueprint::{Server, Upstream};
use tailcall::core::cache::InMemoryCache;
use tailcall::core::error::file;
use tailcall::core::error::http;
use tailcall::core::error::{file, http};
use tailcall::core::http::{RequestContext, Response};
use tailcall::core::ir::{EvaluationContext, ResolverContextLike};
use tailcall::core::path::PathString;
Expand Down
4 changes: 1 addition & 3 deletions src/cli/javascript/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ pub use runtime::Runtime;
use crate::cli::Result;
use crate::core::{blueprint, WorkerIO};

pub fn init_worker_io<T, V>(
script: blueprint::Script,
) -> Arc<dyn WorkerIO<T, V> + Send + Sync>
pub fn init_worker_io<T, V>(script: blueprint::Script) -> Arc<dyn WorkerIO<T, V> + Send + Sync>
where
Runtime: WorkerIO<T, V>,
{
Expand Down
9 changes: 1 addition & 8 deletions src/cli/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,7 @@ fn init_http_worker_io(

fn init_resolver_worker_io(
script: Option<blueprint::Script>,
) -> Option<
Arc<
dyn WorkerIO<
async_graphql::Value,
async_graphql::Value,
>,
>,
> {
) -> Option<Arc<dyn WorkerIO<async_graphql::Value, async_graphql::Value>>> {
#[cfg(feature = "js")]
return Some(super::javascript::init_worker_io(script?));
#[cfg(not(feature = "js"))]
Expand Down
3 changes: 1 addition & 2 deletions src/cli/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ fn set_trace_provider(
.install_batch(runtime::Tokio)?
.provider()
.ok_or(TraceError::Other(
Error::TelemetryTrace("Failed to instantiate OTLP provider".to_string())
.into(),
Error::TelemetryTrace("Failed to instantiate OTLP provider".to_string()).into(),
))?,
// Prometheus works only with metrics
TelemetryExporter::Prometheus(_) => return Ok(None),
Expand Down
3 changes: 1 addition & 2 deletions src/core/http/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use prost::Message;
use tonic::Status;
use tonic_types::Status as GrpcStatus;

use crate::core::error::http;
use crate::core::error::Error as CoreError;
use crate::core::error::{http, Error as CoreError};
use crate::core::grpc::protobuf::ProtobufOperation;
use crate::core::ir::Error;

Expand Down
4 changes: 1 addition & 3 deletions src/core/ir/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ use std::sync::Arc;
use async_graphql::{ErrorExtensions, Value as ConstValue};

use crate::core::auth;
use crate::core::error::http;
use crate::core::error::worker;
use crate::core::error::Error as CoreError;
use crate::core::error::{http, worker, Error as CoreError};

#[derive(Debug, thiserror::Error, Clone)]
pub enum Error {
Expand Down
6 changes: 5 additions & 1 deletion src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ pub trait HttpIO: Sync + Send + 'static {

#[async_trait::async_trait]
pub trait FileIO: Send + Sync {
async fn write<'a>(&'a self, path: &'a str, content: &'a [u8]) -> Result<(), error::file::Error>;
async fn write<'a>(
&'a self,
path: &'a str,
content: &'a [u8],
) -> Result<(), error::file::Error>;
async fn read<'a>(&'a self, path: &'a str) -> Result<String, error::file::Error>;
}

Expand Down
8 changes: 5 additions & 3 deletions src/core/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ pub struct TargetRuntime {
/// Worker middleware for handling HTTP requests.
pub cmd_worker: Option<Arc<dyn WorkerIO<Event, Command>>>,
/// Worker middleware for resolving data.
pub worker:
Option<Arc<dyn WorkerIO<ConstValue, ConstValue>>>,
pub worker: Option<Arc<dyn WorkerIO<ConstValue, ConstValue>>>,
}

impl TargetRuntime {
Expand Down Expand Up @@ -151,7 +150,10 @@ pub mod test {
Ok(())
}

async fn read<'a>(&'a self, path: &'a str) -> crate::core::Result<String, error::file::Error> {
async fn read<'a>(
&'a self,
path: &'a str,
) -> crate::core::Result<String, error::file::Error> {
let mut file = tokio::fs::File::open(path).await?;
let mut buffer = Vec::new();
file.read_to_end(&mut buffer).await?;
Expand Down
5 changes: 1 addition & 4 deletions tailcall-cloudflare/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ fn init_env(env: Rc<worker::Env>) -> Arc<dyn EnvIO> {
Arc::new(env::CloudflareEnv::init(env))
}

fn init_file(
env: Rc<worker::Env>,
bucket_id: &str,
) -> anyhow::Result<Arc<dyn FileIO>> {
fn init_file(env: Rc<worker::Env>, bucket_id: &str) -> anyhow::Result<Arc<dyn FileIO>> {
Ok(Arc::new(file::CloudflareFileIO::init(env, bucket_id)?))
}

Expand Down
12 changes: 6 additions & 6 deletions tests/core/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,12 @@ impl ExecutionSpec {
None
};

let worker: Option<Arc<dyn WorkerIO<ConstValue, ConstValue>>> =
if let Some(script) = script {
Some(javascript::init_worker_io(script))
} else {
None
};
let worker: Option<Arc<dyn WorkerIO<ConstValue, ConstValue>>> = if let Some(script) = script
{
Some(javascript::init_worker_io(script))
} else {
None
};

let runtime = TargetRuntime {
http,
Expand Down
8 changes: 5 additions & 3 deletions tests/server_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ pub mod test {
use tailcall::core::blueprint::{Script, Upstream};
use tailcall::core::cache::InMemoryCache;
use tailcall::core::error::file;
use tailcall::core::error;
use tailcall::core::http::Response;
use tailcall::core::runtime::TargetRuntime;
use tailcall::core::worker::{Command, Event};
use tailcall::core::{EnvIO, FileIO, HttpIO};
use tailcall::core::{error, EnvIO, FileIO, HttpIO};
use tailcall_http_cache::HttpCacheManager;
use tokio::io::{AsyncReadExt, AsyncWriteExt};

Expand Down Expand Up @@ -75,7 +74,10 @@ pub mod test {

#[async_trait::async_trait]
impl HttpIO for TestHttp {
async fn execute(&self, request: reqwest::Request) -> Result<Response<Bytes>, error::http::Error> {
async fn execute(
&self,
request: reqwest::Request,
) -> Result<Response<Bytes>, error::http::Error> {
let response = self.client.execute(request).await;
Response::from_reqwest(
response?
Expand Down

1 comment on commit 04aab0c

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running 30s test @ http://localhost:8000/graphql

4 threads and 100 connections

Thread Stats Avg Stdev Max +/- Stdev
Latency 6.61ms 3.02ms 83.91ms 72.16%
Req/Sec 3.83k 195.14 4.26k 91.25%

457176 requests in 30.01s, 2.29GB read

Requests/sec: 15232.81

Transfer/sec: 78.19MB

Please sign in to comment.