mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-15 18:13:18 +08:00
This will move the definitions of `debug_waitpoint_enable`, `debug_waitpoint_disable`, and `debug_waitpoint_id` to always be defined for debug builds and modify existing tests accordingly. This means that it is no longer necessary to generate isolation test files from templates (in most cases), and it will be straightforward to use these functions in debug builds. The debug utilities can be disabled by setting the option `ENABLE_DEBUG_UTILS` to `OFF`.
114 lines
3.6 KiB
Plaintext
114 lines
3.6 KiB
Plaintext
-- This file and its contents are licensed under the Apache License 2.0.
|
|
-- Please see the included NOTICE for copyright information and
|
|
-- LICENSE-APACHE for a copy of the license.
|
|
\c :TEST_DBNAME :ROLE_SUPERUSER
|
|
CREATE OR REPLACE FUNCTION test.condition() RETURNS VOID
|
|
AS :MODULE_PATHNAME, 'ts_test_utils_condition' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
|
|
CREATE OR REPLACE FUNCTION test.int64_eq() RETURNS VOID
|
|
AS :MODULE_PATHNAME, 'ts_test_utils_int64_eq' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
|
|
CREATE OR REPLACE FUNCTION test.ptr_eq() RETURNS VOID
|
|
AS :MODULE_PATHNAME, 'ts_test_utils_ptr_eq' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
|
|
CREATE OR REPLACE FUNCTION test.double_eq() RETURNS VOID
|
|
AS :MODULE_PATHNAME, 'ts_test_utils_double_eq' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
|
|
SET ROLE :ROLE_DEFAULT_PERM_USER;
|
|
-- We're testing that the test utils work and generate errors on
|
|
-- failing conditions
|
|
\set ON_ERROR_STOP 0
|
|
SELECT test.condition();
|
|
ERROR: TestFailure | (true_value == false_value)
|
|
SELECT test.int64_eq();
|
|
ERROR: TestFailure | (big == small) [32532978 == 3242234]
|
|
SELECT test.ptr_eq();
|
|
ERROR: TestFailure | (true_ptr == false_ptr)
|
|
SELECT test.double_eq();
|
|
ERROR: TestFailure | (big_double == small_double) [923423478.324200 == 324.300000]
|
|
\set ON_ERROR_STOP 1
|
|
-- Test debug points
|
|
--
|
|
\set ECHO all
|
|
\c :TEST_DBNAME :ROLE_SUPERUSER
|
|
-- debug point already enabled
|
|
SELECT debug_waitpoint_enable('test_debug_point');
|
|
debug_waitpoint_enable
|
|
------------------------
|
|
|
|
(1 row)
|
|
|
|
\set ON_ERROR_STOP 0
|
|
SELECT debug_waitpoint_enable('test_debug_point');
|
|
ERROR: debug point "test_debug_point" already enabled
|
|
\set ON_ERROR_STOP 1
|
|
SELECT debug_waitpoint_release('test_debug_point');
|
|
debug_waitpoint_release
|
|
-------------------------
|
|
|
|
(1 row)
|
|
|
|
-- debug point not enabled
|
|
\set ON_ERROR_STOP 0
|
|
SELECT debug_waitpoint_release('test_debug_point');
|
|
WARNING: you don't own a lock of type ExclusiveLock
|
|
ERROR: cannot release debug point "test_debug_point"
|
|
\set ON_ERROR_STOP 1
|
|
-- error injections
|
|
--
|
|
CREATE OR REPLACE FUNCTION test_error_injection(TEXT)
|
|
RETURNS VOID
|
|
AS :MODULE_PATHNAME, 'ts_test_error_injection'
|
|
LANGUAGE C VOLATILE STRICT;
|
|
SET ROLE :ROLE_DEFAULT_PERM_USER;
|
|
SELECT test_error_injection('test_error');
|
|
test_error_injection
|
|
----------------------
|
|
|
|
(1 row)
|
|
|
|
SELECT debug_waitpoint_enable('test_error');
|
|
debug_waitpoint_enable
|
|
------------------------
|
|
|
|
(1 row)
|
|
|
|
\set ON_ERROR_STOP 0
|
|
SELECT test_error_injection('test_error');
|
|
ERROR: error injected at debug point 'test_error'
|
|
\set ON_ERROR_STOP 1
|
|
SELECT debug_waitpoint_release('test_error');
|
|
debug_waitpoint_release
|
|
-------------------------
|
|
|
|
(1 row)
|
|
|
|
SELECT test_error_injection('test_error');
|
|
test_error_injection
|
|
----------------------
|
|
|
|
(1 row)
|
|
|
|
-- Test Scanner
|
|
RESET ROLE;
|
|
CREATE OR REPLACE FUNCTION test.scanner() RETURNS VOID
|
|
AS :MODULE_PATHNAME, 'ts_test_scanner' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
|
|
SET ROLE :ROLE_DEFAULT_PERM_USER;
|
|
-- Create two chunks to scan in the test
|
|
CREATE TABLE hyper (time timestamptz, temp float);
|
|
SELECT create_hypertable('hyper', 'time');
|
|
NOTICE: adding not-null constraint to column "time"
|
|
create_hypertable
|
|
--------------------
|
|
(1,public,hyper,t)
|
|
(1 row)
|
|
|
|
INSERT INTO hyper VALUES ('2021-01-01', 1.0), ('2022-01-01', 2.0);
|
|
SELECT test.scanner();
|
|
NOTICE: 1. Scan: "_timescaledb_internal._hyper_1_1_chunk"
|
|
NOTICE: 1. Scan: "_timescaledb_internal._hyper_1_2_chunk"
|
|
NOTICE: 2. Scan with filter: "_timescaledb_internal._hyper_1_1_chunk"
|
|
NOTICE: 3. ReScan: "_timescaledb_internal._hyper_1_2_chunk"
|
|
NOTICE: 4. IndexScan: "_timescaledb_internal._hyper_1_2_chunk"
|
|
scanner
|
|
---------
|
|
|
|
(1 row)
|
|
|