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

fix calendar test exdate check #3293

Merged
merged 1 commit into from
Dec 17, 2023
Merged

Conversation

khassel
Copy link
Collaborator

@khassel khassel commented Dec 15, 2023

fixes #3291

@khassel khassel requested a review from rejas December 15, 2023 21:00
@KristjanESPERANTO
Copy link
Contributor

Interesting approach! But unfortunately, it seems to me that it will not work if the test is done on a Wednesday after the end of the event. I just set the time on my computer to Wednesday 23:10 and the test failed because it only found 50 events instead of 51.

$ npx jest ./tests/e2e/modules/calendar_spec.js
...
    Received promise rejected instead of resolved
    Rejected to value: [Error: expect(received).toHaveLength(expected)·
    Expected length: 51
    Received length: 50

If I set the day to Thursday or Friday it works with and without your fix.

@khassel khassel marked this pull request as draft December 15, 2023 23:25
@KristjanESPERANTO
Copy link
Contributor

KristjanESPERANTO commented Dec 15, 2023

It's strange.

I added a test for UTC:

describe('Timezones', () => {
	it('should always be UTC', () => {
			expect(new Date().getTimezoneOffset()).toBe(0);
	});
});

and run the test with timezone UTC:

$ TZ=UTC npx jest ./tests/e2e/modules/calendar_spec.js

This UTC test was successful, but the "51 events test" was still not. So the problem does not seem to be the time zone.

@khassel
Copy link
Collaborator Author

khassel commented Dec 16, 2023

If I set the day to Thursday or Friday it works with and without your fix.
So the problem does not seem to be the time zone.

I did some test loops over timezone and weekday and here are the results:

start magicmirror
  console.dir
    'Wed'
  Calendar module
    exdate check per TZ
      ✕ TZ-Offset=-12, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1454 ms)
      ✕ TZ-Offset=-11, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1318 ms)
      ✕ TZ-Offset=-10, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1340 ms)
      ✕ TZ-Offset=-9, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1320 ms)
      ✕ TZ-Offset=-8, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1314 ms)
      ✕ TZ-Offset=-7, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1337 ms)
      ✕ TZ-Offset=-6, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1327 ms)
      ✕ TZ-Offset=-5, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1306 ms)
      ✕ TZ-Offset=-4, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1314 ms)
      ✕ TZ-Offset=-3, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1478 ms)
      ✕ TZ-Offset=-2, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1316 ms)
      ✕ TZ-Offset=-1, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1317 ms)
      ✕ TZ-Offset=0, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1316 ms)
      ✕ TZ-Offset=1, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1330 ms)
      ✕ TZ-Offset=2, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1329 ms)
      ✕ TZ-Offset=3, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1320 ms)
      ✕ TZ-Offset=4, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1311 ms)
      ✓ TZ-Offset=5, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1364 ms)
      ✓ TZ-Offset=6, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1335 ms)
      ✓ TZ-Offset=7, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1328 ms)
      ✓ TZ-Offset=8, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1324 ms)
      ✓ TZ-Offset=9, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1323 ms)
      ✓ TZ-Offset=10, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1308 ms)
      ✓ TZ-Offset=11, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1449 ms)


start magicmirror
  console.dir
    'Thu'
  Calendar module
    exdate check per TZ
      ✓ TZ-Offset=-12, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1427 ms)
      ✓ TZ-Offset=-11, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1330 ms)
      ✓ TZ-Offset=-10, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1310 ms)
      ✓ TZ-Offset=-9, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1327 ms)
      ✓ TZ-Offset=-8, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1327 ms)
      ✓ TZ-Offset=-7, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1316 ms)
      ✓ TZ-Offset=-6, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1327 ms)
      ✓ TZ-Offset=-5, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1356 ms)
      ✓ TZ-Offset=-4, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1324 ms)
      ✓ TZ-Offset=-3, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1343 ms)
      ✓ TZ-Offset=-2, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1317 ms)
      ✓ TZ-Offset=-1, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1317 ms)
      ✓ TZ-Offset=0, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1320 ms)
      ✓ TZ-Offset=1, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1461 ms)
      ✓ TZ-Offset=2, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1325 ms)
      ✓ TZ-Offset=3, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1316 ms)
      ✓ TZ-Offset=4, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1344 ms)
      ✓ TZ-Offset=5, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1320 ms)
      ✓ TZ-Offset=6, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1241 ms)
      ✓ TZ-Offset=7, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1448 ms)
      ✓ TZ-Offset=8, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1333 ms)
      ✓ TZ-Offset=9, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1321 ms)
      ✓ TZ-Offset=10, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1324 ms)
      ✓ TZ-Offset=11, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1339 ms)


