Skip to content

Commit

Permalink
Cover the behat bisect runs with tests
Browse files Browse the repository at this point in the history
And, also, cover a couple of edge cases when
options (normally --tags and --name) have
white-spaces or ampersands.
  • Loading branch information
stronk7 committed Apr 15, 2024
1 parent 50bd22f commit 74907d4
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 63 deletions.
127 changes: 127 additions & 0 deletions test/behat_bisect_test.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#!/usr/bin/env bash
#
# This file is part of the Moodle Continuous Integration Project.
#
# Moodle is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Moodle is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Moodle. If not, see <https://www.gnu.org/licenses/>.

# Run the tests for the behat job type (bisect mode)

setup() {
load 'helpers/common'
_common_setup
}

teardown() {
load 'helpers/common'
_common_teardown
}

@test "Behat bisect tests: run a known 4.3 regression (MDL-77991)" {
# Set all the required variables.
JOBTYPE="behat"
PHP_VERSION="8.2"
DBTYPE="pgsql"
CODEDIR="${MOODLE_CI_RUNNER_GITDIR}"
BEHAT_TAGS="@gradereport_grader&&@core&&~@mod_assign"
BEHAT_NAME="all the user to expand all of them at once"
BEHAT_PARALLEL=3
BEHAT_RERUNS=3
BEHAT_TIMING_FILENAME="wont_be_used.json"
GOOD_COMMIT="ce131c354aaebe40340e4f05334164d585087361"
BAD_COMMIT="567f4c0669e2a37f65d37c2950ccc76cb77a1484"

# Checkout
run git_moodle_checkout v4.3.2
assert_success

# Run the job
run launch_runner
assert_success
assert_output --partial "== JOBTYPE: behat"
assert_output --partial "== Moodle branch (version.php): 403"
assert_output --partial "== PHP version: 8.2"
assert_output --partial "== DBTYPE: pgsql"
assert_output --partial "== BEHAT_NAME: all the user to expand all of them at once"
assert_output --partial "== BEHAT_PARALLEL: 1"
assert_output --partial "== BEHAT_RERUNS: 0"
refute_output --partial "wont_be_used.json"
assert_output --partial "== GOOD_COMMIT: ce131c354aaebe40340e4f05334164d585087361"
assert_output --partial "== BAD_COMMIT: 567f4c0669e2a37f65d37c2950ccc76cb77a1484"
assert_output --partial "Setting up docker-selenium module..."
assert_output --partial "Bisecting:"
assert_output --partial "1be10f4249868e1bf1e9b44ba71b559c23e0cd06 is the first bad commit"
assert_output --partial "Merge branch 'MDL-77991' of https://github.com/Chocolate-lightning/moodle"
assert_output --partial "132 files changed, 3805 insertions(+), 2650 deletions(-)"
assert_output --partial "Bisect logs and reset:"
assert_output --partial "Exporting all docker logs for UUID"
assert_output --partial "Stopping and removing all docker containers"
assert_output --partial "== Exit code: 0"
}

@test "Behat bisect tests: only GOOD_COMMIT specified" {
# Set all the required variables.
JOBTYPE="phpunit"
PHP_VERSION="8.3"
DBTYPE="pgsql"
CODEDIR="${MOODLE_CI_RUNNER_GITDIR}"
PHPUNIT_FILTER="test_enrol_user_sees_own_courses"
GOOD_COMMIT="b4c6ed36503c0d1e69efdb9b18e6846234706da7"

# Checkout
run git_moodle_checkout v4.3.2
assert_success

# Run the job
run launch_runner
assert_failure
assert_output --partial "ERROR: GOOD_COMMIT is set but BAD_COMMIT is not set."
}

@test "Behat bisect tests: only BAD_COMMIT specified" {
# Set all the required variables.
JOBTYPE="phpunit"
PHP_VERSION="8.3"
DBTYPE="pgsql"
CODEDIR="${MOODLE_CI_RUNNER_GITDIR}"
PHPUNIT_FILTER="test_enrol_user_sees_own_courses"
BAD_COMMIT="b4c6ed36503c0d1e69efdb9b18e6846234706da7"

# Checkout
run git_moodle_checkout v4.3.2
assert_success

# Run the job
run launch_runner
assert_failure
assert_output --partial "ERROR: BAD_COMMIT is set but GOOD_COMMIT is not set."
}

