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

Use timer mock on Incremental CAgg Refresh policy tests #7813

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions tsl/test/expected/cagg_refresh_policy_incremental.out
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ SELECT
t, d, 10
FROM
generate_series(
'2025-02-05 00:00:00-03',
'2025-03-05 00:00:00-03',
'2025-02-05 00:00:00+00',
'2025-03-05 00:00:00+00',
'1 hour'::interval) AS t,
generate_series(1,5) AS d;
CREATE MATERIALIZED VIEW conditions_by_day
Expand Down Expand Up @@ -288,8 +288,8 @@ SELECT
t, d, 10
FROM
generate_series(
'2020-02-05 00:00:00-03',
'2020-03-05 00:00:00-03',
'2020-02-05 00:00:00+00',
'2020-03-05 00:00:00+00',
'1 hour'::interval) AS t,
generate_series(1,5) AS d;
-- advance time by 3h so that job runs one more time
Expand Down Expand Up @@ -427,8 +427,8 @@ SELECT
t, d, 10
FROM
generate_series(
'2020-02-05 00:00:00-03',
'2020-02-06 00:00:00-03',
'2020-02-05 00:00:00+00',
'2020-02-06 00:00:00+00',
'1 hour'::interval) AS t,
generate_series(1,5) AS d;
TRUNCATE bgw_log;
Expand Down Expand Up @@ -467,7 +467,7 @@ SELECT count(*) FROM conditions_by_day;
TRUNCATE conditions_by_day, conditions, bgw_log;
-- Less than 1 day of data (smaller than the bucket width)
INSERT INTO conditions
VALUES ('2020-02-05 00:00:00-03', 1, 10);
VALUES ('2020-02-05 00:00:00+00', 1, 10);
-- advance time by 6h so that job runs one more time
SELECT ts_bgw_params_reset_time(extract(epoch from interval '6 hour')::bigint * 1000000, true);
ts_bgw_params_reset_time
Expand Down Expand Up @@ -531,6 +531,7 @@ FROM
'2025-03-11 00:00:00+00'::timestamptz,
'1 hour'::interval) AS t,
generate_series(1,5) AS d;
SET timescaledb.current_timestamp_mock TO '2025-03-11 00:00:00+00';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does timer mock support time zones i.e. is it set to a particular time zone?

Copy link
Member Author

@fabriziomello fabriziomello Mar 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it support ... it just return a TimestampTz. We do something like this in our code base:

#ifdef TS_DEBUG
	Datum res = ts_get_mock_time_or_current_time();
#else
	Datum res = TimestampTzGetDatum(GetCurrentTimestamp());
#endif

It means that will return the mock time if you set it, if you don't set a mock timestamp then ts_get_mock_timr_or_current_time() will return GetCurrentTimestamp().

Copy link
Contributor

@natalya-aksman natalya-aksman Mar 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But will the test interpret, say, 2025-03-11 00:00:00+00 timer mock as being in a particular time zone? I.e. will it translate to local time if run, say, in New York vs. Berlin? Is the time zone hard set in the timer mock?

SELECT ts_bgw_params_reset_time(0, true);
ts_bgw_params_reset_time
--------------------------
Expand Down
15 changes: 8 additions & 7 deletions tsl/test/sql/cagg_refresh_policy_incremental.sql
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ SELECT
t, d, 10
FROM
generate_series(
'2025-02-05 00:00:00-03',
'2025-03-05 00:00:00-03',
'2025-02-05 00:00:00+00',
'2025-03-05 00:00:00+00',
'1 hour'::interval) AS t,
generate_series(1,5) AS d;

Expand Down Expand Up @@ -182,8 +182,8 @@ SELECT
t, d, 10
FROM
generate_series(
'2020-02-05 00:00:00-03',
'2020-03-05 00:00:00-03',
'2020-02-05 00:00:00+00',
'2020-03-05 00:00:00+00',
'1 hour'::interval) AS t,
generate_series(1,5) AS d;

Expand Down Expand Up @@ -249,8 +249,8 @@ SELECT
t, d, 10
FROM
generate_series(
'2020-02-05 00:00:00-03',
'2020-02-06 00:00:00-03',
'2020-02-05 00:00:00+00',
'2020-02-06 00:00:00+00',
'1 hour'::interval) AS t,
generate_series(1,5) AS d;

Expand All @@ -270,7 +270,7 @@ TRUNCATE conditions_by_day, conditions, bgw_log;

-- Less than 1 day of data (smaller than the bucket width)
INSERT INTO conditions
VALUES ('2020-02-05 00:00:00-03', 1, 10);
VALUES ('2020-02-05 00:00:00+00', 1, 10);

-- advance time by 6h so that job runs one more time
SELECT ts_bgw_params_reset_time(extract(epoch from interval '6 hour')::bigint * 1000000, true);
Expand Down Expand Up @@ -314,6 +314,7 @@ FROM
'1 hour'::interval) AS t,
generate_series(1,5) AS d;

SET timescaledb.current_timestamp_mock TO '2025-03-11 00:00:00+00';
SELECT ts_bgw_params_reset_time(0, true);
SELECT ts_bgw_db_scheduler_test_run_and_wait_for_scheduler_finish(25);
SELECT * FROM sorted_bgw_log;
Expand Down
Loading