Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky EvalMinifierTest #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

219sansim
Copy link

Description

There are some assertions in the test testMinify which rely on the fact that iterating over the pool map returns elements in a consistent order. However, a HashMap may return different orders of the tokens. Instead a better Map to use is LinkedHashMap which ensures that the token keys are returned in a consistent order.

assertMinified(
"(function(a,b){return"
+ "[a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,\"z\"]"
+ "}(\"foo\",\"bar\"))",
"['foo','bar','foo','bar','foo','bar','foo','bar','foo','bar','foo',"
+ "'bar','foo','bar','foo','bar','foo','bar','foo','bar','foo','z']");

Motivation and Context

There is a flaky test detected in EvalMinifierTest.java - testMinify. This test may sometimes fail since it assumes that iterating over the Map keys will be the same as their inserting order.

Another, way to resolve this error could be to change the test in such a way that the assertions don't assume a particular order of the keys.

How Has This Been Tested?

Reproduction of error
Run maven tests with NonDex tool

mvn edu.illinois:nondex-maven-plugin:2.1.1:nondex -Dtest=com.google.json.EvalMinifierTest

The test passes after changing the HashMap to LinkedHashMap
Error Output

Running com.google.json.EvalMinifierTest
Tests run: 2, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.012 sec <<< FAILURE!
testMinify(com.google.json.EvalMinifierTest)  Time elapsed: 0.002 sec  <<< FAILURE!
junit.framework.ComparisonFailure: ['foo','bar','foo','bar','foo','bar','foo','bar','foo','bar','foo','bar','foo','bar','foo','bar','foo','bar','foo','bar','foo','z'] expected:<...unction(a,b){return[[a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,"z"]}("foo","bar]"))> but was:<...unction(a,b){return[[b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,"z"]}("bar","foo]"))>

@dbelyaev
Copy link

@mikesamuel can you review this PR and eventually merge?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants