Regress tests to improve the function coverage of schemacmds and user and tablespace files

Started by Haribabu kommiabout 12 years ago6 messages
#1Haribabu kommi
haribabu.kommi@huawei.com
2 attachment(s)

Here I have added some more regression tests to improve the missing function coverage of
schemacmds.c, user.c and tablespace.c.

The added tests are mainly RENAME TO and OWNER TO support.

patches are attached in the mail.
please check and provide your suggestions.

Regards,
Hari babu.

Attachments:

schema_user_v1.patchapplication/octet-stream; name=schema_user_v1.patchDownload
diff --git a/src/test/regress/expected/namespace.out b/src/test/regress/expected/namespace.out
index 9187c81..b0cdd65 100644
--- a/src/test/regress/expected/namespace.out
+++ b/src/test/regress/expected/namespace.out
@@ -36,12 +36,20 @@ SELECT * FROM test_schema_1.abc_view;
  4 |  
 (3 rows)
 
+ALTER SCHEMA test_schema_1 RENAME TO test_schema_renamed;
+SELECT COUNT(*) FROM pg_class WHERE relnamespace =
+    (SELECT oid FROM pg_namespace WHERE nspname = 'test_schema_1');
+ count 
+-------
+     0
+(1 row)
+
 -- test IF NOT EXISTS cases
-CREATE SCHEMA test_schema_1; -- fail, already exists
-ERROR:  schema "test_schema_1" already exists
-CREATE SCHEMA IF NOT EXISTS test_schema_1; -- ok with notice
-NOTICE:  schema "test_schema_1" already exists, skipping
-CREATE SCHEMA IF NOT EXISTS test_schema_1 -- fail, disallowed
+CREATE SCHEMA test_schema_renamed; -- fail, already exists
+ERROR:  schema "test_schema_renamed" already exists
+CREATE SCHEMA IF NOT EXISTS test_schema_renamed; -- ok with notice
+NOTICE:  schema "test_schema_renamed" already exists, skipping
+CREATE SCHEMA IF NOT EXISTS test_schema_renamed -- fail, disallowed
        CREATE TABLE abc (
               a serial,
               b int UNIQUE
@@ -49,13 +57,13 @@ CREATE SCHEMA IF NOT EXISTS test_schema_1 -- fail, disallowed
 ERROR:  CREATE SCHEMA IF NOT EXISTS cannot include schema elements
 LINE 2:        CREATE TABLE abc (
                ^
-DROP SCHEMA test_schema_1 CASCADE;
+DROP SCHEMA test_schema_renamed CASCADE;
 NOTICE:  drop cascades to 2 other objects
-DETAIL:  drop cascades to table test_schema_1.abc
-drop cascades to view test_schema_1.abc_view
+DETAIL:  drop cascades to table test_schema_renamed.abc
+drop cascades to view test_schema_renamed.abc_view
 -- verify that the objects were dropped
 SELECT COUNT(*) FROM pg_class WHERE relnamespace =
-    (SELECT oid FROM pg_namespace WHERE nspname = 'test_schema_1');
+    (SELECT oid FROM pg_namespace WHERE nspname = 'test_schema_renamed');
  count 
 -------
      0
diff --git a/src/test/regress/expected/privileges.out b/src/test/regress/expected/privileges.out
index 3da03fc..5543ce8 100644
--- a/src/test/regress/expected/privileges.out
+++ b/src/test/regress/expected/privileges.out
@@ -1350,6 +1350,34 @@ SELECT has_function_privilege('regressuser1', 'testns.testfunc(int)', 'EXECUTE')
 SET client_min_messages TO 'warning';
 DROP SCHEMA testns CASCADE;
 RESET client_min_messages;
+-- Change owner of the schema & and rename of new schema owner
+\c -
+CREATE ROLE schemauser1 superuser login;
+CREATE ROLE schemauser2 superuser login;
+SET SESSION ROLE schemauser1;
+CREATE SCHEMA testns;
+SELECT nspname, rolname FROM pg_namespace, pg_roles WHERE pg_namespace.nspname = 'testns' AND pg_namespace.nspowner = pg_roles.oid;
+ nspname |   rolname   
+---------+-------------
+ testns  | schemauser1
+(1 row)
+
+ALTER SCHEMA testns OWNER TO schemauser2;
+ALTER ROLE schemauser2 RENAME TO schemauser_renamed;
+SELECT nspname, rolname FROM pg_namespace, pg_roles WHERE pg_namespace.nspname = 'testns' AND pg_namespace.nspowner = pg_roles.oid;
+ nspname |      rolname       
+---------+--------------------
+ testns  | schemauser_renamed
+(1 row)
+
+set session role schemauser_renamed;
+SET client_min_messages TO 'warning';
+DROP SCHEMA testns CASCADE;
+RESET client_min_messages;
+-- clean up
+\c - 
+DROP ROLE schemauser1;
+DROP ROLE schemauser_renamed;
 -- test that dependent privileges are revoked (or not) properly
 \c -
 set session role regressuser1;
diff --git a/src/test/regress/sql/namespace.sql b/src/test/regress/sql/namespace.sql
index 879b6c3..51cb091 100644
--- a/src/test/regress/sql/namespace.sql
+++ b/src/test/regress/sql/namespace.sql
@@ -24,17 +24,21 @@ INSERT INTO test_schema_1.abc DEFAULT VALUES;
 SELECT * FROM test_schema_1.abc;
 SELECT * FROM test_schema_1.abc_view;
 
+ALTER SCHEMA test_schema_1 RENAME TO test_schema_renamed;
+SELECT COUNT(*) FROM pg_class WHERE relnamespace =
+    (SELECT oid FROM pg_namespace WHERE nspname = 'test_schema_1');
+
 -- test IF NOT EXISTS cases
-CREATE SCHEMA test_schema_1; -- fail, already exists
-CREATE SCHEMA IF NOT EXISTS test_schema_1; -- ok with notice
-CREATE SCHEMA IF NOT EXISTS test_schema_1 -- fail, disallowed
+CREATE SCHEMA test_schema_renamed; -- fail, already exists
+CREATE SCHEMA IF NOT EXISTS test_schema_renamed; -- ok with notice
+CREATE SCHEMA IF NOT EXISTS test_schema_renamed -- fail, disallowed
        CREATE TABLE abc (
               a serial,
               b int UNIQUE
        );
 
-DROP SCHEMA test_schema_1 CASCADE;
+DROP SCHEMA test_schema_renamed CASCADE;
 
 -- verify that the objects were dropped
 SELECT COUNT(*) FROM pg_class WHERE relnamespace =
-    (SELECT oid FROM pg_namespace WHERE nspname = 'test_schema_1');
+    (SELECT oid FROM pg_namespace WHERE nspname = 'test_schema_renamed');
diff --git a/src/test/regress/sql/privileges.sql b/src/test/regress/sql/privileges.sql
index cb993ae..d82129b 100644
--- a/src/test/regress/sql/privileges.sql
+++ b/src/test/regress/sql/privileges.sql
@@ -813,6 +813,33 @@ DROP SCHEMA testns CASCADE;
 RESET client_min_messages;
 
 
+-- Change owner of the schema & and rename of new schema owner
+\c -
+
+CREATE ROLE schemauser1 superuser login;
+CREATE ROLE schemauser2 superuser login;
+
+SET SESSION ROLE schemauser1;
+CREATE SCHEMA testns;
+
+SELECT nspname, rolname FROM pg_namespace, pg_roles WHERE pg_namespace.nspname = 'testns' AND pg_namespace.nspowner = pg_roles.oid;
+
+ALTER SCHEMA testns OWNER TO schemauser2;
+ALTER ROLE schemauser2 RENAME TO schemauser_renamed;
+SELECT nspname, rolname FROM pg_namespace, pg_roles WHERE pg_namespace.nspname = 'testns' AND pg_namespace.nspowner = pg_roles.oid;
+
+set session role schemauser_renamed;
+SET client_min_messages TO 'warning';
+DROP SCHEMA testns CASCADE;
+RESET client_min_messages;
+
+-- clean up
+\c - 
+
+DROP ROLE schemauser1;
+DROP ROLE schemauser_renamed;
+
+
 -- test that dependent privileges are revoked (or not) properly
 \c -
 
tablespace_v1.patchapplication/octet-stream; name=tablespace_v1.patchDownload
diff --git a/src/test/regress/input/tablespace.source b/src/test/regress/input/tablespace.source
index dba96f4..4f17b09 100644
--- a/src/test/regress/input/tablespace.source
+++ b/src/test/regress/input/tablespace.source
@@ -54,7 +54,22 @@ CREATE TABLE bar (i int) TABLESPACE nosuchspace;
 -- Fail, not empty
 DROP TABLESPACE testspace;
 
+CREATE ROLE tablespace_testuser1 login;
+CREATE ROLE tablespace_testuser2 login;
+
+ALTER TABLESPACE testspace OWNER TO tablespace_testuser1;
+
+SET SESSION ROLE tablespace_testuser2;
+CREATE TABLE tablespace_table (i int) TABLESPACE testspace; -- fail
+
+\c -
+
+ALTER TABLESPACE testspace RENAME TO testspace_renamed;
+
 DROP SCHEMA testschema CASCADE;
 
 -- Should succeed
-DROP TABLESPACE testspace;
+DROP TABLESPACE testspace_renamed;
+
+DROP ROLE tablespace_testuser1;
+DROP ROLE tablespace_testuser2;
diff --git a/src/test/regress/output/tablespace.source b/src/test/regress/output/tablespace.source
index 1260c96..2868169 100644
--- a/src/test/regress/output/tablespace.source
+++ b/src/test/regress/output/tablespace.source
@@ -72,6 +72,14 @@ ERROR:  tablespace "nosuchspace" does not exist
 -- Fail, not empty
 DROP TABLESPACE testspace;
 ERROR:  tablespace "testspace" is not empty
+CREATE ROLE tablespace_testuser1 login;
+CREATE ROLE tablespace_testuser2 login;
+ALTER TABLESPACE testspace OWNER TO tablespace_testuser1;
+SET SESSION ROLE tablespace_testuser2;
+CREATE TABLE tablespace_table (i int) TABLESPACE testspace; -- fail
+ERROR:  permission denied for tablespace testspace
+\c -
+ALTER TABLESPACE testspace RENAME TO testspace_renamed;
 DROP SCHEMA testschema CASCADE;
 NOTICE:  drop cascades to 4 other objects
 DETAIL:  drop cascades to table testschema.foo
@@ -79,4 +87,6 @@ drop cascades to table testschema.asselect
 drop cascades to table testschema.asexecute
 drop cascades to table testschema.atable
 -- Should succeed
-DROP TABLESPACE testspace;
+DROP TABLESPACE testspace_renamed;
+DROP ROLE tablespace_testuser1;
+DROP ROLE tablespace_testuser2;
#2Michael Paquier
michael.paquier@gmail.com
In reply to: Haribabu kommi (#1)
Re: Regress tests to improve the function coverage of schemacmds and user and tablespace files

Hi,

On Thu, Oct 24, 2013 at 5:59 PM, Haribabu kommi
<haribabu.kommi@huawei.com> wrote:

Here I have added some more regression tests to improve the missing function
coverage of schemacmds.c, user.c and tablespace.c.
The added tests are mainly RENAME TO and OWNER TO support.

Could you add those patches to the next commitfest such as they don't
get lost in the flow?
Here is a URL to it:
https://commitfest.postgresql.org/action/commitfest_view?id=20
Note that you will need a community account to register your patches.

Thanks,
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#3David Rowley
dgrowleyml@gmail.com
In reply to: Haribabu kommi (#1)
Re: Regress tests to improve the function coverage of schemacmds and user and tablespace files

On Thu, Oct 24, 2013 at 9:59 PM, Haribabu kommi
<haribabu.kommi@huawei.com>wrote:

Here I have added some more regression tests to improve the missing
function coverage of

schemacmds.c, user.c and tablespace.c.

The added tests are mainly RENAME TO and OWNER TO support.

I've just had a look at both of these patches. All tests that have been
added seem to cover new areas that are not previously tested, they also
seem to cleanup properly after themselves, so I think these should be a
worthwhile addition to the regression tests.

The only thing I can pickup on which is at fault is the the trailing white
space

src/test/regress/sql/privileges.sql:837: trailing whitespace.
+\c -

But I can't imagine it's worth submitting a new patch to fix it.

I've marked the patch as ready for commiter

Regards

David Rowley

Show quoted text

patches are attached in the mail.

please check and provide your suggestions.

Regards,

Hari babu.

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#4Kevin Grittner
kgrittn@ymail.com
In reply to: David Rowley (#3)
Re: Regress tests to improve the function coverage of schemacmds and user and tablespace files

David Rowley <dgrowleyml@gmail.com> wrote:

I've just had a look at both of these patches. All tests that
have been added seem to cover new areas that are not previously
tested, they also seem to cleanup properly after themselves, so I
think these should be a worthwhile addition to the regression
tests.

Thanks for reviewing!  Did you happen to note the impact on `make
check` runtime?  There are many people who run that many times per
day while working on development, so we try to keep new tests that
significantly extend that separate.  We haven't quite worked out
the best way to exercise such longer-running tests, but I suspect
we soon will.  At any rate, this is a piece of information the
committer will want, so you will be helping whoever that is if you
can supply it.

--
Kevin Grittner
EDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#5David Rowley
dgrowleyml@gmail.com
In reply to: Kevin Grittner (#4)
1 attachment(s)
Re: Regress tests to improve the function coverage of schemacmds and user and tablespace files

On Sun, Nov 24, 2013 at 6:37 AM, Kevin Grittner <kgrittn@ymail.com> wrote:

David Rowley <dgrowleyml@gmail.com> wrote:

I've just had a look at both of these patches. All tests that
have been added seem to cover new areas that are not previously
tested, they also seem to cleanup properly after themselves, so I
think these should be a worthwhile addition to the regression
tests.

Thanks for reviewing! Did you happen to note the impact on `make
check` runtime? There are many people who run that many times per
day while working on development, so we try to keep new tests that
significantly extend that separate. We haven't quite worked out
the best way to exercise such longer-running tests, but I suspect
we soon will. At any rate, this is a piece of information the
committer will want, so you will be helping whoever that is if you
can supply it.

I've done a quick benchmark on this this morning.
Note that I'm using windows here and I used powershell to time the
regression run with the following command:

PS D:\Postgres\b\src\tools\msvc> Measure-Command { .\vcregress.bat check }

I ran the tests 10 times each.
I ran the patched version first, then just did git reset --hard to revert
the patched changes then I ran the tests again.

The average and median results over the 10 runs are as follows:

Patched Unpatched Time increased by
Average 48.23265888 47.70979854 101.10%
Median 47.8993686 47.51177815 100.82%

The slowdown is not too bad. It just around 1% increase of time.

I've attached the results in spreadsheet format.

Regards

David Rowley

--

Show quoted text

Kevin Grittner
EDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

Attachments:

regression_test_benchmark.xlsxapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheet; name=regression_test_benchmark.xlsxDownload
#6Haribabu kommi
haribabu.kommi@huawei.com
In reply to: David Rowley (#5)
Re: Regress tests to improve the function coverage of schemacmds and user and tablespace files

On 24 November 2013 03:04 David Rowley wrote:

I've done a quick benchmark on this this morning.
Note that I'm using windows here and I used powershell to time the regression run with the following command:

PS D:\Postgres\b\src\tools\msvc> Measure-Command { .\vcregress.bat check }

I ran the tests 10 times each.
I ran the patched version first, then just did git reset --hard to revert the patched changes then I ran the tests again.

The average and median results over the 10 runs are as follows:

Patched Unpatched Time increased by
Average 48.23265888 47.70979854 101.10%
Median 47.8993686 47.51177815 100.82%

The slowdown is not too bad. It just around 1% increase of time.

I've attached the results in spreadsheet format.

Thanks for the review and benchmark test.

Regards,
Hari babu.