Skip to content

Commit

Permalink
Fix flaky tests in ParserTest.java (apache#15318)
Browse files Browse the repository at this point in the history
Fixed the following flaky tests:

    org.apache.druid.math.expr.ParserTest#testApplyFunctions
    org.apache.druid.math.expr.ParserTest#testSimpleMultiplicativeOp1
    org.apache.druid.math.expr.ParserTest#testFunctions
    org.apache.druid.math.expr.ParserTest#testSimpleLogicalOps1
    org.apache.druid.math.expr.ParserTest#testSimpleAdditivityOp1
    org.apache.druid.math.expr.ParserTest#testSimpleAdditivityOp2

The above mentioned tests have been reported as flaky (tests assuming deterministic implementation of a non-deterministic specification ) when ran against the NonDex tool.
The tests contain assertions (Assertion 1 & Assertion 2) that compare an ArrayList created from a HashSet using the ArrayList() constructor with another List. However, HashSet does not guarantee the ordering of elements and thus resulting in these flaky tests that assume deterministic implementation of HashSet. Thus, when the NonDex tool shuffles the HashSet elements, it results in the test failures:

Co-authored-by: ythorat2 <ythorat2@illinois.edu>
  • Loading branch information
yashdeep97 and ythorat2 authored Nov 17, 2023
1 parent 77828be commit 7b5790c
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

Expand Down Expand Up @@ -820,15 +821,15 @@ private void validateParser(
}
final Expr.BindingAnalysis deets = parsed.analyzeInputs();
Assert.assertEquals(expression, expected, parsed.toString());
Assert.assertEquals(expression, identifiers, deets.getRequiredBindingsList());
Assert.assertEquals(expression, new HashSet<>(identifiers), deets.getRequiredBindings());
Assert.assertEquals(expression, scalars, deets.getScalarVariables());
Assert.assertEquals(expression, arrays, deets.getArrayVariables());

final Expr parsedNoFlatten = Parser.parse(expression, ExprMacroTable.nil(), false);
final Expr roundTrip = Parser.parse(parsedNoFlatten.stringify(), ExprMacroTable.nil());
Assert.assertEquals(parsed.stringify(), roundTrip.stringify());
final Expr.BindingAnalysis roundTripDeets = roundTrip.analyzeInputs();
Assert.assertEquals(expression, identifiers, roundTripDeets.getRequiredBindingsList());
Assert.assertEquals(expression, new HashSet<>(identifiers), roundTripDeets.getRequiredBindings());
Assert.assertEquals(expression, scalars, roundTripDeets.getScalarVariables());
Assert.assertEquals(expression, arrays, roundTripDeets.getArrayVariables());
}
Expand Down

0 comments on commit 7b5790c

Please sign in to comment.