Skip to content

Commit

Permalink
wip/ci
Browse files Browse the repository at this point in the history
  • Loading branch information
v0idpwn committed Oct 25, 2024
1 parent de3be54 commit f80dfe9
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 24 deletions.
Empty file added pgmq-extension/regression.diffs
Empty file.
Empty file added pgmq-extension/regression.out
Empty file.
4 changes: 3 additions & 1 deletion pgmq-extension/sql/pgmq.sql
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ CREATE TYPE pgmq.metrics_result AS (
newest_msg_age_sec int,
oldest_msg_age_sec int,
total_messages bigint,
scrape_time timestamp with time zone
scrape_time timestamp with time zone,
queue_visible_length bigint
);
-- get metrics for a single queue
Expand All @@ -336,6 +337,7 @@ BEGIN
WITH q_summary AS (
SELECT
count(*) as queue_length,
count(case when vt <= NOW() THEN 1 ELSE 0),
EXTRACT(epoch FROM (NOW() - max(enqueued_at)))::int as newest_msg_age_sec,
EXTRACT(epoch FROM (NOW() - min(enqueued_at)))::int as oldest_msg_age_sec,
NOW() as scrape_time
Expand Down
16 changes: 13 additions & 3 deletions pgmq-extension/test/expected/base.out
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,19 @@ SELECT pgmq.create_partitioned('test_numeric_queue', '10 seconds', '20 seconds')

(1 row)

-- get metrics
SELECT queue_name, queue_length, newest_msg_age_sec, oldest_msg_age_sec, total_messages
FROM pgmq.metrics('test_duration_queue');
-- create a queue for metrics
SELECT pgmq.create('test_metrics_queue');
create
--------------------

(1 row)

-- doing some operations to get some numbers in
PERFORM pgmq.send_batch('test_metrics_queue', '[1, 2, 3, 4, 5]'::jsonb);
PERFORM pgmq.send_batch('test_metrics_queue', '[6, 7]'::jsonb);
PERFORM pgmq.archive('test_metrics_queue', 1);

SELECT * FROM pgmq.metrics('test_duration_queue');
queue_name | queue_length | newest_msg_age_sec | oldest_msg_age_sec | total_messages
---------------------+--------------+--------------------+--------------------+----------------
test_duration_queue | 0 | | | 0
Expand Down
32 changes: 12 additions & 20 deletions pgmq-extension/test/sql/base.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@ SELECT pgmq.create('test_default_queue');
SELECT * from pgmq.send('test_default_queue', '{"hello": "world"}');

-- read message
-- vt=0, limit=1
-- vt=2, limit=1
\set msg_id 1
SELECT msg_id = :msg_id FROM pgmq.read('test_default_queue', 0, 1);

-- read message using conditional
SELECT msg_id = :msg_id FROM pgmq.read('test_default_queue', 2, 1, '{"hello": "world"}');
SELECT msg_id = :msg_id FROM pgmq.read('test_default_queue', 2, 1);

-- set VT to 5 seconds
SELECT vt > clock_timestamp() + '4 seconds'::interval
Expand All @@ -42,13 +39,6 @@ SELECT msg_id = :msg_id FROM pgmq.read('test_default_queue', 2, 1);
-- read again, now using poll to block until message is ready
SELECT msg_id = :msg_id FROM pgmq.read_with_poll('test_default_queue', 10, 1, 10);

-- set VT to 5 seconds again for another read_with_poll test
SELECT vt > clock_timestamp() + '4 seconds'::interval
FROM pgmq.set_vt('test_default_queue', :msg_id, 5);

-- read again, now using poll to block until message is ready
SELECT msg_id = :msg_id FROM pgmq.read_with_poll('test_default_queue', 10, 1, 10, 100, '{"hello": "world"}');

-- after reading it, set VT to now
SELECT msg_id = :msg_id FROM pgmq.set_vt('test_default_queue', :msg_id, 0);

Expand All @@ -68,9 +58,16 @@ SELECT pgmq.create_partitioned('test_duration_queue', '5 seconds', '10 seconds')
-- CREATE with 10 messages per partition, 20 messages retention
SELECT pgmq.create_partitioned('test_numeric_queue', '10 seconds', '20 seconds');

-- get metrics
SELECT queue_name, queue_length, newest_msg_age_sec, oldest_msg_age_sec, total_messages
FROM pgmq.metrics('test_duration_queue');
-- create a queue for metrics
SELECT pgmq.create('test_metrics_queue');

-- doing some operations to get some numbers in
SELECT pgmq.send_batch('test_metrics_queue', '[1, 2, 3, 4, 5]'::jsonb);
SELECT pgmq.send_batch('test_metrics_queue', '[6, 7]'::jsonb, 10);
SELECT pgmq.archive('test_metrics_queue', 1);

-- actually reading metrics
SELECT * FROM pgmq.metrics('test_duration_queue');

-- get metrics all
SELECT * from {PGMQ_SCHEMA}.metrics_all();
Expand Down Expand Up @@ -315,11 +312,6 @@ SELECT pgmq.format_table_name('double--hyphen-fail', 'a');
SELECT pgmq.format_table_name('semicolon;fail', 'a');
SELECT pgmq.format_table_name($$single'quote-fail$$, 'a');
-- test null message
SELECT pgmq.create('null_message_queue');
SELECT pgmq.send('null_message_queue', NULL);
SELECT msg_id, read_ct, message FROM pgmq.read('null_message_queue', 1, 1);
--Cleanup tests
DROP EXTENSION pgmq CASCADE;
DROP EXTENSION pg_partman CASCADE;

0 comments on commit f80dfe9

Please sign in to comment.