blob: 206d509412ac44d216b9df77e4c2d9f246fd30ea [file] [log] [blame]
Marian Harbachebeb1542019-12-13 10:42:46 +01001:linkattrs:
Marco Miller0ca836a2020-03-20 11:38:29 -04002= Gerrit Code Review - End to end tests
Fabio Ponciroli386aebb2019-05-21 20:30:41 -07003
Marco Miller0ca836a2020-03-20 11:38:29 -04004This document provides descriptions of Gerrit end-to-end (`e2e`) test scenarios implemented using
Marco Millerfaa512f2020-03-24 15:13:18 -04005the link:https://gatling.io/[Gatling,role=external,window=_blank] framework.
Fabio Ponciroli386aebb2019-05-21 20:30:41 -07006
Marco Miller9a9d42f2020-01-30 08:53:21 -05007Similar scenarios have been successfully used to compare performance of different Gerrit versions
Marco Miller0ca836a2020-03-20 11:38:29 -04008or study the Gerrit response under different load profiles. Although mostly for load, scenarios can
David Pursehouse4655c8e2020-03-24 08:38:25 +09009either be for link:https://gatling.io/load-testing-continuous-integration/[load or functional,role=external,window=_blank]
Marco Miller0ca836a2020-03-20 11:38:29 -040010(e2e) testing purposes. Functional scenarios may then reuse this framework and Gatling's usability
11features such as its protocols (more below) and
David Pursehouse4655c8e2020-03-24 08:38:25 +090012link:https://en.wikipedia.org/wiki/Domain-specific_language[DSL,role=external,window=_blank].
Marco Miller0ca836a2020-03-20 11:38:29 -040013
14That cross test-scope reusability applies to both Gerrit core scenarios and non-core ones, such as
15for Gerrit plugins or other potential extensions. End-to-end testing may then include scopes like
16feature integration, deployment, smoke (and load) testing. These load and functional test scopes
17should remain orthogonal to the unit and component (aka Gerrit `IT`-suffixed or `acceptance`) ones.
18The term `acceptance` though may still be coined by organizations to target e2e functional testing.
Fabio Ponciroli386aebb2019-05-21 20:30:41 -070019
20== What is Gatling?
21
Marco Miller0ca836a2020-03-20 11:38:29 -040022Gatling is mostly a load testing tool which provides out of the box support for the HTTP protocol.
Marco Miller9a9d42f2020-01-30 08:53:21 -050023Documentation on how to write an HTTP load test can be found
Marco Miller7c41df72020-01-30 15:58:32 -050024link:https://gatling.io/docs/current/http/http_protocol/[here,role=external,window=_blank].
David Pursehouse4655c8e2020-03-24 08:38:25 +090025However, in the scenarios that were initially proposed, the
26link:https://github.com/GerritForge/gatling-git[Gatling Git extension,role=external,window=_blank] was
Marco Miller0ca836a2020-03-20 11:38:29 -040027leveraged to run tests at the Git protocol level.
Fabio Ponciroli386aebb2019-05-21 20:30:41 -070028
Marco Miller9a9d42f2020-01-30 08:53:21 -050029Gatling is written in Scala, but the abstraction provided by the Gatling DSL makes the scenarios
Marco Miller6c2c5eb2020-08-27 14:11:36 -040030implementation easy even without any Scala knowledge. The online `End-to-end tests`
Marco Millerd1839872020-09-03 17:46:24 -040031link:https://www.gerritcodereview.com/presentations.html#list-of-presentations[presentation,role=external,window=_blank]
32links posted on the homepage have more introductory information.
Fabio Poncirolie2244562019-05-21 20:30:41 -070033
Hamza Kaced2e37e272020-07-30 23:18:39 -040034== IDE: IntelliJ
Fabio Ponciroli386aebb2019-05-21 20:30:41 -070035
Marco Miller0ca836a2020-03-20 11:38:29 -040036Examples of scenarios can be found in the `e2e-tests` directory. The files in that directory should
37be formatted using the mainstream
David Pursehouse9b020572020-02-03 08:33:49 +090038link:https://plugins.jetbrains.com/plugin/1347-scala[Scala plugin for IntelliJ,role=external,window=_blank].
39The latter is not mandatory but preferred for `sbt` and Scala IDE purposes in this project.
Marco Millerd1839872020-09-03 17:46:24 -040040So, Eclipse can also be used alongside as a development IDE; this is described below.
Hamza Kaced2e37e272020-07-30 23:18:39 -040041
42=== Eclipse
43
Marco Millerd1839872020-09-03 17:46:24 -0400441. Install the link:http://scala-ide.org/docs/user/gettingstarted.html[Scala plugin for Eclipse,role=external,window=_blank].
Hamza Kaced2e37e272020-07-30 23:18:39 -0400451. Run `sbt eclipse` from the `e2e-tests` root directory.
461. Import the resulting `e2e-tests` eclipse file inside the Gerrit project, in Eclipse.
471. You should see errors in Eclipse telling you there are missing packages.
481. This is due to the sbt-eclipse plugin not properly linking the Gerrit Gatling e2e tests with
49 Gatling Git plugin.
501. You then have to right-click on the root directory and choose the build path->link source option.
511. Then you have to browse to `.sbt/1.0/staging`, find the folder where gatling-git is contained,
52 and choose that.
531. That last step should link the gatling-git plugin to the project; e2e tests should not show
54 errors anymore.
551. You may get errors in the gatling-git directory; these should not affect Gerrit Gatling
56 development and can be ignored.
Fabio Ponciroli386aebb2019-05-21 20:30:41 -070057
Marco Miller62c30e52020-01-30 15:45:02 -050058== How to build the tests
Fabio Ponciroli386aebb2019-05-21 20:30:41 -070059
Marco Miller7c41df72020-01-30 15:58:32 -050060An link:https://www.scala-sbt.org/download.html[sbt-based installation,role=external,window=_blank]
61of link:https://www.scala-lang.org/download/[Scala,role=external,window=_blank] is required.
Fabio Ponciroli386aebb2019-05-21 20:30:41 -070062
Marco Miller9a9d42f2020-01-30 08:53:21 -050063The `scalaVersion` used by `sbt` once installed is defined in the `build.sbt` file. That specific
64version of Scala is automatically used by `sbt` while building:
Marco Miller0b6dd4b2020-01-29 17:24:17 -050065
Fabio Ponciroli386aebb2019-05-21 20:30:41 -070066----
67sbt compile
68----
69
Marco Miller0499d242020-01-30 11:44:27 -050070The following warning, if present when executing `sbt` commands, can be removed by creating the
Marco Miller7c41df72020-01-30 15:58:32 -050071link:https://www.scala-sbt.org/1.x/docs/Using-Sonatype.html#step+3%3A+Credentials[related credentials file,role=external,window=_blank]
Marco Millerd890da52020-01-31 11:08:42 -050072locally. Dummy values for `user` and `password` in that file can be used initially.
Marco Miller0499d242020-01-30 11:44:27 -050073
74----
75[warn] Credentials file ~/.sbt/sonatype_credentials does not exist
76----
77
Marco Millerb7c5dd02020-03-27 17:27:36 -040078The other warning below can be safely ignored, so far. Running the proposed `sbt evicted` command
79should only list `scala-java8-compat_2.12` as `[warn]`. The other dependency conflicts should show
80as `[info]`. All of the listed conflicts get usually resolved seamlessly or so.
81
82----
83[warn] There may be incompatibilities among your library dependencies; run 'evicted' to see detailed eviction warnings.
84----
85
Marco Miller51820c72020-01-30 17:21:18 -050086Every `sbt` command can include an optional log level
Marco Millerd421f802020-01-30 18:19:39 -050087link:https://www.scala-sbt.org/1.x/docs/Howto-Logging.html#Change+the+logging+level+globally[argument,role=external,window=_blank].
Marco Miller51820c72020-01-30 17:21:18 -050088Below, `[info]` logs are no longer shown:
89
90----
91sbt --warn compile
92----
93
Marco Miller62c30e52020-01-30 15:45:02 -050094=== How to build using Docker
Marco Miller75a60462020-01-30 12:14:15 -050095
96----
97docker build . -t e2e-tests
98----
99
Marco Miller62c30e52020-01-30 15:45:02 -0500100== How to set-up
101
102=== SSH keys
Fabio Ponciroli386aebb2019-05-21 20:30:41 -0700103
Marco Millerccd78552020-01-29 17:36:08 -0500104If you are running SSH commands, the private keys of the users used for testing need to go in
105`/tmp/ssh-keys`. The keys need to be generated this way (JSch won't validate them
David Pursehouse8d9c8a82020-01-30 15:11:45 +0900106link:https://stackoverflow.com/questions/53134212/invalid-privatekey-when-using-jsch[otherwise,role=external,window=_blank]):
Fabio Ponciroli386aebb2019-05-21 20:30:41 -0700107
108----
Marco Millerf00947e2020-01-31 14:35:58 -0500109mkdir /tmp/ssh-keys
Fabio Ponciroli386aebb2019-05-21 20:30:41 -0700110ssh-keygen -m PEM -t rsa -C "test@mail.com" -f /tmp/ssh-keys/id_rsa
111----
112
Marco Millerf00947e2020-01-31 14:35:58 -0500113The public key in `/tmp/ssh-keys/id_rsa.pub` has to be added to the test user(s) `SSH Keys` in
114Gerrit. Now, the host from which the latter runs may need public key scanning to become known.
115This applies to the local user that runs the forthcoming `sbt` testing commands. An example
116assuming `localhost` follows:
117
118----
119ssh-keyscan -t rsa -p 29418 localhost > ~/.ssh/known_hosts
120----
Fabio Ponciroli386aebb2019-05-21 20:30:41 -0700121
Marco Miller62c30e52020-01-30 15:45:02 -0500122=== Input file
Fabio Ponciroli386aebb2019-05-21 20:30:41 -0700123
Marco Miller3f46efd2020-02-01 11:06:11 -0500124The `CloneUsingBothProtocols` scenario is fed with the data coming from the
Marco Miller28c26cd2020-03-19 16:41:25 -0400125`src/test/resources/data/com/google/gerrit/scenarios/CloneUsingBothProtocols.json` file. Such a
Marco Miller0ca836a2020-03-20 11:38:29 -0400126file contains the commands and repository used during the e2e test. That file currently looks like
Marco Miller28c26cd2020-03-19 16:41:25 -0400127below. This scenario serves as a simple example with no actual load in it. It can be used to test
128or validate the local setup. More complex scenarios can be further developed, under the
Marco Miller6ba23762020-04-02 14:07:29 -0400129`com.google.gerrit.scenarios` package. The uppercase keywords are discussed further below.
Fabio Ponciroli386aebb2019-05-21 20:30:41 -0700130
131----
132[
133 {
Marco Millerb39b7942020-04-03 15:21:22 -0400134 "url": "ssh://admin@HOSTNAME:SSH_PORT/_PROJECT",
Fabio Ponciroli386aebb2019-05-21 20:30:41 -0700135 "cmd": "clone"
136 },
137 {
Marco Millera543a932020-07-15 13:45:31 -0400138 "url": "HTTP_SCHEME://HOSTNAME:HTTP_PORT/_PROJECT",
Marco Miller3f46efd2020-02-01 11:06:11 -0500139 "cmd": "clone"
Fabio Ponciroli386aebb2019-05-21 20:30:41 -0700140 }
141]
142----
143
144Valid commands are:
Marco Millerc00b0182020-01-29 17:56:05 -0500145
Marco Millercc4810b2020-02-13 13:06:41 -0500146* `clone`
Marco Millerc00b0182020-01-29 17:56:05 -0500147* `fetch`
148* `pull`
149* `push`
Fabio Ponciroli386aebb2019-05-21 20:30:41 -0700150
Marco Millerf5eb7e42020-03-12 15:05:26 -0400151=== Project and HTTP credentials
152
Marco Millercc4810b2020-02-13 13:06:41 -0500153The example above assumes that the `loadtest-repo` project exists in the Gerrit under test. The
Marco Millerf5eb7e42020-03-12 15:05:26 -0400154`CloneUsingBothProtocols` scenario already includes creating that project and deleting it once done
155with it. That scenario class can be used as an example of how a scenario can compose itself
156alongside other scenarios (here, `CreateProject` and `DeleteProject`).
157
158The `HTTP Credentials` or password obtained from test user's `Settings` (in Gerrit) may be
159required, in `src/test/resources/application.conf`, depending on the above commands used. That
160file's `http` section shows which shell environment variables can be used to set those credentials.
161
162Executing the `CloneUsingBothProtocols` scenario, as is, does require setting the http credentials.
163That is because of the aforementioned create/delete project (http) scenarios composed within it.
Marco Millerd92fae82020-01-31 14:45:28 -0500164
Marco Miller6ba23762020-04-02 14:07:29 -0400165=== Environment properties
166
167The `JAVA_OPTS` environment variable
Marco Miller74720262020-04-28 16:51:43 -0400168link:https://gatling.io/docs/current/cookbook/passing_parameters[can optionally be used,role=external,window=_blank]
169to define non-default values for keys found in scenario `json` data files. That variable can
170currently be set with either one or many of these supported properties, from the core framework:
Marco Miller6ba23762020-04-02 14:07:29 -0400171
172* `-Dcom.google.gerrit.scenarios.hostname=localhost`
173* `-Dcom.google.gerrit.scenarios.ssh_port=29418`
174* `-Dcom.google.gerrit.scenarios.http_port=8080`
Marco Millera543a932020-07-15 13:45:31 -0400175* `-Dcom.google.gerrit.scenarios.http_scheme=http`
Marco Miller6ba23762020-04-02 14:07:29 -0400176
177Above, the properties can be set with values matching specific deployment topologies under test.
Marco Millera543a932020-07-15 13:45:31 -0400178The example values shown above are the currently coded default ones. For example, the `http` scheme
179above could be replaced with `https`. The framework could support differing or more properties over
180time.
Marco Miller16406aa2020-04-03 11:26:45 -0400181
182Plugin or otherwise non-core scenarios may do so just as well. The core java package
183`com.google.gerrit.scenarios` from the example above has to be replaced with the one under which
184those scenario classes are. Such extending scenarios can also add extension-specific properties.
185Early examples of this can be found in the Gerrit
Marco Miller6f4534c2020-04-04 10:09:39 -0400186`link:https://gerrit.googlesource.com/plugins/high-availability[high-availability,role=external,window=_blank]`
187and `link:https://gerrit.googlesource.com/plugins/multi-site[multi-site,role=external,window=_blank]`
188plugins test code.
Marco Miller6ba23762020-04-02 14:07:29 -0400189
Marco Millerb39b7942020-04-03 15:21:22 -0400190Further above, the `_PROJECT` keyword is prefixed with an underscore, which means that its value
191gets automatically generated by the scenario. Any property setting for it is therefore not
192applicable. Its usage differs from the non-prefixed `PROJECT` keyword, in that sense.
Fabio Poncirolie2244562019-05-21 20:30:41 -0700193
Marco Miller0b2c50a2020-04-17 14:04:08 -0400194The following core property can be optionally set depending on the runtime environment. The test
195environments used as reference for scenarios development assume its default value, `1.0`. For
196slower or more complex execution environments, the value can be increased this way for example:
197
198* `-Dcom.google.gerrit.scenarios.power_factor=1.5`
199
200This will make the scenario steps take half more time to expect proper completion. A value smaller
201than the default, say `0.8`, will make scenarios wait somewhat less than how they were developed.
202Scenario development is often done using locally running Gerrit systems under test, which are
203sometimes dockerized.
204
Marco Miller62c30e52020-01-30 15:45:02 -0500205== How to run tests
Fabio Ponciroli386aebb2019-05-21 20:30:41 -0700206
207Run all tests:
208----
209sbt "gatling:test"
210----
211
212Run a single test:
213----
Marco Miller3f46efd2020-02-01 11:06:11 -0500214sbt "gatling:testOnly com.google.gerrit.scenarios.CloneUsingBothProtocols"
Fabio Ponciroli386aebb2019-05-21 20:30:41 -0700215----
216
217Generate the last report:
218----
219sbt "gatling:lastReport"
220----
221
Marco Miller51820c72020-01-30 17:21:18 -0500222The `src/test/resources/logback.xml` file
Marco Millerd421f802020-01-30 18:19:39 -0500223link:http://logback.qos.ch/manual/configuration.html[configures,role=external,window=_blank]
Marco Miller74720262020-04-28 16:51:43 -0400224Gatling's logging level. To quickly enable
225link:https://gatling.io/docs/current/general/debugging#logback[detailed logging,role=external,window=_blank]
226of `http` requests and responses, the `root level` can be set to `trace` in that file.
Marco Miller51820c72020-01-30 17:21:18 -0500227
Marco Miller62c30e52020-01-30 15:45:02 -0500228=== How to run using Docker
Marco Miller75a60462020-01-30 12:14:15 -0500229
230----
Marco Miller3f46efd2020-02-01 11:06:11 -0500231docker run -it e2e-tests -s com.google.gerrit.scenarios.CloneUsingBothProtocols
Marco Miller75a60462020-01-30 12:14:15 -0500232----
233
Marco Miller61ccca52020-03-18 09:59:59 -0400234=== How to run non-core scenarios
235
236Locally adding non-core scenarios, for example from Gerrit plugins, is as simple as copying such
237files in. Copying is necessary over linking, unless running using Docker (above) is not required.
238Docker does not support links for files it has to copy over through the Dockerfile (here, the
239scenario files). Here is how to proceed for adding such external (e.g., plugin) scenario files in:
240
241----
242pushd e2e-tests/src/test/scala
243cp -r (or, ln -s) scalaPackageStructure .
244popd
245
246pushd e2e-tests/src/test/resources/data
247cp -r (or, ln -s) jsonFilesPackageStructure .
248popd
249----
250
251The destination folders above readily git-ignore every non-core scenario file added under them. If
252running using Docker, `e2e-tests/Dockerfile` may require another `COPY` line for the hereby added
253scenarios. Aforementioned `sbt` or `docker` commands can then be used to run the added tests.
254
Fabio Ponciroli386aebb2019-05-21 20:30:41 -0700255GERRIT
256------
257Part of link:index.html[Gerrit Code Review]
258
259SEARCHBOX
260---------
261
262[scala]: