Skip to content

Commit 2256ada

Browse files
test: added tests for same key being present in multiple sessions
1 parent b252222 commit 2256ada

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

db/tests/unit/agg_increment.test.sql

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
BEGIN;
22
-- Plan the tests.
3-
SELECT plan(2);
3+
SELECT plan(3);
44

55
INSERT INTO rate_limit.sessions (id, name_, type_)
66
SELECT
77
'00000000-0000-0000-0000-000000000000'::uuid AS id,
88
'dedicated-test'::text AS name_,
9-
'aggregated'::text AS type_;
9+
'aggregated'::text AS type_
10+
UNION
11+
SELECT
12+
'00000000-1111-1111-1111-000000000000'::uuid AS id,
13+
'dedicated-test-2'::text AS name_,
14+
'aggregated'::text AS type_;;
1015

1116
INSERT INTO rate_limit.records_aggregated (key, session_id)
1217
SELECT
@@ -23,6 +28,16 @@ SELECT results_eq(
2328
'rate_limit.agg_increment returns correct count for new key'
2429
);
2530

31+
SELECT results_eq(
32+
$have$
33+
SELECT agg_increment AS count FROM rate_limit.agg_increment('new-key', '00000000-1111-1111-1111-000000000000')
34+
$have$,
35+
$want$
36+
SELECT 1::int AS count;
37+
$want$,
38+
'rate_limit.agg_increment returns correct count for new key on different session'
39+
);
40+
2641
SELECT results_eq(
2742
$have$
2843
SELECT agg_increment AS count FROM rate_limit.agg_increment('existing-key', '00000000-0000-0000-0000-000000000000')

db/tests/unit/ind_increment.test.sql

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
BEGIN;
22
-- Plan the tests.
3-
SELECT plan(3);
3+
SELECT plan(4);
44

55
INSERT INTO rate_limit.sessions (id, name_, type_)
66
SELECT
77
'00000000-0000-0000-0000-000000000000'::uuid AS id,
88
'dedicated-test'::text AS name_,
9+
'individual'::text AS type_
10+
UNION
11+
SELECT
12+
'00000000-1111-1111-1111-000000000000'::uuid AS id,
13+
'dedicated-test-2'::text AS name_,
914
'individual'::text AS type_;
1015

1116
INSERT INTO rate_limit.individual_records (key, session_id)
@@ -23,6 +28,16 @@ SELECT results_eq(
2328
'rate_limit.ind_increment returns correct count for new key'
2429
);
2530

31+
SELECT results_eq(
32+
$have$
33+
SELECT ind_increment AS count FROM rate_limit.ind_increment('new-key', '00000000-1111-1111-1111-000000000000')
34+
$have$,
35+
$want$
36+
SELECT 1::int AS count;
37+
$want$,
38+
'rate_limit.ind_increment returns correct count for new key on another session'
39+
);
40+
2641
SELECT results_eq(
2742
$have$
2843
SELECT ind_increment AS count FROM rate_limit.ind_increment('existing-key', '00000000-0000-0000-0000-000000000000')

0 commit comments

Comments
 (0)