@test "Behat bisect tests: same GOOD and BAD commits specified" {
# Set all the required variables.
JOBTYPE="phpunit"
PHP_VERSION="8.3"
DBTYPE="pgsql"
CODEDIR="${MOODLE_CI_RUNNER_GITDIR}"
GOOD_COMMIT="b4c6ed36503c0d1e69efdb9b18e6846234706da7"
BAD_COMMIT="${GOOD_COMMIT}"

# Checkout
run git_moodle_checkout v4.3.2
assert_success

# Run the job
run launch_runner
assert_failure
assert_output --partial "ERROR: GOOD_COMMIT and BAD_COMMIT are set, but they are the same."
}
12 changes: 6 additions & 6 deletions test/behat_test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ teardown() {
_common_teardown
}

@test "Behat tests: run the job for v3.9.0 and 1 tag" {
@test "Behat tests: run the job for v3.9.0 and some tags" {
# Set all the required variables.
JOBTYPE="behat"
PHP_VERSION="7.4"
DBTYPE="mariadb"
CODEDIR="${MOODLE_CI_RUNNER_GITDIR}"
BEHAT_TAGS="@mod_label"
BEHAT_TAGS="@mod_label&&@core,~@mod_assign"
BEHAT_PARALLEL="1"
BROWSER_HEADLESS="1"

# Checkout v3.9.0 (note this is know to fail for @mod_label
# Checkout v3.9.0 (note this is known to fail for @mod_label
run git_moodle_checkout v3.9.0
assert_success

Expand Down Expand Up @@ -70,7 +70,7 @@ teardown() {
JOBTYPE="behat"
DBTYPE="sqlsrv"
CODEDIR="${MOODLE_CI_RUNNER_GITDIR}"
BEHAT_NAME="label"
BEHAT_NAME="the label"
PLUGINSTOINSTALL="https://github.com/moodlehq/moodle-local_codechecker.git|local_codechecker|master"

# Checkout main
Expand All @@ -81,9 +81,9 @@ teardown() {
run launch_runner
assert_success
assert_output --partial "== JOBTYPE: behat"
assert_output --partial "== PHP version: 8.1"
assert_output --partial "== PHP version: "
assert_output --partial "== DBTYPE: sqlsrv"
assert_output --partial "== BEHAT_NAME: label"
assert_output --partial "== BEHAT_NAME: the label"
assert_output --partial "== DBREPLICAS: 0"
assert_output --partial "== BEHAT_PARALLEL: 1"
assert_output --partial "PLUGINSTOINSTALL: https://github.com/moodlehq/moodle-local_codechecker.git|"
Expand Down
57 changes: 0 additions & 57 deletions test/phpunit_bisect_test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -62,60 +62,3 @@ teardown() {
assert_output --partial "Stopping and removing all docker containers"
assert_output --partial "== Exit code: 0"
}

@test "PHPUnit bisect tests: only GOOD_COMMIT specified" {
# Set all the required variables.
JOBTYPE="phpunit"
PHP_VERSION="8.3"
DBTYPE="pgsql"
CODEDIR="${MOODLE_CI_RUNNER_GITDIR}"
PHPUNIT_FILTER="test_enrol_user_sees_own_courses"
GOOD_COMMIT="b4c6ed36503c0d1e69efdb9b18e6846234706da7"

# Checkout
run git_moodle_checkout v4.3.2
assert_success

# Run the job
run launch_runner
assert_failure
assert_output --partial "ERROR: GOOD_COMMIT is set but BAD_COMMIT is not set."
}

@test "PHPUnit bisect tests: only BAD_COMMIT specified" {
# Set all the required variables.
JOBTYPE="phpunit"
PHP_VERSION="8.3"
DBTYPE="pgsql"
CODEDIR="${MOODLE_CI_RUNNER_GITDIR}"
PHPUNIT_FILTER="test_enrol_user_sees_own_courses"
BAD_COMMIT="b4c6ed36503c0d1e69efdb9b18e6846234706da7"

# Checkout
run git_moodle_checkout v4.3.2
assert_success

# Run the job
run launch_runner
assert_failure
assert_output --partial "ERROR: BAD_COMMIT is set but GOOD_COMMIT is not set."
}

@test "PHPUnit bisect tests: same GOOD and BAD commits specified" {
# Set all the required variables.
JOBTYPE="phpunit"
PHP_VERSION="8.3"
DBTYPE="pgsql"
CODEDIR="${MOODLE_CI_RUNNER_GITDIR}"
GOOD_COMMIT="b4c6ed36503c0d1e69efdb9b18e6846234706da7"
BAD_COMMIT="${GOOD_COMMIT}"

# Checkout
run git_moodle_checkout v4.3.2
assert_success

# Run the job
run launch_runner
assert_failure
assert_output --partial "ERROR: GOOD_COMMIT and BAD_COMMIT are set, but they are the same."
}

0 comments on commit 74907d4

Please sign in to comment.