Add --test long option to make the test suite repeatable.
Some checks failed
Remind unit tests / tests (push) Failing after 3h14m50s

This commit is contained in:
Dianne Skoll
2025-01-20 13:33:00 -05:00
parent e0c5e878a8
commit 901831ff75
7 changed files with 46 additions and 41 deletions

View File

@@ -530,11 +530,16 @@ resources. Note that the limit \fIn\fR is approximate and
\fBRemind\fR might execute for one or two more seconds before it is
killed. If \fIn\fR is specified as zero, then no limit is applied, just
as if the option had not been used at all.
.RS
.PP
If a limit is applied, it applies only to the foreground run of \fBRemind\fR.
If \fBRemind\fR finishes processing the script and then starts handling
queued reminders, the time limit is reset to no limit.
.PP
.RE
.TP
.B \-\-test
The \fB\-\-test\fR long option is only for use by the acceptance tests
run by "make test". Do not use this option in production.
.SH REMINDER FILES
.PP
\fBRemind\fR uses scripts to control its operation. You can use any

View File

@@ -176,6 +176,9 @@ EXTERN INIT( unsigned int FuncRecursionLevel, 0);
/* Suppress warnings about implicit REM and MSG */
EXTERN INIT( int SuppressImplicitRemWarnings, 0);
/* Test mode - used by the acceptance tests */
EXTERN INIT( int TestMode, 0);
extern int NumFullOmits, NumPartialOmits;
/* List of months */

View File

