From ca1d5b0c91c7f8d1166cd6f8c169f4cae4781895 Mon Sep 17 00:00:00 2001 From: Raul Marin Date: Thu, 26 Dec 2019 17:46:10 +0100 Subject: [PATCH] Avoid outputting python error messages in regress tests --- scripts-available/CDB_GhostTables.sql | 4 +-- test/CDB_GhostTables.sql | 50 +++++++++++++++++++++++++++ test/CDB_GhostTables_expect | 10 +++--- 3 files changed, 56 insertions(+), 8 deletions(-) diff --git a/scripts-available/CDB_GhostTables.sql b/scripts-available/CDB_GhostTables.sql index 0b72087..3a19242 100644 --- a/scripts-available/CDB_GhostTables.sql +++ b/scripts-available/CDB_GhostTables.sql @@ -32,7 +32,6 @@ AS $$ client = redis.Redis(host=tis_host, port=tis_port, socket_timeout=tis_timeout) GD['invalidation'] = client except Exception as err: - error = "client_error - %s" % str(err) # NOTE: no retries on connection error plpy.warning('Error trying to connect to Invalidation Service to link Ghost Tables: ' + str(err)) break @@ -41,7 +40,6 @@ AS $$ client.execute_command('DBSCH', db_name, username, event_name) break except Exception as err: - error = "request_error - %s" % str(err) client = GD['invalidation'] = None # force reconnect if not tis_retry: plpy.warning('Error calling Invalidation Service to link Ghost Tables: ' + str(err)) @@ -61,7 +59,7 @@ AS $$ EXECUTE 'SELECT current_database();' INTO db_name; PERFORM @extschema@._CDB_LinkGhostTables(username, db_name, event_name); - RAISE NOTICE '_CDB_LinkGhostTables() called with username=%, event_name=%', username, event_name; + RAISE INFO '_CDB_LinkGhostTables() called with username=%, event_name=%', username, event_name; END; $$ LANGUAGE plpgsql VOLATILE diff --git a/test/CDB_GhostTables.sql b/test/CDB_GhostTables.sql index 1741f01..3d3ac93 100644 --- a/test/CDB_GhostTables.sql +++ b/test/CDB_GhostTables.sql @@ -1,6 +1,56 @@ -- Create user and enable Ghost tables trigger \set QUIET on SET client_min_messages TO error; + +-- Recreate the function without extra error messages as it changes depending on the python-redis version +CREATE OR REPLACE FUNCTION cartodb._CDB_LinkGhostTables(username text, db_name text, event_name text) +RETURNS void +AS $$ + if not username: + return + + if 'json' not in GD: + import json + GD['json'] = json + else: + json = GD['json'] + + tis_config = plpy.execute("select cartodb.CDB_Conf_GetConf('invalidation_service');")[0]['cdb_conf_getconf'] + if not tis_config: + plpy.warning('Invalidation service configuration not found. Skipping Ghost Tables linking.') + return + + tis_config_dict = json.loads(tis_config) + tis_host = tis_config_dict.get('host') + tis_port = tis_config_dict.get('port') + tis_timeout = tis_config_dict.get('timeout', 5) + tis_retry = tis_config_dict.get('retry', 5) + + client = GD.get('invalidation', None) + + while True: + + if not client: + try: + import redis + client = redis.Redis(host=tis_host, port=tis_port, socket_timeout=tis_timeout) + GD['invalidation'] = client + except Exception as err: + # NOTE: no retries on connection error + plpy.warning('Error trying to connect to Invalidation Service to link Ghost Tables') + break + + try: + client.execute_command('DBSCH', db_name, username, event_name) + break + except Exception as err: + client = GD['invalidation'] = None # force reconnect + if not tis_retry: + plpy.warning('Error calling Invalidation Service to link Ghost Tables') + break + tis_retry -= 1 # try reconnecting +$$ LANGUAGE '@@plpythonu@@' VOLATILE PARALLEL UNSAFE; + SELECT CDB_EnableGhostTablesTrigger(); CREATE ROLE "fulano" LOGIN; GRANT ALL ON SCHEMA cartodb TO "fulano"; diff --git a/test/CDB_GhostTables_expect b/test/CDB_GhostTables_expect index 469edeb..a5d2aff 100644 --- a/test/CDB_GhostTables_expect +++ b/test/CDB_GhostTables_expect @@ -1,19 +1,19 @@ WARNING: Invalidation service configuration not found. Skipping Ghost Tables linking. -NOTICE: _CDB_LinkGhostTables() called with username=fulanito, event_name=USER +INFO: _CDB_LinkGhostTables() called with username=fulanito, event_name=USER -WARNING: Error calling Invalidation Service to link Ghost Tables: Error -2 connecting to fake-tis-host:3142. Name or service not known. -NOTICE: _CDB_LinkGhostTables() called with username=fulanito, event_name=USER +WARNING: Error calling Invalidation Service to link Ghost Tables +INFO: _CDB_LinkGhostTables() called with username=fulanito, event_name=USER BEGIN cdb_ddl_execution 0 CREATE TABLE 1 -WARNING: Error calling Invalidation Service to link Ghost Tables: Error -2 connecting to fake-tis-host:3142. Name or service not known. -NOTICE: _CDB_LinkGhostTables() called with username=fulanito, event_name=CREATE TABLE +WARNING: Error calling Invalidation Service to link Ghost Tables +INFO: _CDB_LinkGhostTables() called with username=fulanito, event_name=CREATE TABLE COMMIT