Skip to content

Commit

Permalink
Revert changes on binary engine
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelff committed Dec 15, 2022
1 parent 91ab6d5 commit 5bfa149
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 58 deletions.
Original file line number Diff line number Diff line change
@@ -1,42 +1,27 @@
use crate::{ConnectorTag, RunnerInterface, TestError, TestResult, TxResult};
use hyper::{Body, HeaderMap, Method, Request, Response};
use hyper::{Body, Method, Request, Response};
use query_core::{schema::QuerySchemaRef, TxId};
use query_engine::opt::PrismaOpt;
use query_engine::server::routes;
use query_engine::state::{self, State};
use query_engine::server::{routes, setup, State};
use query_engine_metrics::MetricRegistry;
use request_handlers::{GQLBatchResponse, GQLError, GQLResponse, GraphQlBody, MultiQuery, PrismaResponse};

pub struct BinaryRunner {
connector_tag: ConnectorTag,
current_tx_id: Option<TxId>,
additional_headers: Option<HeaderMap>,
state: State,
}

impl BinaryRunner {
pub(crate) fn set_additional_headers(&mut self, headers: Option<HeaderMap>) {
self.additional_headers = headers;
}
}

#[async_trait::async_trait]
impl RunnerInterface for BinaryRunner {
async fn load(datamodel: String, connector_tag: ConnectorTag, metrics: MetricRegistry) -> TestResult<Self> {
let opts = PrismaOpt::from_list(&[
"binary",
"--enable-raw-queries",
"--enable-logs-in-response",
"--datamodel",
&datamodel,
]);
let state = state::setup(&opts, false, Some(metrics)).await.unwrap();
let opts = PrismaOpt::from_list(&["binary", "--enable-raw-queries", "--datamodel", &datamodel]);
let state = setup(&opts, metrics).await.unwrap();

Ok(BinaryRunner {
state,
connector_tag,
current_tx_id: None,
additional_headers: None,
})
}

Expand All @@ -51,12 +36,6 @@ impl RunnerInterface for BinaryRunner {
builder = builder.header("X-transaction-id", tx_id);
}

if let Some(headers) = &self.additional_headers {
for (key, value) in headers {
builder = builder.header(key, value);
}
}

let req = builder.body(Body::from(body)).unwrap();

let resp = routes(self.state.clone(), req).await.unwrap();
Expand All @@ -83,17 +62,13 @@ impl RunnerInterface for BinaryRunner {

let mut builder = Request::builder().method(Method::POST);

// Garren: basically if there is a current_tx_id we run it as a transaction
// I don't fully understand how ITX works and I need to do this to pass the tests
if self.current_tx_id.is_some() {
let tx_id: String = self.current_tx_id.clone().unwrap().to_string();
let tx_id: String = self.current_tx_id.as_ref().unwrap().clone().to_string();
builder = builder.header("X-transaction-id", tx_id);
}

if let Some(headers) = &self.additional_headers {
for (key, value) in headers {
builder = builder.header(key, value);
}
}

let req = builder.body(Body::from(body)).unwrap();

let resp = routes(self.state.clone(), req).await.unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ mod binary;
mod direct;
mod node_api;

use std::collections::HashMap;

pub use binary::*;
pub use direct::*;
use hyper::HeaderMap;
pub use node_api::*;
use query_core::{schema::QuerySchemaRef, TxId};
use query_engine_metrics::MetricRegistry;
Expand Down Expand Up @@ -165,29 +162,6 @@ impl Runner {
}
}

pub fn set_headers(&mut self, headers: HashMap<String, String>) {
match &mut self.inner {
RunnerType::Direct(_) => todo!(),
RunnerType::NodeApi(_) => todo!(),
RunnerType::Binary(r) => {
let map = Some(HeaderMap::from_iter(
headers
.into_iter()
.map(|(k, v)| (k.parse().unwrap(), v.parse().unwrap())),
));
r.set_additional_headers(map)
}
}
}

pub fn clear_headers(&mut self) {
match &mut self.inner {
RunnerType::Direct(_) => todo!(),
RunnerType::NodeApi(_) => todo!(),
RunnerType::Binary(r) => r.set_additional_headers(None),
}
}

async fn direct(datamodel: String, connector_tag: ConnectorTag, metrics: MetricRegistry) -> TestResult<RunnerType> {
let runner = DirectRunner::load(datamodel, connector_tag, metrics).await?;

Expand Down

0 comments on commit 5bfa149

Please sign in to comment.