Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
5 changes: 1 addition & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys
import os

# If extensions (or modules to document with autodoc) are in another directory,
Expand Down Expand Up @@ -292,9 +291,7 @@ def setup(app):
app.add_css_file("css/custom.css")


user_agent = (
"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:135.0) Gecko/20100101 Firefox/135.0"
)
user_agent = "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:135.0) Gecko/20100101 Firefox/135.0"

linkcheck_ignore = [
# 403 only in CI / GitHub Actions
Expand Down
18 changes: 9 additions & 9 deletions nix/tools/generate_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@
# - the above guarantees JWT cache purging will happen
# - we want this to track resource consumption in the worst case

import argparse
import random
import sys

# And a more normal scenario where non-expiring JWTs are picked
# from an array
import time
import argparse
import sys
import random
import jwt
import jwcrypto.jwk as jwk
from typing import Optional
from pathlib import Path
from typing import Optional

import jwcrypto.jwk as jwk
import jwt

URL = "http://postgrest"

Expand Down Expand Up @@ -51,9 +53,7 @@ def append_targets(lines: list[str], token: str):


def main():
parser = argparse.ArgumentParser(
description="Generate Vegeta targets with unique JWTs"
)
parser = argparse.ArgumentParser(description="Generate Vegeta targets with unique JWTs")
parser.add_argument(
"output",
help="Path to write the generated targets file",
Expand Down
1 change: 1 addition & 0 deletions nix/tools/merge_monitor_result.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import sys

import pandas as pd

KEY = "Elapsed seconds"
Expand Down
3 changes: 2 additions & 1 deletion nix/tools/monitor_pid.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Monitor a process pid with psutil and emits a CSV.
import sys
import time
import psutil

import pandas as pd
import psutil

KEY = "Elapsed seconds"
BASE_METRICS = ["CPU (%)", "Real (MB)"]
Expand Down
4 changes: 2 additions & 2 deletions test/io/config.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import os
import pathlib
import shutil
import pytest
import uuid
import yaml

import pytest
import yaml

BASEDIR = pathlib.Path(os.path.realpath(__file__)).parent
CONFIGSDIR = BASEDIR / "configs"
Expand Down
13 changes: 4 additions & 9 deletions test/io/postgrest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
import pytest
import requests
import requests_unixsocket

from config import *
from config import POSTGREST_BIN, hpctixfile


def sleep_until_postgrest_scache_reload():
Expand Down Expand Up @@ -75,9 +74,7 @@ def read_stdout(self, nlines=1):
def wait_until_scache_starts_loading(self, max_seconds=1):
"Wait for the admin /ready return a status of 503"

wait_until_status_code(
self.admin.baseurl + "/ready", max_seconds=max_seconds, status_code=503
)
wait_until_status_code(self.admin.baseurl + "/ready", max_seconds=max_seconds, status_code=503)


@contextlib.contextmanager
Expand Down Expand Up @@ -153,7 +150,7 @@ def run(
process.terminate()
try:
process.wait(timeout=1)
except:
except subprocess.TimeoutExpired:
process.kill()
process.wait()

Expand Down Expand Up @@ -239,9 +236,7 @@ def set_statement_timeout(postgrest, role, milliseconds):
For this to work reliably with low previous timeout settings,
use a postgrest instance that doesn't use the affected role."""

response = postgrest.session.post(
"/rpc/set_statement_timeout", data={"role": role, "milliseconds": milliseconds}
)
response = postgrest.session.post("/rpc/set_statement_timeout", data={"role": role, "milliseconds": milliseconds})
assert response.text == ""
assert response.status_code == 204

Expand Down
13 changes: 4 additions & 9 deletions test/io/test_big_schema.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"IO tests for PostgREST started on the big schema."

import pytest
from util import parse_server_timings_header

from config import *
from util import *
from postgrest import *
from postgrest import run


def test_requests_with_resource_embedding_wait_for_schema_cache_reload(defaultenv):
Expand All @@ -28,9 +27,7 @@ def test_requests_with_resource_embedding_wait_for_schema_cache_reload(defaulten
response = postgrest.session.get("/tpopmassn?select=*,tpop(*)")
assert response.status_code == 200

plan_dur = parse_server_timings_header(response.headers["Server-Timing"])[
"plan"
]
plan_dur = parse_server_timings_header(response.headers["Server-Timing"])["plan"]
assert plan_dur > 10000.0


Expand All @@ -55,9 +52,7 @@ def test_requests_without_resource_embedding_wait_for_schema_cache_reload(defaul
response = postgrest.session.get("/tpopmassn")
assert response.status_code == 200

plan_dur = parse_server_timings_header(response.headers["Server-Timing"])[
"plan"
]
plan_dur = parse_server_timings_header(response.headers["Server-Timing"])["plan"]
assert plan_dur < 10000.0


Expand Down
27 changes: 9 additions & 18 deletions test/io/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
"Unit tests for Input/Ouput of PostgREST seen as a black box."

from operator import attrgetter
import signal
import subprocess
from operator import attrgetter

import pytest
from syrupy.extensions.json import SingleFileSnapshotExtension
import yaml
from config import CONFIGSDIR, FIXTURES, POSTGREST_BIN, get_admin_host_and_port_from_config, hpctixfile
from syrupy.extensions.json import SingleFileSnapshotExtension

from config import *
from postgrest import *
from postgrest import freeport, is_ipv6, run, set_statement_timeout


class ExtraNewLinesDumper(yaml.SafeDumper):
Expand Down Expand Up @@ -69,15 +70,11 @@ def cli(args, env=None, stdin=None, expect_error=False):
(stdout_output, stderr_output) = process.communicate(timeout=5)
if expect_error: # When expected to fail, return stderr, else stdout
if process.returncode == 0:
raise PostgrestError(
"PostgREST unexpectedly exited with return code zero."
)
raise PostgrestError("PostgREST unexpectedly exited with return code zero.")
return stderr_output.decode()
else:
if process.returncode != 0:
raise PostgrestError(
"PostgREST unexpectedly exited with non-zero return code."
)
raise PostgrestError("PostgREST unexpectedly exited with non-zero return code.")
return stdout_output.decode()
finally:
process.kill()
Expand Down Expand Up @@ -349,10 +346,7 @@ def test_cli_ready_flag_fail_with_http_exception(defaultenv):
output = cli(["--ready"], env=postgrest.config, expect_error=True)
(admin_host, admin_port) = get_admin_host_and_port_from_config(postgrest.config)

assert (
f"ERROR: connection refused to http://{admin_host}:{admin_port}/ready"
in output
)
assert f"ERROR: connection refused to http://{admin_host}:{admin_port}/ready" in output

# When client sends the request to invalid URL
with run(env=defaultenv, port=port) as postgrest:
Expand Down Expand Up @@ -386,7 +380,4 @@ def test_cli_ready_flag_fail_when_no_admin_server(defaultenv):
postgrest.config["PGRST_ADMIN_SERVER_PORT"] = ""
output = cli(["--ready"], env=postgrest.config, expect_error=True)

assert (
"ERROR: Admin server is not running. Please check admin-server-port config."
in output
)
assert "ERROR: Admin server is not running. Please check admin-server-port config." in output
Loading
Loading