Skip to content

Commit ca1d5b0

Browse files
author
Raul Marin
committed
Avoid outputting python error messages in regress tests
1 parent cd62071 commit ca1d5b0

File tree

3 files changed

+56
-8
lines changed

3 files changed

+56
-8
lines changed

scripts-available/CDB_GhostTables.sql

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ AS $$
3232
client = redis.Redis(host=tis_host, port=tis_port, socket_timeout=tis_timeout)
3333
GD['invalidation'] = client
3434
except Exception as err:
35-
error = "client_error - %s" % str(err)
3635
# NOTE: no retries on connection error
3736
plpy.warning('Error trying to connect to Invalidation Service to link Ghost Tables: ' + str(err))
3837
break
@@ -41,7 +40,6 @@ AS $$
4140
client.execute_command('DBSCH', db_name, username, event_name)
4241
break
4342
except Exception as err:
44-
error = "request_error - %s" % str(err)
4543
client = GD['invalidation'] = None # force reconnect
4644
if not tis_retry:
4745
plpy.warning('Error calling Invalidation Service to link Ghost Tables: ' + str(err))
@@ -61,7 +59,7 @@ AS $$
6159
EXECUTE 'SELECT current_database();' INTO db_name;
6260

6361
PERFORM @extschema@._CDB_LinkGhostTables(username, db_name, event_name);
64-
RAISE NOTICE '_CDB_LinkGhostTables() called with username=%, event_name=%', username, event_name;
62+
RAISE INFO '_CDB_LinkGhostTables() called with username=%, event_name=%', username, event_name;
6563
END;
6664
$$ LANGUAGE plpgsql
6765
VOLATILE

test/CDB_GhostTables.sql

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,56 @@
11
-- Create user and enable Ghost tables trigger
22
\set QUIET on
33
SET client_min_messages TO error;
4+
5+
-- Recreate the function without extra error messages as it changes depending on the python-redis version
6+
CREATE OR REPLACE FUNCTION cartodb._CDB_LinkGhostTables(username text, db_name text, event_name text)
7+
RETURNS void
8+
AS $$
9+
if not username:
10+
return
11+
12+
if 'json' not in GD:
13+
import json
14+
GD['json'] = json
15+
else:
16+
json = GD['json']
17+
18+
tis_config = plpy.execute("select cartodb.CDB_Conf_GetConf('invalidation_service');")[0]['cdb_conf_getconf']
19+
if not tis_config:
20+
plpy.warning('Invalidation service configuration not found. Skipping Ghost Tables linking.')
21+
return
22+
23+
tis_config_dict = json.loads(tis_config)
24+
tis_host = tis_config_dict.get('host')
25+
tis_port = tis_config_dict.get('port')
26+
tis_timeout = tis_config_dict.get('timeout', 5)
27+
tis_retry = tis_config_dict.get('retry', 5)
28+
29+
client = GD.get('invalidation', None)
30+
31+
while True:
32+
33+
if not client:
34+
try:
35+
import redis
36+
client = redis.Redis(host=tis_host, port=tis_port, socket_timeout=tis_timeout)
37+
GD['invalidation'] = client
38+
except Exception as err:
39+
# NOTE: no retries on connection error
40+
plpy.warning('Error trying to connect to Invalidation Service to link Ghost Tables')
41+
break
42+
43+
try:
44+
client.execute_command('DBSCH', db_name, username, event_name)
45+
break
46+
except Exception as err:
47+
client = GD['invalidation'] = None # force reconnect
48+
if not tis_retry:
49+
plpy.warning('Error calling Invalidation Service to link Ghost Tables')
50+
break
51+
tis_retry -= 1 # try reconnecting
52+
$$ LANGUAGE '@@plpythonu@@' VOLATILE PARALLEL UNSAFE;
53+
454
SELECT CDB_EnableGhostTablesTrigger();
555
CREATE ROLE "fulano" LOGIN;
656
GRANT ALL ON SCHEMA cartodb TO "fulano";

test/CDB_GhostTables_expect

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11

22

33
WARNING: Invalidation service configuration not found. Skipping Ghost Tables linking.
4-
NOTICE: _CDB_LinkGhostTables() called with username=fulanito, event_name=USER
4+
INFO: _CDB_LinkGhostTables() called with username=fulanito, event_name=USER
55

66

7-
WARNING: Error calling Invalidation Service to link Ghost Tables: Error -2 connecting to fake-tis-host:3142. Name or service not known.
8-
NOTICE: _CDB_LinkGhostTables() called with username=fulanito, event_name=USER
7+
WARNING: Error calling Invalidation Service to link Ghost Tables
8+
INFO: _CDB_LinkGhostTables() called with username=fulanito, event_name=USER
99

1010
BEGIN
1111
cdb_ddl_execution
1212
0
1313
CREATE TABLE
1414
1
15-
WARNING: Error calling Invalidation Service to link Ghost Tables: Error -2 connecting to fake-tis-host:3142. Name or service not known.
16-
NOTICE: _CDB_LinkGhostTables() called with username=fulanito, event_name=CREATE TABLE
15+
WARNING: Error calling Invalidation Service to link Ghost Tables
16+
INFO: _CDB_LinkGhostTables() called with username=fulanito, event_name=CREATE TABLE
1717
COMMIT
1818

1919

0 commit comments

Comments
 (0)