Skip to content

Commit def483b

Browse files
authored
Fix an issue in psycopg2 contract test that cause random run fail (#112)
*Issue #, if available:* A racing condition on trace queue that may not be able to clean on time in some condition *Description of changes:* Fix an issue in psycopg2 contract test that cause random run fail By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
1 parent 94822d9 commit def483b

File tree

2 files changed

+3
-30
lines changed

2 files changed

+3
-30
lines changed

contract-tests/images/applications/psycopg2/psycopg2_server.py

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,6 @@
2020
_DB_NAME = os.getenv("DB_NAME")
2121

2222

23-
def prepare_database() -> None:
24-
conn = psycopg2.connect(dbname=_DB_NAME, user=_DB_USER, password=_DB_PASS, host=_DB_HOST)
25-
cur = conn.cursor()
26-
cur.execute("DROP TABLE IF EXISTS test_table")
27-
cur.execute(
28-
"""
29-
CREATE TABLE test_table (
30-
id SERIAL PRIMARY KEY,
31-
name TEXT NOT NULL
32-
)
33-
"""
34-
)
35-
36-
cur.execute("INSERT INTO test_table (name) VALUES (%s)", ("Alice",))
37-
cur.execute("INSERT INTO test_table (name) VALUES (%s)", ("Bob",))
38-
39-
conn.commit()
40-
41-
cur.close()
42-
conn.close()
43-
44-
4523
class RequestHandler(BaseHTTPRequestHandler):
4624
@override
4725
# pylint: disable=invalid-name
@@ -50,13 +28,9 @@ def do_GET(self):
5028
conn = psycopg2.connect(dbname=_DB_NAME, user=_DB_USER, password=_DB_PASS, host=_DB_HOST)
5129
if self.in_path(_SUCCESS):
5230
cur = conn.cursor()
53-
cur.execute("SELECT id, name FROM test_table")
54-
rows = cur.fetchall()
31+
cur.execute("DROP TABLE IF EXISTS test_table")
5532
cur.close()
56-
if len(rows) == 2:
57-
status_code = 200
58-
else:
59-
status_code = 400
33+
status_code = 200
6034
elif self.in_path(_FAULT):
6135
cur = conn.cursor()
6236
try:
@@ -81,7 +55,6 @@ def in_path(self, sub_path: str):
8155

8256

8357
def main() -> None:
84-
prepare_database()
8558
server_address: Tuple[str, int] = ("0.0.0.0", _PORT)
8659
request_handler_class: type = RequestHandler
8760
requests_server: ThreadingHTTPServer = ThreadingHTTPServer(server_address, request_handler_class)

contract-tests/tests/test/amazon/psycopg2/psycopg2_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def get_application_image_name(self) -> str:
5151

5252
def test_success(self) -> None:
5353
self.mock_collector_client.clear_signals()
54-
self.do_test_requests("success", "GET", 200, 0, 0, sql_command="SELECT")
54+
self.do_test_requests("success", "GET", 200, 0, 0, sql_command="DROP TABLE")
5555

5656
def test_fault(self) -> None:
5757
self.mock_collector_client.clear_signals()

0 commit comments

Comments
 (0)