TESTING.asciidoc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. [[Testing Framework Cheatsheet]]
  2. = Testing
  3. [partintro]
  4. Elasticsearch uses jUnit for testing, it also uses randomness in the
  5. tests, that can be set using a seed, the following is a cheatsheet of
  6. options for running the tests for ES.
  7. == Creating packages
  8. To create a distribution without running the tests, simply run the
  9. following:
  10. -----------------------------
  11. mvn clean package -DskipTests
  12. -----------------------------
  13. == Other test options
  14. To disable and enable network transport, set the `Des.node.mode`.
  15. Use network transport:
  16. ------------------------------------
  17. -Des.node.mode=network
  18. ------------------------------------
  19. Use local transport (default since 1.3):
  20. -------------------------------------
  21. -Des.node.mode=local
  22. -------------------------------------
  23. Alternatively, you can set the `ES_TEST_LOCAL` environment variable:
  24. -------------------------------------
  25. export ES_TEST_LOCAL=true && mvn test
  26. -------------------------------------
  27. === Running Elasticsearch from a checkout
  28. In order to run Elasticsearch from source without building a package, you can
  29. run it using Maven:
  30. -------------------------------------
  31. mvn compile exec:exec
  32. -------------------------------------
  33. === Test case filtering.
  34. - `tests.class` is a class-filtering shell-like glob pattern,
  35. - `tests.method` is a method-filtering glob pattern.
  36. Run a single test case (variants)
  37. ----------------------------------------------------------
  38. mvn test -Dtests.class=org.elasticsearch.package.ClassName
  39. mvn test "-Dtests.class=*.ClassName"
  40. ----------------------------------------------------------
  41. Run all tests in a package and sub-packages
  42. ----------------------------------------------------
  43. mvn test "-Dtests.class=org.elasticsearch.package.*"
  44. ----------------------------------------------------
  45. Run any test methods that contain 'esi' (like: ...r*esi*ze...).
  46. -------------------------------
  47. mvn test "-Dtests.method=*esi*"
  48. -------------------------------
  49. You can also filter tests by certain annotations ie:
  50. * `@Slow` - tests that are know to take a long time to execute
  51. * `@Nightly` - tests that only run in nightly builds (disabled by default)
  52. * `@Integration` - integration tests
  53. * `@Backwards` - backwards compatibility tests (disabled by default)
  54. * `@AwaitsFix` - tests that are waiting for a bugfix (disabled by default)
  55. * `@BadApple` - tests that are known to fail randomly (disabled by default)
  56. Those annotation names can be combined into a filter expression like:
  57. ------------------------------------------------
  58. mvn test -Dtests.filter="@nightly and not @slow"
  59. ------------------------------------------------
  60. to run all nightly test but not the ones that are slow. `tests.filter` supports
  61. the boolean operators `and, or, not` and grouping ie:
  62. ---------------------------------------------------------------
  63. mvn test -Dtests.filter="@nightly and not(@slow or @backwards)"
  64. ---------------------------------------------------------------
  65. === Seed and repetitions.
  66. Run with a given seed (seed is a hex-encoded long).
  67. ------------------------------
  68. mvn test -Dtests.seed=DEADBEEF
  69. ------------------------------
  70. === Repeats _all_ tests of ClassName N times.
  71. Every test repetition will have a different method seed
  72. (derived from a single random master seed).
  73. --------------------------------------------------
  74. mvn test -Dtests.iters=N -Dtests.class=*.ClassName
  75. --------------------------------------------------
  76. === Repeats _all_ tests of ClassName N times.
  77. Every test repetition will have exactly the same master (0xdead) and
  78. method-level (0xbeef) seed.
  79. ------------------------------------------------------------------------
  80. mvn test -Dtests.iters=N -Dtests.class=*.ClassName -Dtests.seed=DEAD:BEEF
  81. ------------------------------------------------------------------------
  82. === Repeats a given test N times
  83. (note the filters - individual test repetitions are given suffixes,
  84. ie: testFoo[0], testFoo[1], etc... so using testmethod or tests.method
  85. ending in a glob is necessary to ensure iterations are run).
  86. -------------------------------------------------------------------------
  87. mvn test -Dtests.iters=N -Dtests.class=*.ClassName -Dtests.method=mytest*
  88. -------------------------------------------------------------------------
  89. Repeats N times but skips any tests after the first failure or M initial failures.
  90. -------------------------------------------------------------
  91. mvn test -Dtests.iters=N -Dtests.failfast=true -Dtestcase=...
  92. mvn test -Dtests.iters=N -Dtests.maxfailures=M -Dtestcase=...
  93. -------------------------------------------------------------
  94. === Test groups.
  95. Test groups can be enabled or disabled (true/false).
  96. Default value provided below in [brackets].
  97. ------------------------------------------------------------------
  98. mvn test -Dtests.nightly=[false] - nightly test group (@Nightly)
  99. mvn test -Dtests.weekly=[false] - weekly tests (@Weekly)
  100. mvn test -Dtests.awaitsfix=[false] - known issue (@AwaitsFix)
  101. mvn test -Dtests.slow=[true] - slow tests (@Slow)
  102. ------------------------------------------------------------------
  103. === Load balancing and caches.
  104. By default, the tests run sequentially on a single forked JVM.
  105. To run with more forked JVMs than the default use:
  106. ----------------------------
  107. mvn test -Dtests.jvms=8 test
  108. ----------------------------
  109. Don't count hypercores for CPU-intense tests and leave some slack
  110. for JVM-internal threads (like the garbage collector). Make sure there is
  111. enough RAM to handle child JVMs.
  112. === Test compatibility.
  113. It is possible to provide a version that allows to adapt the tests behaviour
  114. to older features or bugs that have been changed or fixed in the meantime.
  115. -----------------------------------------
  116. mvn test -Dtests.compatibility=1.0.0
  117. -----------------------------------------
  118. === Miscellaneous.
  119. Run all tests without stopping on errors (inspect log files).
  120. -----------------------------------------
  121. mvn test -Dtests.haltonfailure=false test
  122. -----------------------------------------
  123. Run more verbose output (slave JVM parameters, etc.).
  124. ----------------------
  125. mvn test -verbose test
  126. ----------------------
  127. Change the default suite timeout to 5 seconds for all
  128. tests (note the exclamation mark).
  129. ---------------------------------------
  130. mvn test -Dtests.timeoutSuite=5000! ...
  131. ---------------------------------------
  132. Change the logging level of ES (not mvn)
  133. --------------------------------
  134. mvn test -Des.logger.level=DEBUG
  135. --------------------------------
  136. Print all the logging output from the test runs to the commandline
  137. even if tests are passing.
  138. ------------------------------
  139. mvn test -Dtests.output=always
  140. ------------------------------
  141. Configure the heap size.
  142. ------------------------------
  143. mvn test -Dtests.heap.size=512m
  144. ------------------------------
  145. Pass arbitrary jvm arguments.
  146. ------------------------------
  147. mvn test -Dtests.jvm.argline="-XX:HeapDumpPath=/path/to/heapdumps"
  148. ------------------------------
  149. == Backwards Compatibility Tests
  150. Running backwards compatibility tests is disabled by default since it
  151. requires a release version of elasticsearch to be present on the test system.
  152. To run backwards compatibilty tests untar or unzip a release and run the tests
  153. with the following command:
  154. ---------------------------------------------------------------------------
  155. mvn test -Dtests.filter="@backwards" -Dtests.bwc.version=x.y.z -Dtests.bwc.path=/path/to/elasticsearch -Dtests.security.manager=false
  156. ---------------------------------------------------------------------------
  157. Note that backwards tests must be run with security manager disabled.
  158. If the elasticsearch release is placed under `./backwards/elasticsearch-x.y.z` the path
  159. can be omitted:
  160. ---------------------------------------------------------------------------
  161. mvn test -Dtests.filter="@backwards" -Dtests.bwc.version=x.y.z -Dtests.security.manager=false
  162. ---------------------------------------------------------------------------
  163. To setup the bwc test environment execute the following steps (provided you are
  164. already in your elasticsearch clone):
  165. ---------------------------------------------------------------------------
  166. $ mkdir backwards && cd backwards
  167. $ curl -O https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.2.1.tar.gz
  168. $ tar -xzf elasticsearch-1.2.1.tar.gz
  169. ---------------------------------------------------------------------------
  170. == Testing the REST layer
  171. The available integration tests make use of the java API to communicate with
  172. the elasticsearch nodes, using the internal binary transport (port 9300 by
  173. default).
  174. The REST layer is tested through specific tests that are shared between all
  175. the elasticsearch official clients and consist of YAML files that describe the
  176. operations to be executed and the obtained results that need to be tested.
  177. The REST tests are run automatically when executing the maven test command. To run only the
  178. REST tests use the following command:
  179. ---------------------------------------------------------------------------
  180. mvn test -Dtests.filter="@Rest"
  181. ---------------------------------------------------------------------------
  182. `ElasticsearchRestTests` is the executable test class that runs all the
  183. yaml suites available within the `rest-api-spec` folder.
  184. The REST tests support all the options provided by the randomized runner, plus the following:
  185. * `tests.rest[true|false]`: determines whether the REST tests need to be run (default) or not.
  186. * `tests.rest.suite`: comma separated paths of the test suites to be run
  187. (by default loaded from /rest-api-spec/test). It is possible to run only a subset
  188. of the tests providing a sub-folder or even a single yaml file (the default
  189. /rest-api-spec/test prefix is optional when files are loaded from classpath)
  190. e.g. -Dtests.rest.suite=index,get,create/10_with_id
  191. * `tests.rest.blacklist`: comma separated globs that identify tests that are
  192. blacklisted and need to be skipped
  193. e.g. -Dtests.rest.blacklist=index/*/Index document,get/10_basic/*
  194. * `tests.rest.spec`: REST spec path (default /rest-api-spec/api)
  195. Note that the REST tests, like all the integration tests, can be run against an external
  196. cluster by specifying the `tests.cluster` property, which if present needs to contain a
  197. comma separated list of nodes to connect to (e.g. localhost:9300). A transport client will
  198. be created based on that and used for all the before|after test operations, and to extract
  199. the http addresses of the nodes so that REST requests can be sent to them.
  200. == Skip validate
  201. To disable validation step (forbidden API or `// NOCOMMIT`) use
  202. ---------------------------------------------------------------------------
  203. mvn test -Dvalidate.skip=true
  204. ---------------------------------------------------------------------------
  205. You can also skip this by using the "dev" profile:
  206. ---------------------------------------------------------------------------
  207. mvn test -Pdev
  208. ---------------------------------------------------------------------------
  209. == Testing scripts
  210. Shell scripts can be tested with the Bash Automate Testing System tool available
  211. at https://github.com/sstephenson/bats. Once the tool is installed, you can
  212. execute a .bats test file with the following command:
  213. ---------------------------------------------------------------------------
  214. bats test_file.bats
  215. ---------------------------------------------------------------------------
  216. When executing the test files located in the `/packaging/scripts` folder,
  217. it's possible to add the flag `ES_CLEAN_BEFORE_TEST=true` to clean the test
  218. environment before the tests are executed:
  219. ---------------------------------------------------------------------------
  220. ES_CLEAN_BEFORE_TEST=true bats 30_deb_package.bats
  221. ---------------------------------------------------------------------------