@@ -796,13 +796,9 @@ void InitRemind(int argc, char const *argv[])
}
/* Figure out the offset from UTC */
if (CalculateUTC)
if (CalculateUTC) {
(void) CalcMinsFromUTC(DSEToday, MinutesPastMidnight(0),
&MinsFromUTC, NULL);
/* Warn if REMIND_RUNNING_TEST is set */
s = getenv("REMIND_RUNNING_TEST");
if (s && !strcmp(s, "1")) {
fprintf(stderr, "WARNING: The REMIND_RUNNING_TEST environment variable is set to 1.\nThis is intended only for the Remind acceptance test and not normal use.\n");
}
}
@@ -1126,6 +1122,11 @@ static void
ProcessLongOption(char const *arg)
{
int t;
if (!strcmp(arg, "test")) {
fprintf(stderr, "Enabling test mode: This is meant for the acceptance test.\nDo not use --test in production.\n");
TestMode = 1;
return;
}
if (!strcmp(arg, "version")) {
printf("%s\n", VERSION);
exit(EXIT_SUCCESS);

View File

@@ -1007,27 +1007,18 @@ int SystemTime(int realtime)
{
time_t now;
struct tm *t;
int r;
char const *s;
if (!realtime && (SysTime != -1)) return SysTime;
now = time(NULL);
t = localtime(&now);
r = t->tm_hour * 3600L + t->tm_min * 60L +
t->tm_sec;
if (r < 82800) {
/* Before 23:00 */
return r;
if (TestMode) {
/* Pretend it's 7:00PM in test mode */
return 19 * 3600;
}
s = getenv("REMIND_RUNNING_TEST");
if (!s || strcmp(s, "1")) return r;
/* If it's after 23:00, subtract an hour to avoid
date rollover in queueing tests */
return r-3600;
now = time(NULL);
t = localtime(&now);
return t->tm_hour * 3600L + t->tm_min * 60L +
t->tm_sec;
}
/***************************************************************/
@@ -1057,6 +1048,11 @@ int SystemDate(int *y, int *m, int *d)
time_t now;
struct tm *t;
/* In test mode, always return 6 January 2025 */
if (TestMode) {
return 12803; /* 2025-01-06 */
}
now = time(NULL);
t = localtime(&now);

View File

@@ -460,7 +460,11 @@ void HandleQueuedReminders(void)
if (IsServerMode() && q->typ != RUN_TYPE) {
if (DaemonJSON) {
printf("{\"response\":\"reminder\",");
snprintf(qid, sizeof(qid), "%lx", (unsigned long) q);
if (TestMode) {
snprintf(qid, sizeof(qid), "42424242");
} else {
snprintf(qid, sizeof(qid), "%lx", (unsigned long) q);
}
PrintJSONKeyPairString("qid", qid);
PrintJSONKeyPairString("ttime", SimpleTimeNoSpace(q->tt.ttime));
PrintJSONKeyPairString("now", SimpleTimeNoSpace(MinutesPastMidnight(1)));
@@ -760,7 +764,11 @@ json_queue(QueuedRem const *q)
printf("{");
WriteJSONTrigger(&(q->t), 1, DSEToday);
WriteJSONTimeTrigger(&(q->tt));
snprintf(idbuf, sizeof(idbuf), "%lx", (unsigned long) q);
if (TestMode) {
snprintf(idbuf, sizeof(idbuf), "42424242");
} else {
snprintf(idbuf, sizeof(idbuf), "%lx", (unsigned long) q);
}
PrintJSONKeyPairString("qid", idbuf);
PrintJSONKeyPairInt("rundisabled", q->RunDisabled);
PrintJSONKeyPairInt("ntrig", q->ntrig);

View File

@@ -32,10 +32,6 @@ fi
# ../src/remind. This trick was suggested by Jochen Sprickerhof
alias remind="echo You should be using ../src/remind explicitly in test-rem >&2; exit 1"
# This environment variable is only needed for the queue tests, not for
# any others, so unset it here
unset REMIND_RUNNING_TEST
# Set a known timezone so moon phases show up in predictable places
TZ=UTC
export TZ
@@ -470,13 +466,9 @@ rm -rf include_dir/ww
../src/remind --version >> ../tests/test.out 2>&1
# Test queueing. Because eventstart depends on the actual system
# date, we have to convert it to some constant (in this case,
# VOLATILE) so that tests are not dependent on the system date.
REMIND_RUNNING_TEST=1
export REMIND_RUNNING_TEST
echo JSONQUEUE | ../src/remind -z0 ../tests/queue1.rem 2>&1 | sed -e 's/"eventstart":"................"/"eventstart":"VOLATILE"/g' | sed -e 's/"qid":"[0-9a-f]*",//g' >> ../tests/test.out 2>&1
echo QUEUE | ../src/remind -zj ../tests/queue1.rem 2>&1 | sed -e 's/"eventstart":"................"/"eventstart":"VOLATILE"/g' | sed -e 's/"qid":"[0-9a-f]*",//g' >> ../tests/test.out 2>&1
unset REMIND_RUNNING_TEST
# date, we use the --test flag to fake the date and time.
echo JSONQUEUE | ../src/remind --test -z0 ../tests/queue1.rem >> ../tests/test.out 2>&1
echo QUEUE | ../src/remind --test -zj ../tests/queue1.rem >> ../tests/test.out 2>&1
# Test for leap year bug that was fixed
../src/remind -dte - 28 Feb 2024 <<'EOF' >> ../tests/test.out 2>&1

View File

@@ -23201,14 +23201,14 @@ Error reading include_dir/ww: Can't open file
SECURITY: Won't read world-writable file or directory!
Error reading include_dir/ww: No files matching *.rem
05.02.03
WARNING: The REMIND_RUNNING_TEST environment variable is set to 1.
This is intended only for the Remind acceptance test and not normal use.
Enabling test mode: This is meant for the acceptance test.
Do not use --test in production.
NOTE JSONQUEUE
[{"priority":2,"eventstart":"VOLATILE","time":"23:59","nexttime":"23:59","tdelta":0,"trep":0,"rundisabled":0,"ntrig":1,"filename":"../tests/queue2.rem","lineno":1,"type":"MSG_TYPE","body":"XXXX"},{"priority":999,"eventstart":"VOLATILE","time":"23:58","nexttime":"23:58","tdelta":0,"trep":0,"rundisabled":0,"ntrig":1,"filename":"../tests/queue1.rem","lineno":5,"type":"MSG_TYPE","body":"quux"},{"priority":42,"eventstart":"VOLATILE","time":"23:57","nexttime":"23:57","tdelta":0,"trep":0,"rundisabled":0,"ntrig":1,"filename":"../tests/queue1.rem","lineno":4,"type":"MSG_TYPE","body":"bar"},{"priority":5000,"eventstart":"VOLATILE","time":"23:56","nexttime":"23:56","tdelta":0,"trep":0,"rundisabled":0,"ntrig":1,"filename":"../tests/queue1.rem","lineno":3,"type":"MSG_TYPE","body":"foo"}]
[{"priority":2,"eventstart":"2025-01-20T23:59","time":"23:59","nexttime":"23:59","tdelta":0,"trep":0,"qid":"42424242","rundisabled":0,"ntrig":1,"filename":"../tests/queue2.rem","lineno":1,"type":"MSG_TYPE","body":"XXXX"},{"priority":999,"eventstart":"2025-01-20T23:58","time":"23:58","nexttime":"23:58","tdelta":0,"trep":0,"qid":"42424242","rundisabled":0,"ntrig":1,"filename":"../tests/queue1.rem","lineno":5,"type":"MSG_TYPE","body":"quux"},{"priority":42,"eventstart":"2025-01-20T23:57","time":"23:57","nexttime":"23:57","tdelta":0,"trep":0,"qid":"42424242","rundisabled":0,"ntrig":1,"filename":"../tests/queue1.rem","lineno":4,"type":"MSG_TYPE","body":"bar"},{"priority":5000,"eventstart":"2025-01-20T23:56","time":"23:56","nexttime":"23:56","tdelta":0,"trep":0,"qid":"42424242","rundisabled":0,"ntrig":1,"filename":"../tests/queue1.rem","lineno":3,"type":"MSG_TYPE","body":"foo"}]
NOTE ENDJSONQUEUE
WARNING: The REMIND_RUNNING_TEST environment variable is set to 1.
This is intended only for the Remind acceptance test and not normal use.
{"response":"queue","queue":[{"priority":2,"eventstart":"VOLATILE","time":"23:59","nexttime":"23:59","tdelta":0,"trep":0,"rundisabled":0,"ntrig":1,"filename":"../tests/queue2.rem","lineno":1,"type":"MSG_TYPE","body":"XXXX"},{"priority":999,"eventstart":"VOLATILE","time":"23:58","nexttime":"23:58","tdelta":0,"trep":0,"rundisabled":0,"ntrig":1,"filename":"../tests/queue1.rem","lineno":5,"type":"MSG_TYPE","body":"quux"},{"priority":42,"eventstart":"VOLATILE","time":"23:57","nexttime":"23:57","tdelta":0,"trep":0,"rundisabled":0,"ntrig":1,"filename":"../tests/queue1.rem","lineno":4,"type":"MSG_TYPE","body":"bar"},{"priority":5000,"eventstart":"VOLATILE","time":"23:56","nexttime":"23:56","tdelta":0,"trep":0,"rundisabled":0,"ntrig":1,"filename":"../tests/queue1.rem","lineno":3,"type":"MSG_TYPE","body":"foo"}],"command":"QUEUE"}
Enabling test mode: This is meant for the acceptance test.
Do not use --test in production.
{"response":"queue","queue":[{"priority":2,"eventstart":"2025-01-20T23:59","time":"23:59","nexttime":"23:59","tdelta":0,"trep":0,"qid":"42424242","rundisabled":0,"ntrig":1,"filename":"../tests/queue2.rem","lineno":1,"type":"MSG_TYPE","body":"XXXX"},{"priority":999,"eventstart":"2025-01-20T23:58","time":"23:58","nexttime":"23:58","tdelta":0,"trep":0,"qid":"42424242","rundisabled":0,"ntrig":1,"filename":"../tests/queue1.rem","lineno":5,"type":"MSG_TYPE","body":"quux"},{"priority":42,"eventstart":"2025-01-20T23:57","time":"23:57","nexttime":"23:57","tdelta":0,"trep":0,"qid":"42424242","rundisabled":0,"ntrig":1,"filename":"../tests/queue1.rem","lineno":4,"type":"MSG_TYPE","body":"bar"},{"priority":5000,"eventstart":"2025-01-20T23:56","time":"23:56","nexttime":"23:56","tdelta":0,"trep":0,"qid":"42424242","rundisabled":0,"ntrig":1,"filename":"../tests/queue1.rem","lineno":3,"type":"MSG_TYPE","body":"foo"}],"command":"QUEUE"}
BANNER %
REM 29 MSG One
-(2): Trig = Thursday, 29 February, 2024