From f89a743a71876c810dfa139958dff51d6af5936f Mon Sep 17 00:00:00 2001 From: Sasha Romijn Date: Tue, 11 Jul 2023 16:27:32 +0200 Subject: [PATCH] try testing tx q --- .circleci/config.yml | 1 + irrd/storage/database_handler.py | 10 +++++++++- irrd/storage/tests/test_database.py | 3 +++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2b3947cd9..7d9339b2c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -197,6 +197,7 @@ jobs: POSTGRES_USER: root POSTGRES_DB: circle_test POSTGRES_HOST_AUTH_METHOD: trust + command: postgres -c track_commit_timestamp=true - image: cimg/redis:<< parameters.redis_version >> # - image: cimg/rust:1.65 diff --git a/irrd/storage/database_handler.py b/irrd/storage/database_handler.py index 26d37ec2e..b48a0adb6 100644 --- a/irrd/storage/database_handler.py +++ b/irrd/storage/database_handler.py @@ -586,7 +586,7 @@ def delete_rpsl_object( table.c.prefix, table.c.object_text, ) - results = self._connection.execute(stmt) + results = self.execute_statement(stmt) if not self._check_single_row_match(results, user_identifier=f"{rpsl_pk}/{source}"): return None @@ -817,6 +817,14 @@ def set_force_reload(self, source): "current settings, actual reload process wll take place in next scheduled importer run" ) + def timestamp_last_committed_transaction(self) -> datetime: + result = self.execute_statement("SELECT timestamp FROM pg_last_committed_xact()") + row = result.fetchone() + print(row) + print(type(row['timestamp'])) + raise(Exception(row)) + return datetime.fromisoformat(result.fetchone()['timestamp']) + def record_serial_newest_mirror(self, source: str, serial: int) -> None: """ Record that a mirror was updated to a certain serial. diff --git a/irrd/storage/tests/test_database.py b/irrd/storage/tests/test_database.py index e2d24b674..b7ac5eb70 100644 --- a/irrd/storage/tests/test_database.py +++ b/irrd/storage/tests/test_database.py @@ -215,6 +215,7 @@ def test_object_writing_and_status_checking(self, monkeypatch, irrd_db_mock_prel self.dh.upsert_rpsl_object(rpsl_object_route_v6, JournalEntryOrigin.auth_change, source_serial=43) self.dh.commit() + initial_tx_timestamp = self.dh.timestamp_last_committed_transaction() self.dh.refresh_connection() # There should be two entries with MNT-CORRECT in the db now. @@ -442,6 +443,8 @@ def test_object_writing_and_status_checking(self, monkeypatch, irrd_db_mock_prel assert not len(list(self.dh.execute_query(DatabaseStatusQuery().sources(["TEST"])))) assert len(list(self.dh.execute_query(RPSLDatabaseQuery().sources(["TEST2"])))) == 1 + assert self.dh.timestamp_last_committed_transaction() > initial_tx_timestamp + self.dh.close() assert flatten_mock_calls(self.dh.changed_objects_tracker.preloader.signal_reload) == [