diff --git a/core/src/test/java/org/elasticsearch/index/get/DocumentFieldTests.java b/core/src/test/java/org/elasticsearch/index/get/DocumentFieldTests.java index 0b8549e005367..9d581054f46b8 100644 --- a/core/src/test/java/org/elasticsearch/index/get/DocumentFieldTests.java +++ b/core/src/test/java/org/elasticsearch/index/get/DocumentFieldTests.java @@ -86,7 +86,16 @@ private static DocumentField mutateDocumentField(DocumentField documentField) { List> mutations = new ArrayList<>(); mutations.add(() -> new DocumentField(randomUnicodeOfCodepointLength(15), documentField.getValues())); mutations.add(() -> new DocumentField(documentField.getName(), randomDocumentField(XContentType.JSON).v1().getValues())); - return randomFrom(mutations).get(); + final int index = randomFrom(0, 1); + final DocumentField randomCandidate = mutations.get(index).get(); + if (!documentField.equals(randomCandidate)) { + return randomCandidate; + } else { + // we are unlucky and our random mutation is equal to our mutation, try the other candidate + final DocumentField otherCandidate = mutations.get(1 - index).get(); + assert !documentField.equals(otherCandidate) : documentField; + return otherCandidate; + } } public static Tuple randomDocumentField(XContentType xContentType) {