start magicmirror
  console.dir
    'all other days'
  Calendar module
    exdate check per TZ
      ✓ TZ-Offset=-12, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1437 ms)
      ✓ TZ-Offset=-11, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1307 ms)
      ✓ TZ-Offset=-10, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1310 ms)
      ✓ TZ-Offset=-9, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1319 ms)
      ✓ TZ-Offset=-8, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1310 ms)
      ✓ TZ-Offset=-7, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1310 ms)
      ✓ TZ-Offset=-6, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1291 ms)
      ✓ TZ-Offset=-5, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1312 ms)
      ✓ TZ-Offset=-4, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1328 ms)
      ✓ TZ-Offset=-3, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1323 ms)
      ✓ TZ-Offset=-2, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1241 ms)
      ✓ TZ-Offset=-1, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1359 ms)
      ✓ TZ-Offset=0, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1324 ms)
      ✓ TZ-Offset=1, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1315 ms)
      ✓ TZ-Offset=2, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1315 ms)
      ✓ TZ-Offset=3, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1329 ms)
      ✓ TZ-Offset=4, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1331 ms)
      ✕ TZ-Offset=5, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1349 ms)
      ✕ TZ-Offset=6, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1330 ms)
      ✕ TZ-Offset=7, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1238 ms)
      ✕ TZ-Offset=8, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1387 ms)
      ✕ TZ-Offset=9, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1326 ms)
      ✕ TZ-Offset=10, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1522 ms)
      ✕ TZ-Offset=11, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1251 ms)

I think this has something to do with the ics test data.

For get this working I decided to move this test from e2e to electron where we can set specific days where the test runs (and I choosed a Thursday).

If someone finds a better solution we can fix this in a better way later.

@khassel khassel marked this pull request as ready for review December 16, 2023 22:31
@khassel
Copy link
Collaborator Author

khassel commented Dec 16, 2023

for documentation purpose here my test setup (for me to find it if I have to work on this again):

Test file cal_test.js:

const helpers = require("../helpers/global-setup");

describe("Calendar module", () => {
        /**
         * @param {string} element css selector
         * @param {string} result expected number
         * @param {string} not reverse result
         * @returns {boolean} result
         */
        const testElementLength = async (element, result, not) => {
                const elem = await helpers.waitForAllElements(element);
                expect(elem).not.toBeNull();
                if (not === "not") {
                        expect(elem).not.toHaveLength(result);
                } else {
                        expect(elem).toHaveLength(result);
                }
                return true;
        };

        const testTextContain = async (element, text) => {
                const elem = await helpers.waitForElement(element, "undefinedLoading");
                expect(elem).not.toBeNull();
                expect(elem.textContent).toContain(text);
                return true;
        };

        afterAll(async () => {
                await helpers.stopApplication();
        });

        console.dir(Date().toString());

        process.setMaxListeners(0);
        for (let i = -12; i < 12; i++) {
                describe("exdate check per TZ", () => {
                        beforeAll(async () => {
                                Date.prototype.getTimezoneOffset = () => {
                                        return i * 60;
                                };
                                await helpers.startApplication("tests/configs/modules/calendar/exdate.js");
                                await helpers.getDocument();
                        });

                        it(`TZ-Offset=${i}, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period`, async () => {
                                await expect(testElementLength(".calendar .event", 51)).resolves.toBe(true);
                        });
                });
        }
});

bash file for looping over different days:

#!/bin/bash

for i in {0..6}; do
  echo $i
  docker run --rm -v $(pwd)/cal_test.js:/opt/magic_mirror/tests/e2e/modules/cal_test.js -e LD_PRELOAD="/usr/local/lib/libfaketime.so.1" -e FAKETIME="+${i}d" registry.gitlab.com/khassel/magicmirror:develop_debug21 npx jest tests/e2e/modules/cal_test.js --force-exit

done

@rejas rejas merged commit a7af76b into MagicMirrorOrg:develop Dec 17, 2023
6 checks passed
@khassel khassel deleted the cal-test branch December 21, 2023 19:55
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

Successfully merging this pull request may close these issues.

3 participants