Skip to content

Commit

Permalink
Merge pull request #3854 from 10up/feature/es-8-automated-tests
Browse files Browse the repository at this point in the history
Automated tests with ES 8
  • Loading branch information
felipeelia authored Mar 7, 2024
2 parents 8a99a20 + baa3931 commit 66ebdd9
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 77 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/cypress-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ on:

jobs:
cypress_local:
name: Local - ${{ matrix.core.name }} (${{ matrix.testGroup }})
name: ES ${{ matrix.esVersion }} - ${{ matrix.core.name }} (${{ matrix.testGroup }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
testGroup: ['@slow', '-@slow']
esVersion: ['7.10.1', '8.12.2']
core:
- {name: 'WP latest', version: '', wcVersion: ''}
- {name: 'WP minimum', version: '6.0', wcVersion: '6.4.0'}
Expand Down Expand Up @@ -70,7 +71,10 @@ jobs:
run: npm ci --include=dev

- name: Set up WP environment with Elasticsearch
run: npm run env:start
run: ES_VERSION=${{ matrix.esVersion }} npm run env:start

- name: Check ES response
run: curl --connect-timeout 5 --max-time 10 --retry 5 --retry-max-time 40 --retry-all-errors http://localhost:8890

- name: Build asset
run: npm run build
Expand Down
86 changes: 15 additions & 71 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test
name: Unit Test

env:
COMPOSER_VERSION: "2"
Expand All @@ -17,9 +17,16 @@ on:
- '[0-9].[0-9x]*' # Version branches: 4.x.x, 4.1.x, 5.x

jobs:
phpunit_single_site:
name: PHP Unit (Single Site)
phpunit:
name: ${{ matrix.type.name }} - ES ${{ matrix.esVersion }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
esVersion: ['7.10.1', '8.12.2']
type:
- {name: 'Single Site', command: 'test-single-site'}
- {name: 'Multisite', command: 'test'}

steps:
- name: Checkout
Expand All @@ -28,71 +35,11 @@ jobs:
- name: Start MySQL
run: sudo systemctl start mysql.service

- name: Configure sysctl limits
run: |
sudo swapoff -a
sudo sysctl -w vm.swappiness=1
sudo sysctl -w fs.file-max=262144
sudo sysctl -w vm.max_map_count=262144
- name: Setup Elasticsearch
uses: getong/[email protected]
with:
elasticsearch version: '7.10.1'

- name: Set standard 10up cache directories
run: |
composer config -g cache-dir "${{ env.COMPOSER_CACHE }}"
- name: Prepare composer cache
uses: actions/cache@v3
with:
path: ${{ env.COMPOSER_CACHE }}
key: composer-${{ env.COMPOSER_VERSION }}-${{ hashFiles('**/composer.lock') }}
restore-keys: |
composer-${{ env.COMPOSER_VERSION }}-
- name: Set PHP version
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
extensions: :php-psr
coverage: none
run: cd bin/es-docker/ && docker-compose build --build-arg ES_VERSION=${{ matrix.esVersion }} && docker-compose up -d

- name: Install dependencies
run: composer install --ignore-platform-reqs

- name: Setup WP Tests
run: |
bash bin/install-wp-tests.sh wordpress_test root root 127.0.0.1
sleep 10
- name: PHPUnit
run: |
composer run-script test-single-site
phpunit_multisite:
name: PHP Unit (Multisite)
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Start MySQL
run: sudo systemctl start mysql.service

- name: Configure sysctl limits
run: |
sudo swapoff -a
sudo sysctl -w vm.swappiness=1
sudo sysctl -w fs.file-max=262144
sudo sysctl -w vm.max_map_count=262144
- name: Setup Elasticsearch
uses: getong/[email protected]
with:
elasticsearch version: '7.10.1'
- name: Check ES response
run: curl --connect-timeout 5 --max-time 10 --retry 5 --retry-max-time 40 --retry-all-errors http://127.0.0.1:8890

- name: Set standard 10up cache directories
run: |
Expand All @@ -114,16 +61,13 @@ jobs:
coverage: none

- name: Install dependencies
run: composer install
run: composer install --ignore-platform-reqs

- name: Setup WP Tests
run: |
bash bin/install-wp-tests.sh wordpress_test root root 127.0.0.1
sleep 10
- name: Debug
run: ./vendor/bin/phpunit --filter test_use_language_in_setting_for_multisite
- name: PHPUnit
run: |
composer run-script test
EP_HOST=http://127.0.0.1:8890/ composer run-script ${{ matrix.type.command }}
2 changes: 2 additions & 0 deletions bin/es-docker/elasticsearch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ http.cors.enabled : true
http.cors.allow-origin : "*"
http.cors.allow-methods : OPTIONS, HEAD, GET, POST, PUT, DELETE
http.cors.allow-headers : X-Requested-With,X-Auth-Token,x-elasticpress-request-id,Content-Type,Content-Length

action.destructive_requires_name : false
2 changes: 1 addition & 1 deletion elasticpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function( $class ) {
*
* @since 2.2
*/
define( 'EP_ES_VERSION_MAX', '7.10' );
define( 'EP_ES_VERSION_MAX', '8.99' );
define( 'EP_ES_VERSION_MIN', '5.2' );

require_once __DIR__ . '/includes/compat.php';
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"lint-style": "10up-toolkit lint-style",
"env": "wp-env",
"env:install-tests-cli": "./bin/install-wp-cli.sh tests-wordpress",
"env:start": "wp-env start && npm run env:install-tests-cli && cd bin/es-docker/ && docker-compose up -d",
"env:start": "wp-env start && npm run env:install-tests-cli && cd bin/es-docker/ && docker-compose build --build-arg ES_VERSION=${ES_VERSION-7.10.2} && docker-compose up -d",
"env:stop": "wp-env stop && cd bin/es-docker/ && docker-compose down",
"env:reset": "wp-env clean all && npm run env:start && npm run cypress:setup",
"cypress:setup": "./bin/setup-cypress-env.sh",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ function() {
add_filter(
'ep_elasticsearch_version',
function() {
return '8.0';
return '9.0';
}
);
4 changes: 3 additions & 1 deletion tests/php/TestStats.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ public function testTotals() {

$this->assertEquals( 1, $totals['docs'] );
$this->assertTrue( ! empty( $totals['size'] ) );
$this->assertTrue( ! empty( $totals['memory'] ) );
$this->assertTrue( isset( $totals['memory'] ) );

$this->assertEmpty( Stats::factory()->get_failed_queries() );

$this->markTestIncomplete( 'Memory numbers are always 0 with Elasticsearch 8.x' );
}

/**
Expand Down

0 comments on commit 66ebdd9

Please sign in to comment.