Skip to content

Commit

Permalink
Add retry loops and bump test timeout in test_pageserver_connection_s…
Browse files Browse the repository at this point in the history
…tress (#7281)
  • Loading branch information
save-buffer committed May 2, 2024
1 parent 5558457 commit d43d773
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions test_runner/regress/test_bad_connection.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import random
import time

import psycopg2.errors
import pytest
from fixtures.log_helper import log
from fixtures.neon_fixtures import NeonEnvBuilder


@pytest.mark.timeout(600)
def test_compute_pageserver_connection_stress(neon_env_builder: NeonEnvBuilder):
env = neon_env_builder.init_start()
env.pageserver.allowed_errors.append(".*simulated connection error.*")
Expand All @@ -20,12 +23,20 @@ def test_compute_pageserver_connection_stress(neon_env_builder: NeonEnvBuilder):
pg_conn = endpoint.connect()
cur = pg_conn.cursor()

def execute_retry_on_timeout(query):
while True:
try:
cur.execute(query)
return
except psycopg2.errors.QueryCanceled:
log.info(f"Query '{query}' timed out - retrying")

# Create table, and insert some rows. Make it big enough that it doesn't fit in
# shared_buffers, otherwise the SELECT after restart will just return answer
# from shared_buffers without hitting the page server, which defeats the point
# of this test.
cur.execute("CREATE TABLE foo (t text)")
cur.execute(
execute_retry_on_timeout("CREATE TABLE foo (t text)")
execute_retry_on_timeout(
"""
INSERT INTO foo
SELECT 'long string to consume some space' || g
Expand All @@ -34,7 +45,7 @@ def test_compute_pageserver_connection_stress(neon_env_builder: NeonEnvBuilder):
)

# Verify that the table is larger than shared_buffers
cur.execute(
execute_retry_on_timeout(
"""
select setting::int * pg_size_bytes(unit) as shared_buffers, pg_relation_size('foo') as tbl_size
from pg_settings where name = 'shared_buffers'
Expand All @@ -45,16 +56,16 @@ def test_compute_pageserver_connection_stress(neon_env_builder: NeonEnvBuilder):
log.info(f"shared_buffers is {row[0]}, table size {row[1]}")
assert int(row[0]) < int(row[1])

cur.execute("SELECT count(*) FROM foo")
execute_retry_on_timeout("SELECT count(*) FROM foo")
assert cur.fetchone() == (100000,)

end_time = time.time() + 30
times_executed = 0
while time.time() < end_time:
if random.random() < 0.5:
cur.execute("INSERT INTO foo VALUES ('stas'), ('heikki')")
execute_retry_on_timeout("INSERT INTO foo VALUES ('stas'), ('heikki')")
else:
cur.execute("SELECT t FROM foo ORDER BY RANDOM() LIMIT 10")
execute_retry_on_timeout("SELECT t FROM foo ORDER BY RANDOM() LIMIT 10")
cur.fetchall()
times_executed += 1
log.info(f"Workload executed {times_executed} times")

1 comment on commit d43d773

@github-actions
Copy link

Choose a reason for hiding this comment

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

2937 tests run: 2803 passed, 0 failed, 134 skipped (full report)


Flaky tests (2)

Postgres 16

  • test_fully_custom_config: debug

Postgres 14

  • test_vm_bit_clear_on_heap_lock: debug

Code coverage* (full report)

  • functions: 28.0% (6601 of 23537 functions)
  • lines: 46.7% (46858 of 100326 lines)

* collected from Rust tests only


The comment gets automatically updated with the latest test results
d43d773 at 2024-05-02T06:12:29.002Z :recycle:

Please sign in to comment.