Skip to content

Commit 676091a

Browse files
rationullcolings86
authored andcommitted
Protect ScriptedMetricIT test cases against failures on 0-doc shards (#32959) (#32968)
Randomized test conditions that cause some shards to have no docs on them failed due to test asserts that relied on a lazy initialization side effect from the map script. After this fix: - Test cases with the relevant init script are protected - Test cases with the relevant combine or reduce scripts were already protected, because the combine and reduce scripts safely handle this case.
1 parent e143cce commit 676091a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

server/src/test/java/org/elasticsearch/search/aggregations/metrics/ScriptedMetricIT.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,14 @@ protected Map<String, Function<Map<String, Object>, Object>> pluginScripts() {
108108
aggScript(vars, state -> state.put((String) XContentMapValues.extractValue("params.param1", vars),
109109
XContentMapValues.extractValue("params.param2", vars))));
110110

111-
scripts.put("vars.multiplier = 3", vars ->
112-
((Map<String, Object>) vars.get("vars")).put("multiplier", 3));
111+
scripts.put("vars.multiplier = 3", vars -> {
112+
((Map<String, Object>) vars.get("vars")).put("multiplier", 3);
113+
114+
Map<String, Object> state = (Map<String, Object>) vars.get("state");
115+
state.put("list", new ArrayList());
116+
117+
return state;
118+
});
113119

114120
scripts.put("state.list.add(vars.multiplier)", vars ->
115121
aggScript(vars, state -> {

0 commit comments

Comments
 (0)