Skip to content

Commit

Permalink
Fix accounting in ModelLoadingServiceTests (#55307)
Browse files Browse the repository at this point in the history
In the test after the first load event is is not known which models are cached as 
loading a later one will evict an earlier one and the order is not known.
The models could have been loaded 1 or 2 times not exactly twice
  • Loading branch information
davidkyle authored Apr 21, 2020
1 parent b97c216 commit bbfa5be
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import org.junit.After;
import org.junit.Before;
import org.mockito.ArgumentMatcher;
import org.mockito.Mockito;

import java.io.IOException;
import java.net.InetAddress;
Expand Down Expand Up @@ -146,7 +145,6 @@ public void testGetCachedModels() throws Exception {
verify(trainedModelProvider, times(4)).getTrainedModel(eq(model3), eq(true), any());
}

@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/55251")
public void testMaxCachedLimitReached() throws Exception {
String model1 = "test-cached-limit-load-model-1";
String model2 = "test-cached-limit-load-model-2";
Expand Down Expand Up @@ -184,8 +182,11 @@ public void testMaxCachedLimitReached() throws Exception {
assertThat(future.get(), is(not(nullValue())));
}

verify(trainedModelProvider, times(2)).getTrainedModel(eq(model1), eq(true), any());
verify(trainedModelProvider, times(2)).getTrainedModel(eq(model2), eq(true), any());
// Depending on the order the models were first loaded in the first step
// models 1 & 2 may have been evicted by model 3 in which case they have
// been loaded at most twice
verify(trainedModelProvider, atMost(2)).getTrainedModel(eq(model1), eq(true), any());
verify(trainedModelProvider, atMost(2)).getTrainedModel(eq(model2), eq(true), any());
// Only loaded requested once on the initial load from the change event
verify(trainedModelProvider, times(1)).getTrainedModel(eq(model3), eq(true), any());

Expand Down Expand Up @@ -252,8 +253,7 @@ public boolean matches(final Object o) {

verify(trainedModelProvider, atMost(3)).getTrainedModel(eq(model1), eq(true), any());
verify(trainedModelProvider, atMost(3)).getTrainedModel(eq(model2), eq(true), any());
verify(trainedModelProvider, Mockito.atLeast(5)).getTrainedModel(eq(model3), eq(true), any());
verify(trainedModelProvider, atMost(5)).getTrainedModel(eq(model3), eq(true), any());
verify(trainedModelProvider, times(5)).getTrainedModel(eq(model3), eq(true), any());
}


Expand Down

0 comments on commit bbfa5be

Please sign in to comment.