Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some tests in test/cron_test.c failing #8

Open
marcelgoh opened this issue Jan 16, 2023 · 1 comment
Open

Some tests in test/cron_test.c failing #8

marcelgoh opened this issue Jan 16, 2023 · 1 comment

Comments

@marcelgoh
Copy link

marcelgoh commented Jan 16, 2023

Hi! I was trying to get a minimal build of this repo working so that I can run the tests in the test folder (and once these all pass, to write my own). I created a fork of this repo and, because there were a bunch of files in test/Makefile that were missing, I added them all individually (they are in src/common and src/frozen of my fork). Then I updated the paths in test/Makefile to point to where I added these new files.

After this is done, I can run make test from the test folder, but immediately there are issues. Here is the output from this first run:

(Expand first run output)
NOW: 1504065620 (2017-08-29 22:00:20 UTC-7)
--------------------------------------------------
expr = "* * * * * *"
current = 1504065621 (2017-08-29 22:00:21 UTC-7)
expe[0] = 1504065621 (2017-08-29 22:00:21 UTC-7)
--------------------------------------------------
expr = "*/15 * * * * *"
current = 1504065630 (2017-08-29 22:00:30 UTC-7)
expe[0] = 1504065630 (2017-08-29 22:00:30 UTC-7)
--------------------------------------------------
expr = "0 * * * * *"
current = 1504065660 (2017-08-29 22:01:00 UTC-7)
expe[0] = 1504065660 (2017-08-29 22:01:00 UTC-7)
--------------------------------------------------
expr = "0 * * * * 3"
current = 1504065660 (2017-08-29 22:01:00 UTC-7)
expe[0] = 1504072800 (2017-08-29 22:01:00 UTC-7)      <---- FAIL
--------------------------------------------------
expr = "10 * * * * *"
current = 1504065670 (2017-08-29 22:01:10 UTC-7)
expe[0] = 1504065670 (2017-08-29 22:01:10 UTC-7)
--------------------------------------------------
expr = "10 */1 * * * *"
current = 1504065670 (2017-08-29 22:01:10 UTC-7)
expe[0] = 1504065670 (2017-08-29 22:01:10 UTC-7)
--------------------------------------------------
expr = "0 0 * * * *"
current = 1504069200 (2017-08-29 23:00:00 UTC-7)
expe[0] = 1504069200 (2017-08-29 23:00:00 UTC-7)
--------------------------------------------------
expr = "0 0 0 * * *"
current = 1504137600 (2017-08-30 18:00:00 UTC-7)
expe[0] = 1504072800 (2017-08-30 18:00:00 UTC-7)      <---- FAIL
--------------------------------------------------
expr = "0 0 0 31 * *"
current = 1504137600 (2017-08-30 18:00:00 UTC-7)
expe[0] = 1504159200 (2017-08-30 18:00:00 UTC-7)      <---- FAIL
--------------------------------------------------
expr = "0 0 0 1 * *"
current = 1504224000 (2017-08-31 18:00:00 UTC-7)
expe[0] = 1504245600 (2017-08-31 18:00:00 UTC-7)      <---- FAIL
--------------------------------------------------
expr = "0 0 9 1-7 * 1"
current = 1504515600 (2017-09-04 03:00:00 UTC-7)
expe[0] = 1504537200 (2017-09-04 03:00:00 UTC-7)      <---- FAIL
--------------------------------------------------
expr = "* * * 5 9 *"
current = 1504569600 (2017-09-04 18:00:00 UTC-7)
expe[0] = 1504591200 (2017-09-04 18:00:00 UTC-7)      <---- FAIL
--------------------------------------------------
expr = "0 0 0 * * 3"
current = 1504656000 (2017-09-05 18:00:00 UTC-7)
expe[0] = 1504072800 (2017-09-05 18:00:00 UTC-7)      <---- FAIL
--------------------------------------------------

Fail on line 236: [s_te[i].count == 1]
FAIL, tests run: 17
make: *** [Makefile:13: test] Error 1

The most obvious problem is that several of the tests fail. However, even when current doesn't equal expe[0], the string representation of the dates are equal (and match the current date). I found that this could be fixed by splitting the printf call on line 246 of test/cron_test.c into multiple calls, one for current and one for expe[0]. (Though why this fixes the issue, I have no clue.) I then also decided to print expe[1] and expe[2] just for extra data, and also print the difference in seconds between current and expe[0]. This produces the following output:

(Expand output with extra print statements)
NOW: 1504065620 (2017-08-29 22:00:20 UTC-7)
--------------------------------------------------
expr = "* * * * * *"
current = 1504065621 (2017-08-29 22:00:21 UTC-7)
expe[0] = 1504065621 (2017-08-29 22:00:21 UTC-7)
expe[1] = 1504065622 (2017-08-29 22:00:22 UTC-7)
expe[2] = 1504065623 (2017-08-29 22:00:23 UTC-7)
--------------------------------------------------
expr = "*/15 * * * * *"
current = 1504065630 (2017-08-29 22:00:30 UTC-7)
expe[0] = 1504065630 (2017-08-29 22:00:30 UTC-7)
expe[1] = 1504065645 (2017-08-29 22:00:45 UTC-7)
expe[2] = 1504065660 (2017-08-29 22:01:00 UTC-7)
--------------------------------------------------
expr = "0 * * * * *"
current = 1504065660 (2017-08-29 22:01:00 UTC-7)
expe[0] = 1504065660 (2017-08-29 22:01:00 UTC-7)
expe[1] = 1504065720 (2017-08-29 22:02:00 UTC-7)
expe[2] = 1504065780 (2017-08-29 22:03:00 UTC-7)
--------------------------------------------------
expr = "0 * * * * 3"
current = 1504065660 (2017-08-29 22:01:00 UTC-7)
expe[0] = 1504072800 (2017-08-30 00:00:00 UTC-7)
expe[1] = 1504072860 (2017-08-30 00:01:00 UTC-7)
expe[2] = 1504072920 (2017-08-30 00:02:00 UTC-7)      <---- FAIL (difference: -7140)
--------------------------------------------------
expr = "10 * * * * *"
current = 1504065670 (2017-08-29 22:01:10 UTC-7)
expe[0] = 1504065670 (2017-08-29 22:01:10 UTC-7)
expe[1] = 1504065730 (2017-08-29 22:02:10 UTC-7)
expe[2] = 1504065790 (2017-08-29 22:03:10 UTC-7)
--------------------------------------------------
expr = "10 */1 * * * *"
current = 1504065670 (2017-08-29 22:01:10 UTC-7)
expe[0] = 1504065670 (2017-08-29 22:01:10 UTC-7)
expe[1] = 1504065730 (2017-08-29 22:02:10 UTC-7)
expe[2] = 1504065790 (2017-08-29 22:03:10 UTC-7)
--------------------------------------------------
expr = "0 0 * * * *"
current = 1504069200 (2017-08-29 23:00:00 UTC-7)
expe[0] = 1504069200 (2017-08-29 23:00:00 UTC-7)
expe[1] = 1504072800 (2017-08-30 00:00:00 UTC-7)
expe[2] = 1504076400 (2017-08-30 01:00:00 UTC-7)
--------------------------------------------------
expr = "0 0 0 * * *"
current = 1504137600 (2017-08-30 18:00:00 UTC-7)
expe[0] = 1504072800 (2017-08-30 00:00:00 UTC-7)
expe[1] = 1504159200 (2017-08-31 00:00:00 UTC-7)
expe[2] = 1504245600 (2017-09-01 00:00:00 UTC-7)      <---- FAIL (difference: 64800)
--------------------------------------------------
expr = "0 0 0 31 * *"
current = 1504137600 (2017-08-30 18:00:00 UTC-7)
expe[0] = 1504159200 (2017-08-31 00:00:00 UTC-7)
expe[1] = 1509429600 (2017-10-31 00:00:00 UTC-7)
expe[2] = 1514703600 (2017-12-31 00:00:00 UTC-7)      <---- FAIL (difference: -21600)
--------------------------------------------------
expr = "0 0 0 1 * *"
current = 1504224000 (2017-08-31 18:00:00 UTC-7)
expe[0] = 1504245600 (2017-09-01 00:00:00 UTC-7)
expe[1] = 1506837600 (2017-10-01 00:00:00 UTC-7)
expe[2] = 1509516000 (2017-11-01 00:00:00 UTC-7)      <---- FAIL (difference: -21600)
--------------------------------------------------
expr = "0 0 9 1-7 * 1"
current = 1504515600 (2017-09-04 03:00:00 UTC-7)
expe[0] = 1504537200 (2017-09-04 09:00:00 UTC-7)
expe[1] = 1506956400 (2017-10-02 09:00:00 UTC-7)
expe[2] = 1509984000 (2017-11-06 09:00:00 UTC-7)      <---- FAIL (difference: -21600)
--------------------------------------------------
expr = "* * * 5 9 *"
current = 1504569600 (2017-09-04 18:00:00 UTC-7)
expe[0] = 1504591200 (2017-09-05 00:00:00 UTC-7)
expe[1] = 1504591201 (2017-09-05 00:00:01 UTC-7)
expe[2] = 1504591202 (2017-09-05 00:00:02 UTC-7)      <---- FAIL (difference: -21600)
--------------------------------------------------
expr = "0 0 0 * * 3"
current = 1504656000 (2017-09-05 18:00:00 UTC-7)
expe[0] = 1504072800 (2017-08-30 00:00:00 UTC-7)
expe[1] = 1504677600 (2017-09-06 00:00:00 UTC-7)
expe[2] = 1505282400 (2017-09-13 00:00:00 UTC-7)      <---- FAIL (difference: 583200)
--------------------------------------------------

Fail on line 239: [s_te[i].count == 1]
FAIL, tests run: 17
make: *** [Makefile:13: test] Error 1

Just eyeballing the outputs, it seems like the tests that fail are the ones related to the date. For example, in the first failing test, the date August 29, 2017 is a Tuesday, so querying the next Wednesday should return midnight on August 30; however, I believe the code is interpreting the epoch time as a GMT date, so it thinks it is already Wednesday and just returns the next whole minute. (My current timezone is Mountain Standard Time (UTC -7).)

I wonder if this is an issue in my fork or if there is actually an issue in the cron implementation that causes these tests to fail. For reference, here is a link to my fork so that you can see the code that causes the output above.

@marcelgoh
Copy link
Author

This was fixed by adding -DCRON_USE_LOCAL_TIME=1 to the build commands in the Makefile. If this seems like a valuable change to make in the master branch of the repo I could make a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant