Skip to content

Commit 06c7aef

Browse files
committed
Fix test flakiness
1 parent a0dc9f1 commit 06c7aef

File tree

3 files changed

+42
-23
lines changed

3 files changed

+42
-23
lines changed

pgvectorscale/src/access_method/build.rs

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -469,15 +469,17 @@ pub mod tests {
469469
#[cfg(any(test, feature = "pg_test"))]
470470
pub unsafe fn test_index_creation_and_accuracy_scaffold(
471471
index_options: &str,
472+
name: &str,
472473
) -> spi::Result<()> {
474+
let table_name = format!("test_data_icaa_{}", name);
473475
Spi::run(&format!(
474-
"CREATE TABLE test_data (
476+
"CREATE TABLE {table_name} (
475477
embedding vector (1536)
476478
);
477479
478480
select setseed(0.5);
479481
-- generate 300 vectors
480-
INSERT INTO test_data (embedding)
482+
INSERT INTO {table_name} (embedding)
481483
SELECT
482484
*
483485
FROM (
@@ -488,15 +490,15 @@ pub mod tests {
488490
GROUP BY
489491
i % 300) g;
490492
491-
CREATE INDEX idx_diskann_bq ON test_data USING diskann (embedding) WITH ({index_options});
493+
CREATE INDEX ON {table_name} USING diskann (embedding) WITH ({index_options});
492494
493495
494496
SET enable_seqscan = 0;
495497
-- perform index scans on the vectors
496498
SELECT
497499
*
498500
FROM
499-
test_data
501+
{table_name}
500502
ORDER BY
501503
embedding <=> (
502504
SELECT
@@ -514,7 +516,7 @@ pub mod tests {
514516
SET enable_seqscan = 0;
515517
SET enable_indexscan = 1;
516518
SET diskann.query_search_list_size = 2;
517-
WITH cte as (select * from test_data order by embedding <=> $1::vector) SELECT count(*) from cte;
519+
WITH cte as (select * from {table_name} order by embedding <=> $1::vector) SELECT count(*) from cte;
518520
",
519521
),
520522
vec![(
@@ -530,7 +532,7 @@ pub mod tests {
530532

531533
Spi::run(&format!("
532534
-- test insert 2 vectors
533-
INSERT INTO test_data (embedding)
535+
INSERT INTO {table_name} (embedding)
534536
SELECT
535537
*
536538
FROM (
@@ -546,15 +548,15 @@ pub mod tests {
546548
SELECT
547549
*
548550
FROM
549-
test_data
551+
{table_name}
550552
ORDER BY
551553
embedding <=> (
552554
SELECT
553555
('[' || array_to_string(array_agg(random()), ',', '0') || ']')::vector AS embedding
554556
FROM generate_series(1, 1536));
555557
556558
-- test insert 10 vectors to search for that aren't random
557-
INSERT INTO test_data (embedding)
559+
INSERT INTO {table_name} (embedding)
558560
SELECT
559561
*
560562
FROM (
@@ -578,7 +580,7 @@ pub mod tests {
578580
SELECT
579581
ctid
580582
FROM
581-
test_data
583+
{table_name}
582584
ORDER BY
583585
embedding <=> $1::vector
584586
LIMIT 10
@@ -601,7 +603,7 @@ pub mod tests {
601603
SELECT
602604
ctid
603605
FROM
604-
test_data
606+
{table_name}
605607
ORDER BY
606608
embedding <=> $1::vector
607609
LIMIT 10
@@ -625,7 +627,7 @@ pub mod tests {
625627
SELECT
626628
ctid
627629
FROM
628-
test_data
630+
{table_name}
629631
ORDER BY
630632
embedding <=> $1::vector
631633
LIMIT 10
@@ -661,7 +663,7 @@ pub mod tests {
661663
SET enable_seqscan = 0;
662664
SET enable_indexscan = 1;
663665
SET diskann.query_search_list_size = 2;
664-
WITH cte as (select * from test_data order by embedding <=> $1::vector) SELECT count(*) from cte;
666+
WITH cte as (select * from {table_name} order by embedding <=> $1::vector) SELECT count(*) from cte;
665667
",
666668
),
667669
vec![(
@@ -736,16 +738,21 @@ pub mod tests {
736738
}
737739

738740
#[cfg(any(test, feature = "pg_test"))]
739-
pub unsafe fn test_index_updates(index_options: &str, expected_cnt: i64) -> spi::Result<()> {
741+
pub unsafe fn test_index_updates(
742+
index_options: &str,
743+
expected_cnt: i64,
744+
name: &str,
745+
) -> spi::Result<()> {
746+
let table_name = format!("test_data_index_updates_{}", name);
740747
Spi::run(&format!(
741-
"CREATE TABLE test_data (
748+
"CREATE TABLE {table_name} (
742749
id int,
743750
embedding vector (1536)
744751
);
745752
746753
select setseed(0.5);
747754
-- generate 300 vectors
748-
INSERT INTO test_data (id, embedding)
755+
INSERT INTO {table_name} (id, embedding)
749756
SELECT
750757
*
751758
FROM (
@@ -757,15 +764,15 @@ pub mod tests {
757764
GROUP BY
758765
i % {expected_cnt}) g;
759766
760-
CREATE INDEX idx_diskann_bq ON test_data USING diskann (embedding) WITH ({index_options});
767+
CREATE INDEX ON {table_name} USING diskann (embedding) WITH ({index_options});
761768
762769
763770
SET enable_seqscan = 0;
764771
-- perform index scans on the vectors
765772
SELECT
766773
*
767774
FROM
768-
test_data
775+
{table_name}
769776
ORDER BY
770777
embedding <=> (
771778
SELECT
@@ -783,7 +790,7 @@ pub mod tests {
783790
SET enable_seqscan = 0;
784791
SET enable_indexscan = 1;
785792
SET diskann.query_search_list_size = 2;
786-
WITH cte as (select * from test_data order by embedding <=> $1::vector) SELECT count(*) from cte;
793+
WITH cte as (select * from {table_name} order by embedding <=> $1::vector) SELECT count(*) from cte;
787794
",
788795
),
789796
vec![(
@@ -797,7 +804,7 @@ pub mod tests {
797804
Spi::run(&format!(
798805
"
799806
800-
--CREATE INDEX idx_id ON test_data(id);
807+
--CREATE INDEX idx_id ON {table_name}(id);
801808
802809
WITH CTE as (
803810
SELECT
@@ -808,9 +815,9 @@ pub mod tests {
808815
GROUP BY
809816
i % {expected_cnt}
810817
)
811-
UPDATE test_data SET embedding = cte.embedding
818+
UPDATE {table_name} SET embedding = cte.embedding
812819
FROM cte
813-
WHERE test_data.id = cte.id;
820+
WHERE {table_name}.id = cte.id;
814821
815822
--DROP INDEX idx_id;
816823
",
@@ -822,7 +829,7 @@ pub mod tests {
822829
SET enable_seqscan = 0;
823830
SET enable_indexscan = 1;
824831
SET diskann.query_search_list_size = 2;
825-
WITH cte as (select * from test_data order by embedding <=> $1::vector) SELECT count(*) from cte;
832+
WITH cte as (select * from {table_name} order by embedding <=> $1::vector) SELECT count(*) from cte;
826833
",
827834
),
828835
vec![(

pgvectorscale/src/access_method/plain_storage.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ mod tests {
360360
unsafe fn test_plain_storage_index_creation_many_neighbors() -> spi::Result<()> {
361361
crate::access_method::build::tests::test_index_creation_and_accuracy_scaffold(
362362
"num_neighbors=38, storage_layout = plain",
363+
"plain_many_neighbors",
363364
)?;
364365
Ok(())
365366
}
@@ -369,6 +370,7 @@ mod tests {
369370
//a test with few neighbors tests the case that nodes share a page, which has caused deadlocks in the past.
370371
crate::access_method::build::tests::test_index_creation_and_accuracy_scaffold(
371372
"num_neighbors=10, storage_layout = plain",
373+
"plain_few_neighbors",
372374
)?;
373375
Ok(())
374376
}
@@ -412,6 +414,7 @@ mod tests {
412414
unsafe fn test_plain_storage_num_dimensions() -> spi::Result<()> {
413415
crate::access_method::build::tests::test_index_creation_and_accuracy_scaffold(
414416
"num_neighbors=38, storage_layout = plain, num_dimensions=768",
417+
"plain_num_dimensions",
415418
)?;
416419
Ok(())
417420
}
@@ -421,6 +424,7 @@ mod tests {
421424
crate::access_method::build::tests::test_index_updates(
422425
"storage_layout = plain, num_neighbors=30",
423426
50,
427+
"plain",
424428
)?;
425429
Ok(())
426430
}

pgvectorscale/src/access_method/sbq.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,7 @@ mod tests {
969969
unsafe fn test_bq_speedup_storage_index_creation_default_neighbors() -> spi::Result<()> {
970970
crate::access_method::build::tests::test_index_creation_and_accuracy_scaffold(
971971
"storage_layout = io_optimized",
972+
"bq_speedup_default_neighbors",
972973
)?;
973974
Ok(())
974975
}
@@ -978,6 +979,7 @@ mod tests {
978979
//a test with few neighbors tests the case that nodes share a page, which has caused deadlocks in the past.
979980
crate::access_method::build::tests::test_index_creation_and_accuracy_scaffold(
980981
"num_neighbors=10, storage_layout = io_optimized",
982+
"bq_speedup_few_neighbors",
981983
)?;
982984
Ok(())
983985
}
@@ -1014,6 +1016,7 @@ mod tests {
10141016
unsafe fn test_bq_speedup_storage_index_creation_num_dimensions() -> spi::Result<()> {
10151017
crate::access_method::build::tests::test_index_creation_and_accuracy_scaffold(
10161018
"storage_layout = io_optimized, num_dimensions=768",
1019+
"bq_speedup_num_dimensions",
10171020
)?;
10181021
Ok(())
10191022
}
@@ -1023,14 +1026,16 @@ mod tests {
10231026
crate::access_method::build::tests::test_index_updates(
10241027
"storage_layout = io_optimized, num_neighbors=10",
10251028
300,
1029+
"bq_speedup",
10261030
)?;
10271031
Ok(())
10281032
}
10291033

10301034
#[pg_test]
1031-
unsafe fn test_bq_speedup_compressed_index_creation_default_neighbors() -> spi::Result<()> {
1035+
unsafe fn test_bq_compressed_index_creation_default_neighbors() -> spi::Result<()> {
10321036
crate::access_method::build::tests::test_index_creation_and_accuracy_scaffold(
10331037
"storage_layout = memory_optimized",
1038+
"bq_compressed_default_neighbors",
10341039
)?;
10351040
Ok(())
10361041
}
@@ -1040,6 +1045,7 @@ mod tests {
10401045
//a test with few neighbors tests the case that nodes share a page, which has caused deadlocks in the past.
10411046
crate::access_method::build::tests::test_index_creation_and_accuracy_scaffold(
10421047
"num_neighbors=10, storage_layout = memory_optimized",
1048+
"bq_compressed_few_neighbors",
10431049
)?;
10441050
Ok(())
10451051
}
@@ -1082,6 +1088,7 @@ mod tests {
10821088
unsafe fn test_bq_compressed_storage_index_creation_num_dimensions() -> spi::Result<()> {
10831089
crate::access_method::build::tests::test_index_creation_and_accuracy_scaffold(
10841090
"storage_layout = memory_optimized, num_dimensions=768",
1091+
"bq_compressed_num_dimensions",
10851092
)?;
10861093
Ok(())
10871094
}
@@ -1091,6 +1098,7 @@ mod tests {
10911098
crate::access_method::build::tests::test_index_updates(
10921099
"storage_layout = memory_optimized, num_neighbors=10",
10931100
300,
1101+
"bq_compressed",
10941102
)?;
10951103
Ok(())
10961104
}

0 commit comments

Comments
 (0)