Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2939e20

Browse files
committed
Reduce risk of accidentally running temp-install regression tests against
a mismatching installation. Pick a default port number calculated from theversion number, and try a few times with other numbers if that one doesn'twork. Check if we can connect to the port before starting our own postmaster,to detect some other server already running there. To simplify the code,drop --temp-port option and use --port for both temp-install and pre-installedcase.
1 parenta93b3b9 commit2939e20

File tree

2 files changed

+48
-26
lines changed

2 files changed

+48
-26
lines changed

‎src/test/regress/GNUmakefile

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,14 @@
66
# Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
77
# Portions Copyright (c) 1994, Regents of the University of California
88
#
9-
# $PostgreSQL: pgsql/src/test/regress/GNUmakefile,v 1.75 2008/10/01 22:38:57 petere Exp $
9+
# $PostgreSQL: pgsql/src/test/regress/GNUmakefile,v 1.76 2008/11/28 12:45:34 petere Exp $
1010
#
1111
#-------------------------------------------------------------------------
1212

1313
subdir = src/test/regress
1414
top_builddir = ../../..
1515
include$(top_builddir)/src/Makefile.global
1616

17-
# port number for temp-installation test postmaster
18-
TEMP_PORT = 5$(DEF_PGPORT)
19-
2017
# file with extra config for temp build
2118
TEMP_CONF =
2219
ifdefTEMP_CONFIG
@@ -144,7 +141,7 @@ tablespace-setup:
144141
pg_regress_call = ./pg_regress --inputdir=$(srcdir) --dlpath=. --multibyte=$(MULTIBYTE) --load-language=plpgsql$(NOLOCALE)
145142

146143
check: all
147-
$(pg_regress_call) --temp-install=./tmp_check --top-builddir=$(top_builddir) --temp-port=$(TEMP_PORT) --schedule=$(srcdir)/parallel_schedule$(MAXCONNOPT)$(TEMP_CONF)
144+
$(pg_regress_call) --temp-install=./tmp_check --top-builddir=$(top_builddir) --schedule=$(srcdir)/parallel_schedule$(MAXCONNOPT)$(TEMP_CONF)
148145

149146
installcheck: all
150147
$(pg_regress_call) --psqldir=$(PSQLDIR) --schedule=$(srcdir)/serial_schedule
@@ -163,7 +160,7 @@ bigtest: all
163160
$(pg_regress_call) --psqldir=$(PSQLDIR) --schedule=$(srcdir)/serial_schedule numeric_big
164161

165162
bigcheck: all
166-
$(pg_regress_call) --temp-install=./tmp_check --top-builddir=$(top_builddir) --temp-port=$(TEMP_PORT) --schedule=$(srcdir)/parallel_schedule$(MAXCONNOPT) numeric_big
163+
$(pg_regress_call) --temp-install=./tmp_check --top-builddir=$(top_builddir) --schedule=$(srcdir)/parallel_schedule$(MAXCONNOPT) numeric_big
167164

168165

169166
##

