Re: contrib/dblink GRANTs and regression test fix - Mailing list pgsql-patches

From Joe Conway
Subject Re: contrib/dblink GRANTs and regression test fix
Date
Msg-id 3D83AEC0.6070807@joeconway.com
Whole thread Raw
In response to contrib/dblink GRANTs and regression test fix  (Joe Conway <mail@joeconway.com>)
Responses Re: contrib/dblink GRANTs and regression test fix  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-patches
Tom Lane wrote:
> Applied.  The method for dropping the second database seems pretty
> cheesy itself, though; and wouldn't it make it harder to investigate
> the cause of a test failure, if one occurs?  I think I'd vote for
> getting rid of the trailing wait() and DROP and instead doing
>
> \set ECHO none
> DROP DATABASE regression_slave;
> \set ECHO all
> CREATE DATABASE regression_slave;
>

I didn't give you any time for a reply, but just in case you think this
acceptable, here's a patch that does what I mentioned in the last post. Namely
it removes the wait() function and DROP DATABASE at the end of the script, and
adds a conditional_drop() function to the beginning of the script.

If there are no objections, please apply.

Thanks,

Joe
Index: contrib/dblink/expected/dblink.out
===================================================================
RCS file: /opt/src/cvs/pgsql-server/contrib/dblink/expected/dblink.out,v
retrieving revision 1.1
diff -c -r1.1 dblink.out
*** contrib/dblink/expected/dblink.out    14 Sep 2002 20:28:54 -0000    1.1
--- contrib/dblink/expected/dblink.out    14 Sep 2002 21:11:21 -0000
***************
*** 3,8 ****
--- 3,25 ----
  -- Turn off echoing so that expected file does not depend on
  -- contents of dblink.sql.
  --
+ CREATE FUNCTION conditional_drop() RETURNS text AS '
+ DECLARE
+     dbname    text;
+ BEGIN
+     SELECT INTO dbname datname FROM pg_database WHERE datname = ''regression_slave'';
+     IF FOUND THEN
+         DROP DATABASE regression_slave;
+     END IF;
+     RETURN ''OK'';
+ END;
+ ' LANGUAGE 'plpgsql';
+ SELECT conditional_drop();
+  conditional_drop
+ ------------------
+  OK
+ (1 row)
+
  CREATE DATABASE regression_slave;
  \connect regression_slave
  \set ECHO none
***************
*** 219,259 ****
   OK
  (1 row)

- -- now wait for the connection to the slave to be cleared before
- -- we try to drop the database
- CREATE FUNCTION wait() RETURNS TEXT AS '
- DECLARE
-     rec           record;
-     cntr          int;
- BEGIN
-     cntr = 0;
-
-     select into rec d.datname
-     from pg_database d,
-         (select pg_stat_get_backend_dbid(pg_stat_get_backend_idset()) AS dbid) b
-     where d.oid = b.dbid and d.datname = ''regression_slave'';
-
-     WHILE FOUND LOOP
-         cntr = cntr + 1;
-
-         select into rec d.datname
-         from pg_database d,
-             (select pg_stat_get_backend_dbid(pg_stat_get_backend_idset()) AS dbid) b
-         where d.oid = b.dbid and d.datname = ''regression_slave'';
-
-         -- safety valve
-         if cntr > 1000 THEN
-             EXIT;
-         end if;
-     END LOOP;
-     RETURN ''OK'';
- END;
- ' LANGUAGE 'plpgsql';
- SELECT wait();
-  wait
- ------
-  OK
- (1 row)
-
- -- OK, safe to drop the slave
- DROP DATABASE regression_slave;
--- 236,238 ----
Index: contrib/dblink/sql/dblink.sql
===================================================================
RCS file: /opt/src/cvs/pgsql-server/contrib/dblink/sql/dblink.sql,v
retrieving revision 1.1
diff -c -r1.1 dblink.sql
*** contrib/dblink/sql/dblink.sql    14 Sep 2002 20:28:54 -0000    1.1
--- contrib/dblink/sql/dblink.sql    14 Sep 2002 21:11:15 -0000
***************
*** 3,8 ****
--- 3,20 ----
  -- Turn off echoing so that expected file does not depend on
  -- contents of dblink.sql.
  --
+ CREATE FUNCTION conditional_drop() RETURNS text AS '
+ DECLARE
+     dbname    text;
+ BEGIN
+     SELECT INTO dbname datname FROM pg_database WHERE datname = ''regression_slave'';
+     IF FOUND THEN
+         DROP DATABASE regression_slave;
+     END IF;
+     RETURN ''OK'';
+ END;
+ ' LANGUAGE 'plpgsql';
+ SELECT conditional_drop();
  CREATE DATABASE regression_slave;
  \connect regression_slave
  \set ECHO none
***************
*** 112,149 ****

  -- close the persistent connection
  select dblink_disconnect();
-
- -- now wait for the connection to the slave to be cleared before
- -- we try to drop the database
- CREATE FUNCTION wait() RETURNS TEXT AS '
- DECLARE
-     rec           record;
-     cntr          int;
- BEGIN
-     cntr = 0;
-
-     select into rec d.datname
-     from pg_database d,
-         (select pg_stat_get_backend_dbid(pg_stat_get_backend_idset()) AS dbid) b
-     where d.oid = b.dbid and d.datname = ''regression_slave'';
-
-     WHILE FOUND LOOP
-         cntr = cntr + 1;
-
-         select into rec d.datname
-         from pg_database d,
-             (select pg_stat_get_backend_dbid(pg_stat_get_backend_idset()) AS dbid) b
-         where d.oid = b.dbid and d.datname = ''regression_slave'';
-
-         -- safety valve
-         if cntr > 1000 THEN
-             EXIT;
-         end if;
-     END LOOP;
-     RETURN ''OK'';
- END;
- ' LANGUAGE 'plpgsql';
- SELECT wait();
-
- -- OK, safe to drop the slave
- DROP DATABASE regression_slave;
--- 124,126 ----

pgsql-patches by date:

Previous
From: Tom Lane
Date:
Subject: Re: contrib/dblink GRANTs and regression test fix
Next
From: Tom Lane
Date:
Subject: Re: contrib/dblink GRANTs and regression test fix