Skip to content

Commit 27a8310

Browse files
committed
Fix pg_regress.c to report tests in a parallel group when they finish,
not when they're started. This mimics a subtle point of the behavior of the old shell script, and gives better feedback when watching the tests.
1 parent 5652ea7 commit 27a8310

File tree

1 file changed

+48
-27
lines changed

1 file changed

+48
-27
lines changed

src/test/regress/pg_regress.c

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Portions Copyright (c) 1996-2006, 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.6 2006/07/20 01:16:57 tgl Exp $
14+
* $PostgreSQL: pgsql/src/test/regress/pg_regress.c,v 1.7 2006/07/20 02:10:00 tgl Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -919,47 +919,70 @@ results_differ(const char *testname)
919919

920920
/*
921921
* Wait for specified subprocesses to finish
922+
*
923+
* If names isn't NULL, report each subprocess as it finishes
924+
*
925+
* Note: it's OK to scribble on the pids array, but not on the names array
922926
*/
923927
static void
924-
wait_for_tests(PID_TYPE *pids, int num_tests)
928+
wait_for_tests(PID_TYPE *pids, char **names, int num_tests)
925929
{
926-
#ifndef WIN32
927930
int tests_left;
928931
int i;
929932

933+
#ifdef WIN32
934+
PID_TYPE *active_pids = malloc(num_tests * sizeof(PID_TYPE));
935+
936+
memcpy(active_pids, pids, num_tests * sizeof(PID_TYPE));
937+
#endif
938+
930939
tests_left = num_tests;
931940
while (tests_left > 0)
932941
{
933-
pid_t p = wait(NULL);
942+
PID_TYPE p;
934943

935-
if (p == -1)
944+
#ifndef WIN32
945+
p = wait(NULL);
946+
947+
if (p == INVALID_PID)
936948
{
937-
fprintf(stderr, _("could not wait(): %s\n"), strerror(errno));
949+
fprintf(stderr, _("failed to wait for subprocesses: %s\n"),
950+
strerror(errno));
938951
exit_nicely(2);
939952
}
953+
#else
954+
int r;
955+
956+
r = WaitForMultipleObjects(tests_left, active_pids, FALSE, INFINITE);
957+
if (r < WAIT_OBJECT_0 || r >= WAIT_OBJECT_0 + tests_left)
958+
{
959+
fprintf(stderr, _("failed to wait for subprocesses: %lu\n"),
960+
GetLastError());
961+
exit_nicely(2);
962+
}
963+
p = active_pids[r - WAIT_OBJECT_0];
964+
/* compact the active_pids array */
965+
active_pids[r - WAIT_OBJECT_0] = active_pids[tests_left - 1];
966+
#endif /* WIN32 */
967+
940968
for (i=0; i < num_tests; i++)
941969
{
942-
/* Make sure we only count the processes we explicitly started */
943970
if (p == pids[i])
944971
{
945-
pids[i] = -1;
972+
#ifdef WIN32
973+
CloseHandle(pids[i]);
974+
#endif
975+
pids[i] = INVALID_PID;
976+
if (names)
977+
status(" %s", names[i]);
946978
tests_left--;
979+
break;
947980
}
948981
}
949982
}
950-
#else
951-
int r;
952-
int i;
953983

954-
r = WaitForMultipleObjects(num_tests, pids, TRUE, INFINITE);
955-
if (r != WAIT_OBJECT_0)
956-
{
957-
fprintf(stderr, _("could not wait for commands to finish: %lu\n"),
958-
GetLastError());
959-
exit_nicely(2);
960-
}
961-
for (i = 0; i < num_tests; i++)
962-
CloseHandle(pids[i]);
984+
#ifdef WIN32
985+
free(active_pids);
963986
#endif
964987
}
965988

@@ -1059,7 +1082,7 @@ run_schedule(const char *schedule)
10591082
{
10601083
status(_("test %-20s ... "), tests[0]);
10611084
pids[0] = psql_start_test(tests[0]);
1062-
wait_for_tests(pids, 1);
1085+
wait_for_tests(pids, NULL, 1);
10631086
/* status line is finished below */
10641087
}
10651088
else if (max_connections > 0 && max_connections < num_tests)
@@ -1072,24 +1095,22 @@ run_schedule(const char *schedule)
10721095
{
10731096
if (i - oldest >= max_connections)
10741097
{
1075-
wait_for_tests(pids + oldest, i - oldest);
1098+
wait_for_tests(pids + oldest, tests + oldest, i - oldest);
10761099
oldest = i;
10771100
}
1078-
status(" %s", tests[i]);
10791101
pids[i] = psql_start_test(tests[i]);
10801102
}
1081-
wait_for_tests(pids + oldest, i - oldest);
1103+
wait_for_tests(pids + oldest, tests + oldest, i - oldest);
10821104
status_end();
10831105
}
10841106
else
10851107
{
10861108
status(_("parallel group (%d tests): "), num_tests);
10871109
for (i = 0; i < num_tests; i++)
10881110
{
1089-
status(" %s", tests[i]);
10901111
pids[i] = psql_start_test(tests[i]);
10911112
}
1092-
wait_for_tests(pids, num_tests);
1113+
wait_for_tests(pids, tests, num_tests);
10931114
status_end();
10941115
}
10951116

@@ -1146,7 +1167,7 @@ run_single_test(const char *test)
11461167

11471168
status(_("test %-20s ... "), test);
11481169
pid = psql_start_test(test);
1149-
wait_for_tests(&pid, 1);
1170+
wait_for_tests(&pid, NULL, 1);
11501171

11511172
if (results_differ(test))
11521173
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy