blob: 1151f1c81bc4609997b8542384acc904deae59c2 [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].
Marco Miller4f898442020-09-29 14:18:51 -0400452. Run `sbt eclipse` from the `e2e-tests` root directory.
463. Import the resulting `e2e-tests` eclipse file inside the Gerrit project, in Eclipse.
474. You should see errors in Eclipse telling you there are missing packages.
485. This is due to the sbt-eclipse plugin not properly linking the Gerrit Gatling e2e tests with
Hamza Kaced2e37e272020-07-30 23:18:39 -040049 Gatling Git plugin.
Marco Miller4f898442020-09-29 14:18:51 -0400506. You then have to right-click on the root directory and choose the build path->link source option.
517. Then you have to browse to `.sbt/1.0/staging`, find the folder where gatling-git is contained,
Hamza Kaced2e37e272020-07-30 23:18:39 -040052 and choose that.
Marco Miller4f898442020-09-29 14:18:51 -0400538. That last step should link the gatling-git plugin to the project; e2e tests should not show
Hamza Kaced2e37e272020-07-30 23:18:39 -040054 errors anymore.
Marco Miller4f898442020-09-29 14:18:51 -0400559. You may get errors in the gatling-git directory; these should not affect Gerrit Gatling
Hamza Kaced2e37e272020-07-30 23:18:39 -040056 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
David Ostrovsky0cba3e32021-11-29 20:05:13 +0100105`/tmp/ssh-keys`. The keys need to be generated this way and won't be validated.
Fabio Ponciroli386aebb2019-05-21 20:30:41 -0700106
107----
Marco Millerf00947e2020-01-31 14:35:58 -0500108mkdir /tmp/ssh-keys
Fabio Ponciroli386aebb2019-05-21 20:30:41 -0700109ssh-keygen -m PEM -t rsa -C "test@mail.com" -f /tmp/ssh-keys/id_rsa
110----
111
Marco Millerf00947e2020-01-31 14:35:58 -0500112The public key in `/tmp/ssh-keys/id_rsa.pub` has to be added to the test user(s) `SSH Keys` in
113Gerrit. Now, the host from which the latter runs may need public key scanning to become known.
114This applies to the local user that runs the forthcoming `sbt` testing commands. An example
115assuming `localhost` follows:
116
117----
118ssh-keyscan -t rsa -p 29418 localhost > ~/.ssh/known_hosts
119----
Fabio Ponciroli386aebb2019-05-21 20:30:41 -0700120
Marco Miller62c30e52020-01-30 15:45:02 -0500121=== Input file
Fabio Ponciroli386aebb2019-05-21 20:30:41 -0700122
Marco Miller3f46efd2020-02-01 11:06:11 -0500123The `CloneUsingBothProtocols` scenario is fed with the data coming from the
Marco Miller28c26cd2020-03-19 16:41:25 -0400124`src/test/resources/data/com/google/gerrit/scenarios/CloneUsingBothProtocols.json` file. Such a
Marco Miller0ca836a2020-03-20 11:38:29 -0400125file contains the commands and repository used during the e2e test. That file currently looks like
Marco Miller28c26cd2020-03-19 16:41:25 -0400126below. This scenario serves as a simple example with no actual load in it. It can be used to test
127or validate the local setup. More complex scenarios can be further developed, under the
Marco Miller2536cee2020-09-17 16:53:41 -0400128`com.google.gerrit.scenarios` package. The uppercase keywords are set through
Marco Miller1b100682020-09-21 11:30:31 -0400129link:#_environment_properties[environment properties,role=external,window=_blank].
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`
David Åkerman2f9757f2022-02-16 10:25:37 +0100176* `-Dcom.google.gerrit.scenarios.username=admin`
David Åkerman6e9dc532022-02-16 10:48:31 +0100177* `-Dcom.google.gerrit.scenarios.replica_hostname=localhost`
David Åkerman9aac9a82022-02-16 11:57:42 +0100178* `-Dcom.google.gerrit.scenarios.project_prefix=`
Marco Miller6ba23762020-04-02 14:07:29 -0400179
180Above, the properties can be set with values matching specific deployment topologies under test.
Marco Miller2536cee2020-09-17 16:53:41 -0400181The name of the property corresponds to the uppercase keyword found in the json file. For example,
Marco Miller1b100682020-09-21 11:30:31 -0400182`hostname` above will set the value of `HOSTNAME` in the
183link:#_input_file[aforementioned example,role=external,window=_blank].
Marco Miller16406aa2020-04-03 11:26:45 -0400184
Marco Millera543a932020-07-15 13:45:31 -0400185The example values shown above are the currently coded default ones. For example, the `http` scheme
Marco Millercdb29272020-09-17 17:15:36 -0400186above could be replaced with `https`. The framework may support differing or more properties over time.
187
188==== Replication delay
189
190The `replication_delay` property allows test scenario steps to wait for that many seconds, prior to
191expecting a done replication. Its default is `15` seconds and can be set using another value:
192
193* `-Dcom.google.gerrit.scenarios.replication_delay=15`
194
195There is a short time buffer added to this property. Now, the replication starts after replication
196plugin's own `replicationDelay`, in seconds, and typically takes some more seconds to complete.
197That whole replication time depends on the system under test. Therefore, this property here should
198be set to a value high enough, so that the test checks for a done replication at the right time.
Marco Miller16406aa2020-04-03 11:26:45 -0400199
David Åkerman4e635372022-02-16 11:28:34 +0100200==== Context path
201
202The `context_path` property allows test scenarios to send Gerrit REST requests to Gerrit instances
203that use a context path in the URL. Its default is no context path and can be set using another value:
204
205* `-Dcom.google.gerrit.scenarios.context_path=/context`
206
David Åkerman4dae9de2022-04-20 11:19:00 +0200207==== Authentication
208
209The `authenticated` property allows test scenarios to use authenticated HTTP clones. Its default is
210no authentication:
211
212* `-Dcom.google.gerrit.scenarios.authenticated=false`
213
Marco Miller2536cee2020-09-17 16:53:41 -0400214==== Automatic properties
215
Marco Miller1b100682020-09-21 11:30:31 -0400216The link:#_input_file[example keywords,role=external,window=_blank] also include `_PROJECT`,
217prefixed with an underscore, which means that its value gets automatically generated by the
218scenario. Any property setting for it is therefore not applicable. Its usage differs from the
219non-prefixed `PROJECT` keyword, in that sense. Using the latter instead in json files requires
220setting this `JAVA_OPTS` property:
Marco Miller2536cee2020-09-17 16:53:41 -0400221
222* `-Dcom.google.gerrit.scenarios.project=myOwnTestRepoProjectName`
223
224Other automatic keys may be used and implemented, always prefixed with an underscore that tells so.
Marco Miller2f6d90d2020-09-17 16:08:09 -0400225
226==== Plugin scenarios
227
228Plugin or otherwise non-core scenarios can also use such properties. The core java package
Marco Miller16406aa2020-04-03 11:26:45 -0400229`com.google.gerrit.scenarios` from the example above has to be replaced with the one under which
230those scenario classes are. Such extending scenarios can also add extension-specific properties.
Marco Millerc0448852020-09-04 12:51:36 -0400231Examples of this can be found in these Gerrit plugins test code:
232
Marco Miller95fc71f2020-09-17 17:59:06 -0400233* `link:https://gerrit.googlesource.com/plugins/gc-conductor[gc-conductor,role=external,window=_blank]`
Jacek Centkowski839fab12020-09-11 17:05:18 +0200234* `link:https://gerrit.googlesource.com/plugins/high-availability[high-availability,role=external,window=_blank]`
235* `link:https://gerrit.googlesource.com/plugins/multi-site[multi-site,role=external,window=_blank]`
236* `link:https://gerrit.googlesource.com/plugins/rename-project[rename-project,role=external,window=_blank]`
Marco Miller6ba23762020-04-02 14:07:29 -0400237
Marco Millere9859dc2020-09-17 16:04:08 -0400238==== Power factor
Fabio Poncirolie2244562019-05-21 20:30:41 -0700239
Marco Miller0b2c50a2020-04-17 14:04:08 -0400240The following core property can be optionally set depending on the runtime environment. The test
241environments used as reference for scenarios development assume its default value, `1.0`. For
242slower or more complex execution environments, the value can be increased this way for example:
243
244* `-Dcom.google.gerrit.scenarios.power_factor=1.5`
245
246This will make the scenario steps take half more time to expect proper completion. A value smaller
247than the default, say `0.8`, will make scenarios wait somewhat less than how they were developed.
248Scenario development is often done using locally running Gerrit systems under test, which are
249sometimes dockerized.
250
Nguyen Tuan Khang Phan58117f42021-01-14 15:22:42 -0500251==== Number of users
252
253The `number_of_users` property can be used to scale scenario steps to run with the specified number
254of concurrent users. The value of this property remains `1` by default. For example, this sets the
255number of concurrent users to 10:
256
257* `-Dcom.google.gerrit.scenarios.number_of_users=10`
258
259This will make scenarios that support the `number_of_users` property to inject that many users
260concurrently for load testing.
261
Marco Miller62c30e52020-01-30 15:45:02 -0500262== How to run tests
Fabio Ponciroli386aebb2019-05-21 20:30:41 -0700263
264Run all tests:
265----
266sbt "gatling:test"
267----
268
269Run a single test:
270----
Marco Miller3f46efd2020-02-01 11:06:11 -0500271sbt "gatling:testOnly com.google.gerrit.scenarios.CloneUsingBothProtocols"
Fabio Ponciroli386aebb2019-05-21 20:30:41 -0700272----
273
274Generate the last report:
275----
276sbt "gatling:lastReport"
277----
278
Marco Miller51820c72020-01-30 17:21:18 -0500279The `src/test/resources/logback.xml` file
Marco Millerd421f802020-01-30 18:19:39 -0500280link:http://logback.qos.ch/manual/configuration.html[configures,role=external,window=_blank]
Marco Miller74720262020-04-28 16:51:43 -0400281Gatling's logging level. To quickly enable
282link:https://gatling.io/docs/current/general/debugging#logback[detailed logging,role=external,window=_blank]
283of `http` requests and responses, the `root level` can be set to `trace` in that file.
Marco Miller51820c72020-01-30 17:21:18 -0500284
Marco Miller62c30e52020-01-30 15:45:02 -0500285=== How to run using Docker
Marco Miller75a60462020-01-30 12:14:15 -0500286
287----
Marco Miller3f46efd2020-02-01 11:06:11 -0500288docker run -it e2e-tests -s com.google.gerrit.scenarios.CloneUsingBothProtocols
Marco Miller75a60462020-01-30 12:14:15 -0500289----
290
Marco Miller61ccca52020-03-18 09:59:59 -0400291=== How to run non-core scenarios
292
293Locally adding non-core scenarios, for example from Gerrit plugins, is as simple as copying such
294files in. Copying is necessary over linking, unless running using Docker (above) is not required.
295Docker does not support links for files it has to copy over through the Dockerfile (here, the
296scenario files). Here is how to proceed for adding such external (e.g., plugin) scenario files in:
297
298----
299pushd e2e-tests/src/test/scala
300cp -r (or, ln -s) scalaPackageStructure .
301popd
302
303pushd e2e-tests/src/test/resources/data
304cp -r (or, ln -s) jsonFilesPackageStructure .
305popd
306----
307
308The destination folders above readily git-ignore every non-core scenario file added under them. If
309running using Docker, `e2e-tests/Dockerfile` may require another `COPY` line for the hereby added
310scenarios. Aforementioned `sbt` or `docker` commands can then be used to run the added tests.
311
Fabio Ponciroli386aebb2019-05-21 20:30:41 -0700312GERRIT
313------
314Part of link:index.html[Gerrit Code Review]
315
316SEARCHBOX
317---------
318
319[scala]: