From 18e6e3502bcf5a5fc962cb29d94a378857bb9b33 Mon Sep 17 00:00:00 2001 From: Jack Mazanec Date: Wed, 9 Feb 2022 20:00:56 -0500 Subject: [PATCH] [FLAKY TEST] Fix codec test causing CI to fail (#277) Closes resource monitor at the end of the Codec tests so that there are no unparked threads. Signed-off-by: John Mazanec --- .../knn/index/codec/KNNCodecTestCase.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/opensearch/knn/index/codec/KNNCodecTestCase.java b/src/test/java/org/opensearch/knn/index/codec/KNNCodecTestCase.java index c0cd1e9f9..0688f554e 100644 --- a/src/test/java/org/opensearch/knn/index/codec/KNNCodecTestCase.java +++ b/src/test/java/org/opensearch/knn/index/codec/KNNCodecTestCase.java @@ -109,7 +109,8 @@ public void testFooter(Codec codec) throws Exception { doc.add(vectorField); writer.addDocument(doc); - NativeMemoryLoadStrategy.IndexLoadStrategy.initialize(createDisabledResourceWatcherService()); + ResourceWatcherService resourceWatcherService = createDisabledResourceWatcherService(); + NativeMemoryLoadStrategy.IndexLoadStrategy.initialize(resourceWatcherService); IndexReader reader = writer.getReader(); LeafReaderContext lrc = reader.getContext().leaves().iterator().next(); // leaf reader context SegmentReader segmentReader = (SegmentReader) FilterLeafReader.unwrap(lrc.reader()); @@ -131,6 +132,8 @@ public void testFooter(Codec codec) throws Exception { reader.close(); writer.close(); dir.close(); + resourceWatcherService.close(); + NativeMemoryLoadStrategy.IndexLoadStrategy.getInstance().close(); } public void testMultiFieldsKnnIndex(Codec codec) throws Exception { @@ -165,7 +168,8 @@ public void testMultiFieldsKnnIndex(Codec codec) throws Exception { writer.addDocument(doc1); IndexReader reader = writer.getReader(); writer.close(); - NativeMemoryLoadStrategy.IndexLoadStrategy.initialize(createDisabledResourceWatcherService()); + ResourceWatcherService resourceWatcherService = createDisabledResourceWatcherService(); + NativeMemoryLoadStrategy.IndexLoadStrategy.initialize(resourceWatcherService); List hnswfiles = Arrays.stream(dir.listAll()).filter(x -> x.contains("hnsw")).collect(Collectors.toList()); // there should be 2 hnsw index files created. one for test_vector and one for my_vector @@ -186,6 +190,8 @@ public void testMultiFieldsKnnIndex(Codec codec) throws Exception { reader.close(); dir.close(); + resourceWatcherService.close(); + NativeMemoryLoadStrategy.IndexLoadStrategy.getInstance().close(); } public void testBuildFromModelTemplate(Codec codec) throws IOException, ExecutionException, InterruptedException { @@ -257,7 +263,8 @@ public void testBuildFromModelTemplate(Codec codec) throws IOException, Executio // Make sure that search returns the correct results KNNWeight.initialize(modelDao); - NativeMemoryLoadStrategy.IndexLoadStrategy.initialize(createDisabledResourceWatcherService()); + ResourceWatcherService resourceWatcherService = createDisabledResourceWatcherService(); + NativeMemoryLoadStrategy.IndexLoadStrategy.initialize(resourceWatcherService); float [] query = {10.0f, 10.0f, 10.0f}; IndexSearcher searcher = new IndexSearcher(reader); TopDocs topDocs = searcher.search(new KNNQuery(fieldName, query, 4, "dummy"), 10); @@ -269,6 +276,8 @@ public void testBuildFromModelTemplate(Codec codec) throws IOException, Executio reader.close(); dir.close(); + resourceWatcherService.close(); + NativeMemoryLoadStrategy.IndexLoadStrategy.getInstance().close(); } }