Skip to content

Conversation

@cbuescher
Copy link
Member

Currently we use Math.random() in a few places in the tests which makes these
tests not reproducable with the random seed mechanism that comes with
ESTestCase. The change removes those instances.

Currently we use Math.random() in a few places in the tests which makes these
tests not reproducable with the random seed mechanism that comes with
ESTestCase. The change removes those instances.
@cbuescher cbuescher added >test Issues or PRs that are addressing/adding tests :Search/Search Search-related issues that do not fall into other categories v7.0.0 v6.6.0 labels Dec 4, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search

Copy link
Contributor

@jtibshirani jtibshirani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good to me, just left one comment.

value = Math.random() * 10;
array[i] = value + ((randomFreq(0.5) ? 1 : -1) * Math.random() * tolerance);
if (frequently()) {
value = randomIntBetween(0, 10);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To match the old behavior I think this should be randomDoubleBetween(0, 10, true).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I missed this being a double. Upon further inspection I now think it should be randomDoubleBetween(0, 9, true) but including the edge values of the interval shouldn't really matter here.

@cbuescher
Copy link
Member Author

run the gradle build tests 1 and the gradle build tests 2

@cbuescher
Copy link
Member Author

@elasticmachine run the gradle build tests 2

@jpountz
Copy link
Contributor

jpountz commented Dec 5, 2018

Should it be a forbidden API for tests?

@cbuescher
Copy link
Member Author

@jpountz good idea, but I didn't go into how to add this solely for the tests, not sure if this is possible. I will check and open a separate PR if it is easily done. There are some usages of Math.random() in o.e.search.aggregations.pipeline e.g. in the HoltWintersModel so we cannot generally block its use in the whole codebase.

@jpountz
Copy link
Contributor

jpountz commented Dec 5, 2018

You can add forbidden APIs for tests only by adding them to buildSrc/src/main/resources/forbidden/es-test-signatures.txt.

value = Math.random() * 10;
array[i] = value + ((randomFreq(0.5) ? 1 : -1) * Math.random() * tolerance);
if (frequently()) {
value = randomDoubleBetween(0, 9, true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wasn't the test generating doubles between 0 and 10 before? (it might not matter)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Math.random() -> "a pseudorandom {@code double} greater than or equal to {@code 0.0} and less than {@code 1.0}", so I think 10 wasn't included. But yes, I agree it probably doesn't matter at all ;-)

@cbuescher
Copy link
Member Author

@elasticmachine run the gradle build tests 2

1 similar comment
@cbuescher
Copy link
Member Author

@elasticmachine run the gradle build tests 2

@cbuescher cbuescher merged commit 7563525 into elastic:master Dec 5, 2018
cbuescher pushed a commit that referenced this pull request Dec 5, 2018
Currently we use Math.random() in a few places in the tests which makes these
tests not reproducable with the random seed mechanism that comes with
ESTestCase. The change removes those instances.
jasontedor added a commit to jasontedor/elasticsearch that referenced this pull request Dec 6, 2018
* master: (133 commits)
  SNAPSHOT: Increase Timeout to Stabilize Test (elastic#36294)
  Fix get certificates HLRC API (elastic#36198)
  Avoid shutting down the only master (elastic#36272)
  Fix typo in comment
  Fix total hits serialization of the search response (elastic#36290)
  Fix FullClusterRestartIT#testRollupIDSchemeAfterRestart
  Mute FullClusterRestartIT#testRollupIDSchemeAfterRestart as we await a fix.
  [Docs] Add Profile API limitations (elastic#36252)
  Make sure test don't use Math.random for reproducability (elastic#36241)
  Fix compilation
  ingest: support default pipeline through an alias (elastic#36231)
  Zen2: Rename tombstones to exclusions (elastic#36226)
  [Zen2] Hide not recovered state (elastic#36224)
  Test: mute testDataNodeRestartWithBusyMasterDuringSnapshot
  Test: mute testSnapshotAndRestoreWithNested
  Revert "Test: mute failing mtermvector rest test"
  Test: mute failing mtermvector rest test
  add version 6.5.3 (elastic#36268)
  Make hits.total an object in the search response (elastic#35849)
  [DOCS] Fixes broken link in execute watch
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Search/Search Search-related issues that do not fall into other categories >test Issues or PRs that are addressing/adding tests v6.6.0 v7.0.0-beta1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants