Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharmath committed Oct 1, 2024
1 parent 3ce9bfd commit bb028c5
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 82 deletions.
35 changes: 35 additions & 0 deletions src/core/jit/fixtures/dedupe.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
schema
@server(port: 8000, hostname: "0.0.0.0")
@upstream(baseURL: "http://jsonplaceholder.typicode.com", httpCache: 42) {
query: Query
}

type Query {
posts: [Post] @http(path: "/posts")
users: [User] @http(path: "/users", dedupe: true)
}

type User {
id: ID!
name: String!
username: String!
email: String!
phone: String
comments: [Comment] @http(path: "/users/{{.value.id}}/comments", dedupe: true)
}

type Post {
id: ID!
userId: ID!
title: String!
body: String!
user: User @http(path: "/users/{{.value.userId}}", dedupe: true)
}

type Comment {
id: ID!
name: String!
email: String!
body: String!
postId: ID!
}
46 changes: 18 additions & 28 deletions src/core/jit/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,12 +695,22 @@ mod test {
use async_graphql::Request;
use async_graphql_value::ConstValue;

use super::Directive;
use super::{Directive, OperationPlan};
use crate::core::blueprint::Blueprint;
use crate::core::config::ConfigModule;
use crate::core::jit;
use crate::include_config;

fn plan(query: &str) -> OperationPlan<ConstValue> {
let config = include_config!("./fixtures/dedupe.graphql").unwrap();
let module = ConfigModule::from(config);
let bp = Blueprint::try_from(&module).unwrap();

let request = Request::new(query);
let jit_request = jit::Request::from(request);
jit_request.create_plan(&bp).unwrap()
}

#[test]
fn test_from_custom_directive() {
let custom_directive = Directive {
Expand All @@ -711,45 +721,25 @@ mod test {
let async_directive: ConstDirective = (&custom_directive).into();
insta::assert_debug_snapshot!(async_directive);
}

#[test]
fn test_operation_plan_dedupe() {
let config =
include_config!("../../../tailcall-fixtures/fixtures/configs/dedupe.graphql").unwrap();
let module = ConfigModule::from(config);
let bp = Blueprint::try_from(&module).unwrap();
let actual = plan(r#"{ posts { id } }"#);

let request = Request::new(r#"{ posts { id } }"#);
let jit_request = jit::Request::from(request);
let plan = jit_request.create_plan(&bp).unwrap();

assert!(plan.dedupe);
assert!(!actual.dedupe);
}

#[test]
fn test_operation_plan_dedupe_nested() {
let config =
include_config!("../../../tailcall-fixtures/fixtures/configs/dedupe.graphql").unwrap();
let module = ConfigModule::from(config);
let bp = Blueprint::try_from(&module).unwrap();

let request = Request::new(r#"{ posts { id users { id } } }"#);
let jit_request = jit::Request::from(request);
let plan = jit_request.create_plan(&bp).unwrap();
let actual = plan(r#"{ posts { id users { id } } }"#);

assert!(!plan.dedupe);
assert!(!actual.dedupe);
}

#[test]
fn test_operation_plan_dedupe_false() {
let config =
include_config!("../../../tailcall-fixtures/fixtures/configs/dedupe.graphql").unwrap();
let module = ConfigModule::from(config);
let bp = Blueprint::try_from(&module).unwrap();

let request = Request::new(r#"{ users { id } }"#);
let jit_request = jit::Request::from(request);
let plan = jit_request.create_plan(&bp).unwrap();
let actual = plan(r#"{ users { id comments {body} } }"#);

assert!(!plan.dedupe);
assert!(actual.dedupe);
}
}
54 changes: 0 additions & 54 deletions tailcall-fixtures/fixtures/configs/dedupe.graphql

This file was deleted.

1 comment on commit bb028c5

@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 7.13ms 2.82ms 38.79ms 66.74%
Req/Sec 3.53k 180.14 5.48k 88.08%

421407 requests in 30.04s, 785.46MB read

Requests/sec: 14027.99

Transfer/sec: 26.15MB

Please sign in to comment.