‎src/test/regress/pg_regress.c

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
1212
* Portions Copyright (c) 1994, Regents of the University of California
1313
*
14-
* $PostgreSQL: pgsql/src/test/regress/pg_regress.c,v 1.53 2008/11/26 13:26:52 tgl Exp $
14+
* $PostgreSQL: pgsql/src/test/regress/pg_regress.c,v 1.54 2008/11/28 12:45:34 petere Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -83,10 +83,10 @@ static _stringlist *extra_tests = NULL;
8383
staticchar*temp_install=NULL;
8484
staticchar*temp_config=NULL;
8585
staticchar*top_builddir=NULL;
86-
staticinttemp_port=65432;
8786
staticboolnolocale= false;
8887
staticchar*hostname=NULL;
8988
staticintport=-1;
89+
staticboolport_specified_by_user= false;
9090
staticchar*dlpath=PKGLIBDIR;
9191
staticchar*user=NULL;
9292
static_stringlist*extraroles=NULL;
@@ -1844,7 +1844,7 @@ help(void)
18441844
printf(_("Options for \"temp-install\" mode:\n"));
18451845
printf(_(" --no-locale use C locale\n"));
18461846
printf(_(" --top-builddir=DIR (relative) path to top level build directory\n"));
1847-
printf(_(" --temp-port=PORTport number to start temppostmaster on\n"));
1847+
printf(_(" --port=PORT startpostmaster on PORT\n"));
18481848
printf(_(" --temp-config=PATH append contents of PATH to temporary config\n"));
18491849
printf(_("\n"));
18501850
printf(_("Options for using an existing installation:\n"));
@@ -1867,6 +1867,7 @@ regression_main(int argc, char *argv[], init_function ifunc, test_function tfunc
18671867
inti;
18681868
intoption_index;
18691869
charbuf[MAXPGPATH*4];
1870+
charbuf2[MAXPGPATH*4];
18701871

18711872
staticstructoptionlong_options[]= {
18721873
{"help",no_argument,NULL,'h'},
@@ -1882,7 +1883,6 @@ regression_main(int argc, char *argv[], init_function ifunc, test_function tfunc
18821883
{"temp-install",required_argument,NULL,9},
18831884
{"no-locale",no_argument,NULL,10},
18841885
{"top-builddir",required_argument,NULL,11},
1885-
{"temp-port",required_argument,NULL,12},
18861886
{"host",required_argument,NULL,13},
18871887
{"port",required_argument,NULL,14},
18881888
{"user",required_argument,NULL,15},
@@ -1956,20 +1956,12 @@ regression_main(int argc, char *argv[], init_function ifunc, test_function tfunc
19561956
case11:
19571957
top_builddir=strdup(optarg);
19581958
break;
1959-
case12:
1960-
{
1961-
intp=atoi(optarg);
1962-
1963-
/* Since Makefile isn't very bright, check port range */
1964-
if (p >=1024&&p <=65535)
1965-
temp_port=p;
1966-
}
1967-
break;
19681959
case13:
19691960
hostname=strdup(optarg);
19701961
break;
19711962
case14:
19721963
port=atoi(optarg);
1964+
port_specified_by_user= true;
19731965
break;
19741966
case15:
19751967
user=strdup(optarg);
@@ -2005,8 +1997,13 @@ regression_main(int argc, char *argv[], init_function ifunc, test_function tfunc
20051997
optind++;
20061998
}
20071999

2008-
if (temp_install)
2009-
port=temp_port;
2000+
if (temp_install&& !port_specified_by_user)
2001+
/*
2002+
* To reduce chances of interference with parallel
2003+
* installations, use a port number starting in the private
2004+
* range (49152-65535) calculated from the version number.
2005+
*/
2006+
port=0xC000 | (PG_VERSION_NUM&0x3FFF);
20102007

20112008
inputdir=make_absolute_path(inputdir);
20122009
outputdir=make_absolute_path(outputdir);
@@ -2106,6 +2103,37 @@ regression_main(int argc, char *argv[], init_function ifunc, test_function tfunc
21062103
fclose(pg_conf);
21072104
}
21082105

2106+
/*
2107+
* Check if there is a postmaster running already.
2108+
*/
2109+
snprintf(buf2,sizeof(buf2),
2110+
SYSTEMQUOTE"\"%s/psql\" -X postgres <%s 2>%s"SYSTEMQUOTE,
2111+
bindir,DEVNULL,DEVNULL);
2112+
2113+
for (i=0;i<16;i++)
2114+
{
2115+
if (system(buf2)==0)
2116+
{
2117+
chars[16];
2118+
2119+
if (port_specified_by_user||i==15)
2120+
{
2121+
fprintf(stderr,_("port %d apparently in use\n"),port);
2122+
if (!port_specified_by_user)
2123+
fprintf(stderr,_("%s: could not determine an available port\n"),progname);
2124+
fprintf(stderr,_("Specify an unused port using the --port option or shut down any conflicting PostgreSQL servers.\n"));
2125+
exit_nicely(2);
2126+
}
2127+
2128+
fprintf(stderr,_("port %d apparently in use, trying %d\n"),port,port+1);
2129+
port++;
2130+
sprintf(s,"%d",port);
2131+
doputenv("PGPORT",s);
2132+
}
2133+
else
2134+
break;
2135+
}
2136+
21092137
/*
21102138
* Start the temp postmaster
21112139
*/
@@ -2129,13 +2157,10 @@ regression_main(int argc, char *argv[], init_function ifunc, test_function tfunc
21292157
* second or so, but Cygwin is reportedly *much* slower). Don't wait
21302158
* forever, however.
21312159
*/
2132-
snprintf(buf,sizeof(buf),
2133-
SYSTEMQUOTE"\"%s/psql\" -X postgres <%s 2>%s"SYSTEMQUOTE,
2134-
bindir,DEVNULL,DEVNULL);
21352160
for (i=0;i<60;i++)
21362161
{
21372162
/* Done if psql succeeds */
2138-
if (system(buf)==0)
2163+
if (system(buf2)==0)
21392164
break;
21402165

21412166
/*
@@ -2180,7 +2205,7 @@ regression_main(int argc, char *argv[], init_function ifunc, test_function tfunc
21802205
postmaster_running= true;
21812206

21822207
printf(_("running on port %d with pid %lu\n"),
2183-
temp_port, (unsigned long)postmaster_pid);
2208+
port, (unsigned long)postmaster_pid);
21842209
}
21852210
else
21862211
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp