Skip to content

Commit

Permalink
[FLAKY TEST] Fix codec test causing CI to fail (opensearch-project#277)
Browse files Browse the repository at this point in the history
Closes resource monitor at the end of the Codec tests so that there are no
unparked threads.

Signed-off-by: John Mazanec <[email protected]>
  • Loading branch information
jmazanec15 authored Feb 10, 2022
1 parent c46b3de commit 18e6e35
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/test/java/org/opensearch/knn/index/codec/KNNCodecTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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 {
Expand Down Expand Up @@ -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<String> 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
Expand All @@ -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 {
Expand Down Expand Up @@ -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);
Expand All @@ -269,6 +276,8 @@ public void testBuildFromModelTemplate(Codec codec) throws IOException, Executio

reader.close();
dir.close();
resourceWatcherService.close();
NativeMemoryLoadStrategy.IndexLoadStrategy.getInstance().close();
}
}

0 comments on commit 18e6e35

Please sign in to comment.