|
78 | 78 |
|
79 | 79 | DBNAME=${WP_CLI_TEST_DBNAME:-wp_cli_test} |
80 | 80 |
|
81 | | - # We need to test the connection. |
82 | | - # Let's try to connect to the specific test database. |
83 | | - if ! ${DB_CLIENT} ${HOST_STRING} --user="${USER}" ${PASSWORD_ARG} --execute="USE \`${DBNAME}\`;" 2>/dev/null; then |
| 81 | + # We need to test the connection, and that the test user may create the test database. |
| 82 | + # The database itself does not need to exist, as the scenarios drop and create it, which |
| 83 | + # is also why a rerun after a run in parallel workers usually finds it missing. |
| 84 | + if ! ${DB_CLIENT} ${HOST_STRING} --user="${USER}" ${PASSWORD_ARG} --execute="CREATE DATABASE IF NOT EXISTS \`${DBNAME}\`;" 2>/dev/null; then |
84 | 85 | echo "Warning: Could not connect to the MySQL/MariaDB database." |
85 | 86 | echo "Please make sure the database is running and run 'composer prepare-tests' once to set it up." |
86 | 87 | echo "The tests will continue to be run, but with WP_CLI_TEST_DBTYPE=sqlite." |
@@ -270,4 +271,39 @@ for arg in "$@"; do |
270 | 271 | fi |
271 | 272 | done |
272 | 273 |
|
| 274 | +# Run the scenarios in parallel workers when WP_CLI_TEST_PARALLEL is set to their number. |
| 275 | +# Every worker but the first uses its own test database, which the test user needs |
| 276 | +# to be allowed to create, as set up by "composer prepare-tests". |
| 277 | +PARALLEL="${WP_CLI_TEST_PARALLEL-}" |
| 278 | + |
| 279 | +# A rerun after a parallel run covers exactly the scenarios that failed in it, which only the |
| 280 | +# parallel runner knows, whether or not WP_CLI_TEST_PARALLEL is set for the rerun as well. |
| 281 | +for arg in "$@"; do |
| 282 | + if [ "$arg" = "--rerun" ] && [ -f "${TMPDIR:-/tmp}/wp-cli-test-parallel-failures.scenarios" ]; then |
| 283 | + exec php "$WP_CLI_TESTS_ROOT"/utils/behat-parallel.php 1 --snippets-for="WP_CLI\Tests\Context\FeatureContext" "${FORMAT_ARGS[@]}" "$BEHAT_TAGS" --strict "${BEHAT_EXTRA_ARGS[@]}" -- "$@" |
| 284 | + fi |
| 285 | +done |
| 286 | + |
| 287 | +case "$(uname -s)" in |
| 288 | + MINGW*|MSYS*|CYGWIN*) |
| 289 | + PARALLEL="";; |
| 290 | +esac |
| 291 | +if [ -n "${PARALLEL}" ] && [ "${PARALLEL}" != "1" ]; then |
| 292 | + if ! is_numeric "${PARALLEL}"; then |
| 293 | + echo "Warning: WP_CLI_TEST_PARALLEL is not a number of workers, running the scenarios one after the other." >&2 |
| 294 | + PARALLEL="" |
| 295 | + elif [[ "${WP_CLI_TEST_COVERAGE}" == "true" ]]; then |
| 296 | + echo "Code coverage is collected, running the scenarios one after the other." >&2 |
| 297 | + PARALLEL="" |
| 298 | + elif [ "${WP_CLI_TEST_DBTYPE-}" != "sqlite" ] && ! ${DB_CLIENT} ${HOST_STRING} --user="${USER}" ${PASSWORD_ARG} --execute="CREATE DATABASE IF NOT EXISTS \`${DBNAME}_1\`; DROP DATABASE \`${DBNAME}_1\`;" 2>/dev/null; then |
| 299 | + echo "Warning: The test user cannot create the databases of parallel workers, running the scenarios one after the other." >&2 |
| 300 | + echo "Run 'composer prepare-tests' once to allow it." >&2 |
| 301 | + PARALLEL="" |
| 302 | + fi |
| 303 | +fi |
| 304 | + |
| 305 | +if [ -n "${PARALLEL}" ] && [ "${PARALLEL}" != "1" ]; then |
| 306 | + exec php "$WP_CLI_TESTS_ROOT"/utils/behat-parallel.php "${PARALLEL}" --snippets-for="WP_CLI\Tests\Context\FeatureContext" "${FORMAT_ARGS[@]}" "$BEHAT_TAGS" --strict "${BEHAT_EXTRA_ARGS[@]}" -- "$@" |
| 307 | +fi |
| 308 | + |
273 | 309 | vendor/bin/behat --snippets-for="WP_CLI\Tests\Context\FeatureContext" "${FORMAT_ARGS[@]}" "$BEHAT_TAGS" --strict "${BEHAT_EXTRA_ARGS[@]}" "$@" |
0 commit comments