Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions server/tests-py/remote_relationship_tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__pycache__
test_output
.previous_work_dir
50 changes: 50 additions & 0 deletions server/tests-py/remote_relationship_tests/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@


### Setup ###

The test setup includes two Postgres databases with [sportsdb](https://www.thesportsdb.com/) schema and data, and two GraphQL engines running on the Postgres databases. Then one of the GraphQL engines is added as a remote schema to another GraphQL engine.

The data will be same in both the databases. But the tables will reside in different database schema in-order to avoid GraphQL schema conflicts.

The Python script `test_with_sportsdb.py` will help in setting up the databases, starting the Hasura GraphQL engines, and setting up relationships (both local and remote). This script will run databases on docker, and the GraphQL engines are run with `stack exec`.

#### Setup GraphQL Engines ####
- Install dependencies for the Python script in a virtual environment
```sh
$ python3 -m venv venv
$ source venv/bin/activate
$ pip3 install -r requirements.txt
```
- Inorder to start GraphQL engines with sportsdb, run
```sh
python3 test_with_sportsdb.py
```

This will setup Postgres databases and runs the main and remote GraphQL servers
Pressing enter will teardown both Postgres database

The initial setup will take some time. The subsequent ones will be faster. The Postgres data is bind mounted from a volume in the host, which will be reused.

### Benchmarking ###

We may employ https://github.com/hasura/graphql-bench to do the benchmarks.

Create the `bench.yaml` file
```
- name: events_remote_affilications
warmup_duration: 60
duration: 300
candidates:
- name: hge-with-remote
url: http://127.0.0.1:8081/v1/graphql
query: events_remote_affiliations
queries_file: queries.graphql
rps:
- 20
- 40
```

To run the benchmark, do
```sh
cat bench.yaml | docker run -i --rm --net=host -v $(pwd)/queries.graphql:/graphql-bench/ws/queries.graphql hasura/graphql-bench:v0.3
```
11 changes: 11 additions & 0 deletions server/tests-py/remote_relationship_tests/example-bench.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
- name: events_affilications
warmup_duration: 60
duration: 300
candidates:
- name: hge-with-remote
url: http://127.0.0.1:8081/v1/graphql
query: events_remote_affiliations
queries_file: queries.graphql
rps:
- 20
- 40
27 changes: 27 additions & 0 deletions server/tests-py/remote_relationship_tests/port_allocator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import threading
import socket


class PortAllocator:

def __init__(self):
self.allocated_ports = set()
self.lock = threading.Lock()

def get_unused_port(self, start):
port = start
if self.is_port_open(port) or port in self.allocated_ports:
return self.get_unused_port(port + 1)
else:
return port

def is_port_open(self, port):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
res = sock.connect_ex(('127.0.0.1', port))
return res == 0

def allocate_port(self, start):
with self.lock:
port = self.get_unused_port(start)
self.allocated_ports.add(port)
return port
27 changes: 27 additions & 0 deletions server/tests-py/remote_relationship_tests/queries.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
query events_affiliations {
hge_events(limit: 50){
event_status
last_update
affiliations_events_by_event_id(limit: 2) {
affiliation{
publisher{
publisher_name
}
}
}
}
}

query events_remote_affiliations {
hge_events(limit: 50){
event_status
last_update
remote_affiliations_events_by_event_id(limit: 2) {
affiliation{
publisher{
publisher_name
}
}
}
}
}
5 changes: 5 additions & 0 deletions server/tests-py/remote_relationship_tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
requests-cache
docker
psycopg2
colorama
inflection
Loading