Skip to content

Commit

Permalink
Fix flaky upgrade test
Browse files Browse the repository at this point in the history
The upgrade test utilizes several CAggs and defines refresh policies.
However, the test results are not deterministic due to the unpredictable
timing of the refreshes. This causes the test to be flaky. This pull
request explicitly adds explicit refreshes to the upgrade test to ensure
that the test results are deterministic.

(cherry picked from commit 53e9747)
  • Loading branch information
jnidzwetzki authored and timescale-automation committed Oct 26, 2023
1 parent 2a39fbb commit fad0a20
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
11 changes: 11 additions & 0 deletions test/sql/updates/post.continuous_aggs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
-- Please see the included NOTICE for copyright information and
-- LICENSE-APACHE for a copy of the license.

SELECT
extversion < '2.0.0' AS has_refresh_mat_view
FROM pg_extension
WHERE extname = 'timescaledb' \gset

\if :has_refresh_mat_view
REFRESH MATERIALIZED VIEW mat_before;
\else
CALL refresh_continuous_aggregate('mat_before',NULL,NULL);
\endif

\x on
SELECT * FROM mat_before ORDER BY bucket, location;
\x off
Expand Down
12 changes: 12 additions & 0 deletions test/sql/updates/post.continuous_aggs.v3.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@

\ir post.continuous_aggs.v2.sql

-- Ensure CAgg is refreshed
SELECT
extversion < '2.0.0' AS has_refresh_mat_view
FROM pg_extension
WHERE extname = 'timescaledb' \gset

\if :has_refresh_mat_view
REFRESH MATERIALIZED VIEW rename_cols;
\else
CALL refresh_continuous_aggregate('rename_cols',NULL,NULL);
\endif

SELECT "time", count(*) from rename_cols GROUP BY 1 ORDER BY 1;

--verify compression can be enabled
Expand Down
2 changes: 1 addition & 1 deletion test/sql/updates/setup.catalog.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
-- Please see the included NOTICE for copyright information and
-- LICENSE-APACHE for a copy of the license.

-- Catalog tables are occationally rewritten as part of updates, so
-- Catalog tables are occasionally rewritten as part of updates, so
-- this is to test that privileges are maintained over updates of the
-- extension. We could verify that other properties (e.g., comments)
-- are maintained here as well, but this is not something we use right
Expand Down
1 change: 0 additions & 1 deletion test/sql/updates/setup.continuous_aggs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ SELECT generate_series('2018-11-01 00:00'::timestamp, '2018-12-15 00:00'::timest
\else
GROUP BY bucket, location
HAVING min(location) >= 'NYC' and avg(temperature) > 2 WITH NO DATA;
SELECT add_continuous_aggregate_policy('mat_before', NULL, '-30 days'::interval, '336 h');
ALTER MATERIALIZED VIEW mat_before SET (timescaledb.materialized_only=true);
\endif

Expand Down
3 changes: 0 additions & 3 deletions test/sql/updates/setup.continuous_aggs.v2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ SELECT generate_series('2018-11-01 00:00'::timestamp, '2018-12-15 00:00'::timest
\else
GROUP BY bucket, location
WITH NO DATA;
SELECT add_continuous_aggregate_policy('rename_cols', NULL, '14 days'::interval, '336 h');
\endif

\if :has_refresh_mat_view
Expand Down Expand Up @@ -141,7 +140,6 @@ SELECT generate_series('2018-11-01 00:00'::timestamp, '2018-12-15 00:00'::timest
\else
GROUP BY bucket, location
HAVING min(location) >= 'NYC' and avg(temperature) > 2 WITH NO DATA;
SELECT add_continuous_aggregate_policy('mat_before', NULL, '-30 days'::interval, '336 h');

ALTER MATERIALIZED VIEW rename_cols RENAME COLUMN bucket TO "time";
\endif
Expand Down Expand Up @@ -218,7 +216,6 @@ CREATE SCHEMA cagg;
\else
GROUP BY bucket, location
HAVING min(location) >= 'NYC' and avg(temperature) > 2 WITH NO DATA;
SELECT add_continuous_aggregate_policy('cagg.realtime_mat', NULL, '-30 days'::interval, '336 h');
\endif
\if :WITH_SUPERUSER
GRANT SELECT ON cagg.realtime_mat TO cagg_user;
Expand Down

0 comments on commit fad0a20

Please sign in to comment.