Skip to content

Commit

Permalink
Protect ScriptedMetricIT test cases against failures on 0-doc shards (#…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
rationull authored and jasontedor committed Aug 21, 2018
1 parent 93ed36d commit aecc997
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,14 @@ protected Map<String, Function<Map<String, Object>, Object>> pluginScripts() {
aggScript(vars, state -> state.put((String) XContentMapValues.extractValue("params.param1", vars),
XContentMapValues.extractValue("params.param2", vars))));

scripts.put("vars.multiplier = 3", vars ->
((Map<String, Object>) vars.get("vars")).put("multiplier", 3));
scripts.put("vars.multiplier = 3", vars -> {
((Map<String, Object>) vars.get("vars")).put("multiplier", 3);

Map<String, Object> state = (Map<String, Object>) vars.get("state");
state.put("list", new ArrayList());

return state;
});

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

0 comments on commit aecc997

Please sign in to comment.