Skip to content

Commit 1fac481

Browse files
sohaibiftikharjavanna
authored andcommitted
Improve test times for tests using RandomObjects::addFields (#31556)
Currently RandomObjects::addFields can potentially generate a large number of fields This commit decreases the chances that a new object or array is added as a new branch of an object, which lowers the probability of ending up with very big documents generated. It also reduces the number of documents generated for the SimulatePipelineResponseTests from 10 to 5 to reduce the testing time required for parsing.
1 parent 0e5d6bd commit 1fac481

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

server/src/test/java/org/elasticsearch/action/ingest/SimulateDocumentVerboseResultTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
public class SimulateDocumentVerboseResultTests extends AbstractXContentTestCase<SimulateDocumentVerboseResult> {
3232

3333
static SimulateDocumentVerboseResult createTestInstance(boolean withFailures) {
34-
int numDocs = randomIntBetween(0, 10);
34+
int numDocs = randomIntBetween(0, 5);
3535
List<SimulateProcessorResult> results = new ArrayList<>();
3636
for (int i = 0; i<numDocs; i++) {
3737
boolean isSuccessful = !(withFailures && randomBoolean());

server/src/test/java/org/elasticsearch/action/ingest/SimulatePipelineResponseTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public void testSerialization() throws IOException {
9494
}
9595

9696
static SimulatePipelineResponse createInstance(String pipelineId, boolean isVerbose, boolean withFailure) {
97-
int numResults = randomIntBetween(1, 10);
97+
int numResults = randomIntBetween(1, 5);
9898
List<SimulateDocumentResult> results = new ArrayList<>(numResults);
9999
for (int i = 0; i < numResults; i++) {
100100
if (isVerbose) {

test/framework/src/main/java/org/elasticsearch/test/RandomObjects.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,9 @@ public static BytesReference randomSource(Random random, XContentType xContentTy
187187
* Randomly adds fields, objects, or arrays to the provided builder. The maximum depth is 5.
188188
*/
189189
private static void addFields(Random random, XContentBuilder builder, int minNumFields, int currentDepth) throws IOException {
190-
int numFields = randomIntBetween(random, minNumFields, 10);
190+
int numFields = randomIntBetween(random, minNumFields, 5);
191191
for (int i = 0; i < numFields; i++) {
192-
if (currentDepth < 5 && random.nextBoolean()) {
192+
if (currentDepth < 5 && random.nextInt(100) >= 70) {
193193
if (random.nextBoolean()) {
194194
builder.startObject(RandomStrings.randomAsciiOfLengthBetween(random, 6, 10));
195195
addFields(random, builder, minNumFields, currentDepth + 1);

0 commit comments

Comments
 (0)