Adapt QuotaTest to avoid randoms

This commit is contained in:
Raul Marin
2019-10-23 16:49:57 +02:00
parent 29397ff929
commit 021c7318a3
2 changed files with 18 additions and 14 deletions
+15 -12
View File
@@ -1,30 +1,33 @@
set client_min_messages to error; set client_min_messages to error;
\set VERBOSITY TERSE \set VERBOSITY TERSE
-- See the dice
SELECT setseed(0.5);
CREATE TABLE big(a int); CREATE TABLE big(a int);
-- Try the legacy interface -- Try the legacy interface
-- See https://github.com/CartoDB/cartodb-postgresql/issues/13 -- See https://github.com/CartoDB/cartodb-postgresql/issues/13
CREATE TRIGGER test_quota BEFORE UPDATE OR INSERT ON big CREATE TRIGGER test_quota BEFORE UPDATE OR INSERT ON big
EXECUTE PROCEDURE CDB_CheckQuota(1, 1, 'public'); EXECUTE PROCEDURE cartodb.CDB_CheckQuota(2, 1, 'public');
INSERT INTO big VALUES (1); -- allowed, check runs before INSERT INTO big VALUES (1); -- allowed, check runs before
INSERT INTO big VALUES (2); -- disallowed, quota exceeds before INSERT INTO big VALUES (2); -- disallowed, quota exceeds before
SELECT CDB_SetUserQuotaInBytes(0); SELECT cartodb.CDB_SetUserQuotaInBytes(0);
SELECT CDB_CartodbfyTable('big'); SELECT cartodb.CDB_CartodbfyTable('big');
-- Creating the trigger should fail as it was created by CDB_CartodbfyTable
CREATE TRIGGER test_quota BEFORE UPDATE OR INSERT ON big
EXECUTE PROCEDURE cartodb.CDB_CheckQuota(2, 1, 'public');
-- Drop the trigger and recreate it forcing a 100% checks
DROP TRIGGER test_quota ON big;
CREATE TRIGGER test_quota BEFORE UPDATE OR INSERT ON big
EXECUTE PROCEDURE cartodb.CDB_CheckQuota(2, 1, 'public');
INSERT INTO big SELECT generate_series(2049,4096); INSERT INTO big SELECT generate_series(2049,4096);
INSERT INTO big SELECT generate_series(4097,6144); INSERT INTO big SELECT generate_series(4097,6144);
INSERT INTO big SELECT generate_series(6145,8192); INSERT INTO big SELECT generate_series(6145,8192);
-- Test for #108: https://github.com/CartoDB/cartodb-postgresql/issues/108 -- Test for #108: https://github.com/CartoDB/cartodb-postgresql/issues/108
SELECT CDB_UserDataSize(); SELECT cartodb.CDB_UserDataSize();
SELECT cartodb._CDB_total_relation_size('public', 'big'); SELECT cartodb._CDB_total_relation_size('public', 'big');
SELECT cartodb._CDB_total_relation_size('public', 'nonexistent_table_name'); SELECT cartodb._CDB_total_relation_size('public', 'nonexistent_table_name');
-- END Test for #108 -- END Test for #108
SELECT setseed(0.9); SELECT cartodb.CDB_SetUserQuotaInBytes(2);
SELECT CDB_SetUserQuotaInBytes(2);
INSERT INTO big VALUES (8193); INSERT INTO big VALUES (8193);
SELECT CDB_SetUserQuotaInBytes(0); SELECT cartodb.CDB_SetUserQuotaInBytes(0);
INSERT INTO big VALUES (8194); INSERT INTO big VALUES (8194);
DROP TABLE big; DROP TABLE big;
@@ -32,8 +35,8 @@ DROP TABLE big;
--analysis tables should be excluded from quota: --analysis tables should be excluded from quota:
CREATE TABLE big(a int); CREATE TABLE big(a int);
CREATE TRIGGER test_quota BEFORE UPDATE OR INSERT ON big CREATE TRIGGER test_quota BEFORE UPDATE OR INSERT ON big
EXECUTE PROCEDURE CDB_CheckQuota(1, 1, 'public'); EXECUTE PROCEDURE cartodb.CDB_CheckQuota(2, 1, 'public');
SELECT CDB_SetUserQuotaInBytes(1); SELECT cartodb.CDB_SetUserQuotaInBytes(1);
CREATE TABLE analysis_2f13a3dbd7_41bd92976fc6dd97072afe4ee450054f4c0715d4(id int); CREATE TABLE analysis_2f13a3dbd7_41bd92976fc6dd97072afe4ee450054f4c0715d4(id int);
INSERT INTO analysis_2f13a3dbd7_41bd92976fc6dd97072afe4ee450054f4c0715d4(id) VALUES (1),(2),(3),(4),(5); INSERT INTO analysis_2f13a3dbd7_41bd92976fc6dd97072afe4ee450054f4c0715d4(id) VALUES (1),(2),(3),(4),(5);
INSERT INTO big VALUES (1); -- allowed, check runs before INSERT INTO big VALUES (1); -- allowed, check runs before
+3 -2
View File
@@ -1,18 +1,19 @@
SET SET
CREATE TABLE CREATE TABLE
CREATE TRIGGER CREATE TRIGGER
INSERT 0 1 INSERT 0 1
ERROR: Quota exceeded by 3.9990234375KB ERROR: Quota exceeded by 3.9990234375KB
0 0
big big
ERROR: trigger "test_quota" for relation "big" already exists
DROP TRIGGER
CREATE TRIGGER
INSERT 0 2048 INSERT 0 2048
INSERT 0 2048 INSERT 0 2048
INSERT 0 2048 INSERT 0 2048
454656 454656
909312 909312
0 0
2 2
ERROR: Quota exceeded by 443.998046875KB ERROR: Quota exceeded by 443.998046875KB
0 0