e2e-tests: Add CheckMasterBranchReplica1 scenarios

Add the CheckMasterBranchReplica1 and GetMasterBranchRevision scenarios.
Make the latter usable independently of the former which composes it.
Adapt the existing SubmitChange scenario so it can be composed by
CheckMasterBranchReplica1 just as well.

CheckMasterBranchReplica1 is meant to test a gerrit (8080) replicating
to another (8081) locally. The scenario assumes an already created and
replicated test project, with a name specified through the already
supported PROJECT property; cf. [1] (e.g., [2]). The core CreateProject
scenario can be used prior, for that purpose. This is all based on the
core replication plugin being installed and configured with at least the
heads and meta refs pushed.

Make this CheckMasterBranchReplica1 scenario use its own http password
towards the 8081 replica, to not fail upon a 401 otherwise. The other
CheckMasterBranchReplica1 test steps still use 8080's base http password
for the admin test user. As usual with the core framework, this requires
an http.password_replica entry in [3] locally; cf. [4].

[1] https://gerrit-documentation.storage.googleapis.com/Documentation/3.0.9/dev-e2e-tests.html#_environment_properties
[2] export JAVA_OPTS="-Dcom.google.gerrit.scenarios.project=CheckMasterBranchReplica1"
[3] e2e-tests/src/test/resources/application.conf
[4] https://gerrit-documentation.storage.googleapis.com/Documentation/3.0.9/dev-e2e-tests.html#_project_and_http_credentials

Feature: Issue 12813
Change-Id: I224d365f978bbd4cf419312ebf7116f9557d7c95
This commit is contained in:
Marco Miller
2020-06-03 17:18:36 -04:00
parent 523de1b6e4
commit fa45c1af95
5 changed files with 133 additions and 2 deletions

View File

@@ -0,0 +1,5 @@
[
{
"url": "http://HOSTNAME:HTTP_PORT1/a/projects/PROJECT/branches/master"
}
]

View File

@@ -0,0 +1,5 @@
[
{
"url": "http://HOSTNAME:HTTP_PORT/a/projects/PROJECT/branches/master"
}
]

View File

@@ -0,0 +1,73 @@
// Copyright (C) 2020 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.scenarios
import com.typesafe.config.ConfigFactory
import io.gatling.core.Predef._
import io.gatling.core.feeder.FeederBuilder
import io.gatling.core.structure.ScenarioBuilder
import io.gatling.http.Predef._
import scala.concurrent.duration._
class CheckMasterBranchReplica1 extends ProjectSimulation {
private val data: FeederBuilder = jsonFile(resource).convert(keys).queue
override def replaceOverride(in: String): String = {
val next = replaceProperty("http_port1", 8081, in)
super.replaceOverride(next)
}
private val httpForReplica = http.basicAuth(
conf.httpConfiguration.userName,
ConfigFactory.load().getString("http.password_replica"))
private val createChange = new CreateChange
private val approveChange = new ApproveChange(createChange)
private val submitChange = new SubmitChange(createChange)
private val getBranch = new GetMasterBranchRevision
private val test: ScenarioBuilder = scenario(unique)
.feed(data)
.exec(session => {
session.set(getBranch.revisionKey, getBranch.revision.get)
})
.exec(http(unique).get("${url}")
.check(regex(getBranch.revisionPattern)
.is(session => session(getBranch.revisionKey).as[String])))
setUp(
createChange.test.inject(
nothingFor(stepWaitTime(createChange) seconds),
atOnceUsers(1)
),
approveChange.test.inject(
nothingFor(stepWaitTime(approveChange) seconds),
atOnceUsers(1)
),
submitChange.test.inject(
nothingFor(stepWaitTime(submitChange) seconds),
atOnceUsers(1)
),
getBranch.test.inject(
nothingFor(stepWaitTime(getBranch) seconds),
atOnceUsers(1)
),
test.inject(
nothingFor(stepWaitTime(this) seconds),
atOnceUsers(1)
).protocols(httpForReplica),
).protocols(httpProtocol)
}

View File

@@ -0,0 +1,41 @@
// Copyright (C) 2020 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.scenarios
import io.gatling.core.Predef._
import io.gatling.core.feeder.FeederBuilder
import io.gatling.core.structure.ScenarioBuilder
import io.gatling.http.Predef._
class GetMasterBranchRevision extends ProjectSimulation {
private val data: FeederBuilder = jsonFile(resource).convert(keys).queue
var revision: Option[String] = None
val revisionKey = "revision"
val revisionPattern: String = "\"" + revisionKey + "\": \"(.+)\""
val test: ScenarioBuilder = scenario(unique)
.feed(data)
.exec(http(unique).get("${url}")
.check(regex(revisionPattern).saveAs(revisionKey)))
.exec(session => {
revision = Some(session(revisionKey).as[String])
session
})
setUp(
test.inject(
atOnceUsers(1)
)).protocols(httpProtocol)
}

View File

@@ -24,8 +24,16 @@ import scala.concurrent.duration._
class SubmitChange extends GerritSimulation {
private val data: FeederBuilder = jsonFile(resource).convert(keys).queue
private val default: String = name
private var createChange = new CreateChange(default)
private val test: ScenarioBuilder = scenario(unique)
override def relativeRuntimeWeight = 10
def this(createChange: CreateChange) {
this()
this.createChange = createChange
}
val test: ScenarioBuilder = scenario(unique)
.feed(data)
.exec(session => {
session.set("number", createChange.number)
@@ -33,7 +41,6 @@ class SubmitChange extends GerritSimulation {
.exec(http(unique).post("${url}${number}/submit"))
private val createProject = new CreateProject(default)
private val createChange = new CreateChange(default)
private val approveChange = new ApproveChange(createChange)
private val deleteProject = new DeleteProject(default)