Skip to content

Commit

Permalink
add some more tests clean things up
Browse files Browse the repository at this point in the history
  • Loading branch information
ezra-varady committed Oct 5, 2023
1 parent 98d6e5e commit d6c7da7
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 77 deletions.
12 changes: 8 additions & 4 deletions scripts/run_all_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,15 @@ if [ "$PARALLEL" -eq 1 ]; then
else
SCHEDULE='schedule.txt'
fi
if [ -n "$FILTER" ] && [ -z "$PARALLEL" ]; then
if [[ "$pgvector_installed" == "1" ]]; then
TEST_FILES=$(cat $SCHEDULE | grep -E '^(test:|test_pgvector:)' | sed -E -e 's/^test:|test_pgvector://' | tr " " "\n" | sed -e '/^$/d')
if [ -n "$FILTER" ]; then
if [ "$PARALLEL" -eq 1 ]; then
TEST_FILES=$(cat $SCHEDULE | grep -E '^(test:|test_begin:|test_end:)' | sed -E -e 's/^test:|test_begin:|test_end://' | tr " " "\n" | sed -e '/^$/d')
else
TEST_FILES=$(cat $SCHEDULE | grep '^test:' | sed -e 's/^test://' | tr " " "\n" | sed -e '/^$/d')
if [[ "$pgvector_installed" == "1" ]]; then
TEST_FILES=$(cat $SCHEDULE | grep -E '^(test:|test_pgvector:)' | sed -E -e 's/^test:|test_pgvector://' | tr " " "\n" | sed -e '/^$/d')
else
TEST_FILES=$(cat $SCHEDULE | grep '^test:' | sed -e 's/^test://' | tr " " "\n" | sed -e '/^$/d')
fi
fi

while IFS= read -r f; do
Expand Down
12 changes: 12 additions & 0 deletions test/parallel/expected/begin.out
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ CREATE TABLE IF NOT EXISTS sift_base10k (
v REAL[128]
);
\copy sift_base10k (v) FROM '/tmp/lantern/vector_datasets/siftsmall_base_arrays.csv' with csv;
\ir utils/random_array.sql
CREATE OR REPLACE FUNCTION random_int_array(dim integer, min integer, max integer) RETURNS integer[] AS $BODY$
begin
return (select array_agg(round(random() * (max - min)) + min) from generate_series (0, dim - 1));
end
$BODY$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION random_array(dim integer, min real, max real) RETURNS REAL[] AS $BODY$
begin
return (select array_agg(random() * (max - min) + min) from generate_series (0, dim - 1));
end
$BODY$ LANGUAGE plpgsql;
CREATE SEQUENCE serial START 10001;
CREATE INDEX ON sift_base10k USING HNSW (v) WITH (M=5, ef=20, ef_construction=20);
INFO: done init usearch index
INFO: inserted 10000 elements
Expand Down
30 changes: 13 additions & 17 deletions test/parallel/expected/insert.out
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
\ir utils/random_array.sql
CREATE OR REPLACE FUNCTION random_int_array(dim integer, min integer, max integer) RETURNS integer[] AS $BODY$
begin
return (select array_agg(round(random() * (max - min)) + min) from generate_series (0, dim - 1));
end
$BODY$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION random_array(dim integer, min real, max real) RETURNS REAL[] AS $BODY$
begin
return (select array_agg(random() * (max - min) + min) from generate_series (0, dim - 1));
end
$BODY$ LANGUAGE plpgsql;
DO $$
BEGIN
FOR i IN 1..10 LOOP
INSERT INTO sift_base10k (v) VALUES (random_array(128, 0, 128));
END LOOP;
END; $$
BEGIN;
INSERT INTO sift_base10k (id, v) VALUES
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128));
COMMIT;
30 changes: 13 additions & 17 deletions test/parallel/expected/insert2.out
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
\ir utils/random_array.sql
CREATE OR REPLACE FUNCTION random_int_array(dim integer, min integer, max integer) RETURNS integer[] AS $BODY$
begin
return (select array_agg(round(random() * (max - min)) + min) from generate_series (0, dim - 1));
end
$BODY$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION random_array(dim integer, min real, max real) RETURNS REAL[] AS $BODY$
begin
return (select array_agg(random() * (max - min) + min) from generate_series (0, dim - 1));
end
$BODY$ LANGUAGE plpgsql;
DO $$
BEGIN
FOR i IN 1..10 LOOP
INSERT INTO sift_base10k (v) VALUES (random_array(128, 0, 128));
END LOOP;
END; $$
BEGIN;
INSERT INTO sift_base10k (id, v) VALUES
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128));
COMMIT;
30 changes: 13 additions & 17 deletions test/parallel/expected/insert3.out
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
\ir utils/random_array.sql
CREATE OR REPLACE FUNCTION random_int_array(dim integer, min integer, max integer) RETURNS integer[] AS $BODY$
begin
return (select array_agg(round(random() * (max - min)) + min) from generate_series (0, dim - 1));
end
$BODY$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION random_array(dim integer, min real, max real) RETURNS REAL[] AS $BODY$
begin
return (select array_agg(random() * (max - min) + min) from generate_series (0, dim - 1));
end
$BODY$ LANGUAGE plpgsql;
DO $$
BEGIN
FOR i IN 1..10 LOOP
INSERT INTO sift_base10k (v) VALUES (random_array(128, 0, 128));
END LOOP;
END; $$
BEGIN;
INSERT INTO sift_base10k (id, v) VALUES
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128));
COMMIT;
28 changes: 28 additions & 0 deletions test/parallel/expected/select.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
SELECT v AS v1111 FROM sift_base10k WHERE id = 1111 \gset
SELECT v AS v2222 FROM sift_base10k WHERE id = 2222 \gset
SELECT v AS v3333 FROM sift_base10k WHERE id = 3333 \gset
SELECT v AS v4444 FROM sift_base10k WHERE id = 4444 \gset
SELECT id FROM sift_base10k ORDER BY v <-> :'v1111' ASC LIMIT 1;
id
------
1111
(1 row)

SELECT id FROM sift_base10k ORDER BY v <-> :'v2222' ASC LIMIT 1;
id
------
2222
(1 row)

SELECT id FROM sift_base10k ORDER BY v <-> :'v3333' ASC LIMIT 1;
id
------
3333
(1 row)

SELECT id FROM sift_base10k ORDER BY v <-> :'v4444' ASC LIMIT 1;
id
------
4444
(1 row)

2 changes: 2 additions & 0 deletions test/parallel/sql/begin.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
\ir utils/sift10k_array.sql
\ir utils/random_array.sql

CREATE SEQUENCE serial START 10001;
CREATE INDEX ON sift_base10k USING HNSW (v) WITH (M=5, ef=20, ef_construction=20);
20 changes: 13 additions & 7 deletions test/parallel/sql/insert.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
\ir utils/random_array.sql
DO $$
BEGIN
FOR i IN 1..10 LOOP
INSERT INTO sift_base10k (v) VALUES (random_array(128, 0, 128));
END LOOP;
END; $$
BEGIN;
INSERT INTO sift_base10k (id, v) VALUES
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128));
COMMIT;
20 changes: 13 additions & 7 deletions test/parallel/sql/insert2.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
\ir utils/random_array.sql
DO $$
BEGIN
FOR i IN 1..10 LOOP
INSERT INTO sift_base10k (v) VALUES (random_array(128, 0, 128));
END LOOP;
END; $$
BEGIN;
INSERT INTO sift_base10k (id, v) VALUES
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128));
COMMIT;
20 changes: 13 additions & 7 deletions test/parallel/sql/insert3.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
\ir utils/random_array.sql
DO $$
BEGIN
FOR i IN 1..10 LOOP
INSERT INTO sift_base10k (v) VALUES (random_array(128, 0, 128));
END LOOP;
END; $$
BEGIN;
INSERT INTO sift_base10k (id, v) VALUES
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128)),
(nextval('serial'), random_array(128, 0, 128));
COMMIT;
8 changes: 8 additions & 0 deletions test/parallel/sql/select.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
SELECT v AS v1111 FROM sift_base10k WHERE id = 1111 \gset
SELECT v AS v2222 FROM sift_base10k WHERE id = 2222 \gset
SELECT v AS v3333 FROM sift_base10k WHERE id = 3333 \gset
SELECT v AS v4444 FROM sift_base10k WHERE id = 4444 \gset
SELECT id FROM sift_base10k ORDER BY v <-> :'v1111' ASC LIMIT 1;
SELECT id FROM sift_base10k ORDER BY v <-> :'v2222' ASC LIMIT 1;
SELECT id FROM sift_base10k ORDER BY v <-> :'v3333' ASC LIMIT 1;
SELECT id FROM sift_base10k ORDER BY v <-> :'v4444' ASC LIMIT 1;
2 changes: 1 addition & 1 deletion test/parallel_schedule.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
# - 'test' lines may have multiple space-separated tests. All tests in a single 'test' line will be run in parallel

test_begin: begin
test: insert insert2 insert3
test: insert insert2 insert3 select
test_end: end

0 comments on commit d6c7da7

Please sign in to comment.