Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FLAKY TEST] Fix codec test causing CI to fail #277

Merged
merged 2 commits into from
Feb 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that the only change in these lines is related to improved code readability, is this correct?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did it to be able to close resourceWatcherService at the end.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see, that makes sense. Thank you Jack

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();
}
}