ho-nl / magento2-ReachDigital_TestFramework

Faster drop-in replacement for Magento's integration test.
MIT License
75 stars 13 forks source link

Elasticsearch errors when creating entities that trigger reindex. #30

Closed klevu closed 1 year ago

klevu commented 1 year ago

Hi, I've been checking out this framework and the results so far are extremely impressive. It is so much faster than the default Magento. I have hit an issue though.

When using fixtures to create products, either our own or TTDWizard Magento2-fixtures, we see Elasticsearch errors when the reindex is triggered, causing the tests to fail.

PHPUnit\Framework\Exception: User Deprecated: Specifying types in urls has been deprecated in /var/www/html/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Endpoints/Bulk.php:44.

If I run the test from the default Magento integration dir then all tests pass (though with xdebug I can see that these errors are still thrown by ES).

Running Magento 2.4.5-p1, PHP 8.1.6, ElasticSearch 7.17 (Mark Shust Magento 2 Docker)

Is this a known issue? Do you have any suggestions as to why this may be happening?


~/html/dev/tests/integration$ php ../../../vendor/bin/phpunit 
    -c ../integration/phpunit.xml 
    ../../../magento2-plugin/module-registry/Test/Integration/Controller/ProductPageTest.php
PHPUnit 9.5.28 by Sebastian Bergmann and contributors.

Warning:       Using a custom test suite loader is deprecated

...                                                                                                                                                                3 / 3 (100%)

Time: 00:08.880, Memory: 189.50 MB

OK (3 tests, 12 assertions)

=== Memory Usage System Stats ===
Memory usage (OS):  250.42M (135.00% of 185.50M reported by PHP)
Estimated memory leak:  64.92M (25.93% of used memory)

~/html/dev/tests/integration$ php ../../../vendor/bin/phpunit 
    -c ../quick-integration/phpunit.xml 
    ../../../magento2-plugin/module-registry/Test/Integration/Controller/ProductPageTest.php

PHPUnit 9.5.28 by Sebastian Bergmann and contributors.

EEE                                                                 3 / 3 (100%)

Time: 00:11.302, Memory: 133.00 MB

There were 3 errors:

1) Vendor\Registry\Test\Integration\Controller\ProductPageTest::testRegistryValuesOnEnabledProduct
Magento\Framework\Exception\CouldNotSaveException: The stock item was unable to be saved. Please try again.

/var/www/html/vendor/magento/module-catalog-inventory/Model/Stock/StockItemRepository.php:196
/var/www/html/vendor/magento/module-catalog-inventory/Model/StockRegistry.php:181
/var/www/html/vendor/magento/framework/Interception/Interceptor.php:58
/var/www/html/vendor/magento/framework/Interception/Interceptor.php:138
/var/www/html/vendor/magento/framework/Interception/Interceptor.php:153
/var/www/html/generated/code/Magento/CatalogInventory/Model/StockRegistry/Interceptor.php:59
/var/www/html/vendor/magento/module-catalog-inventory/Observer/SaveInventoryDataObserver.php:125
/var/www/html/vendor/magento/framework/Event/Invoker/InvokerDefault.php:88
/var/www/html/vendor/magento/framework/Event/Invoker/InvokerDefault.php:74
/var/www/html/vendor/magento/framework/Event/Manager.php:65
/var/www/html/generated/code/Magento/Framework/Event/Manager/Proxy.php:95
/var/www/html/vendor/magento/framework/Model/AbstractModel.php:832
/var/www/html/vendor/magento/module-catalog/Model/Product.php:985
/var/www/html/vendor/magento/framework/EntityManager/Observer/AfterEntitySave.php:34
/var/www/html/vendor/magento/framework/Event/Invoker/InvokerDefault.php:88
/var/www/html/vendor/magento/framework/Event/Invoker/InvokerDefault.php:74
/var/www/html/vendor/magento/framework/Event/Manager.php:65
/var/www/html/generated/code/Magento/Framework/Event/Manager/Proxy.php:95
/var/www/html/vendor/magento/framework/EntityManager/EventManager.php:50
/var/www/html/vendor/magento/framework/EntityManager/Operation/Create.php:123
/var/www/html/vendor/magento/framework/EntityManager/EntityManager.php:106
/var/www/html/vendor/magento/module-catalog/Model/ResourceModel/Product.php:777
/var/www/html/vendor/magento/framework/Interception/Interceptor.php:58
/var/www/html/vendor/magento/framework/Interception/Interceptor.php:138
/var/www/html/vendor/magento/module-catalog-search/Model/Indexer/Fulltext/Plugin/Product.php:58
/var/www/html/vendor/magento/module-catalog-search/Model/Indexer/Fulltext/Plugin/Product.php:28
/var/www/html/vendor/magento/framework/Interception/Interceptor.php:135
/var/www/html/vendor/magento/framework/Interception/Interceptor.php:153
/var/www/html/generated/code/Magento/Catalog/Model/ResourceModel/Product/Interceptor.php:32
/var/www/html/vendor/magento/module-catalog/Model/ProductRepository.php:886
/var/www/html/vendor/magento/module-catalog/Model/ProductRepository.php:634
/var/www/html/vendor/magento/framework/Interception/Interceptor.php:58
/var/www/html/vendor/magento/framework/Interception/Interceptor.php:138
/var/www/html/vendor/magento/framework/Interception/Interceptor.php:153
/var/www/html/generated/code/Magento/Catalog/Model/ProductRepository/Interceptor.php:32
/var/www/html/vendor/tddwizard/magento2-fixtures/src/Catalog/ProductBuilder.php:341
/var/www/html/vendor/tddwizard/magento2-fixtures/src/Catalog/ProductBuilder.php:303
/var/www/html/magento2-plugin/module-registry/Test/Integration/Controller/ProductPageTest.php:151
/var/www/html/magento2-plugin/module-registry/Test/Integration/Controller/ProductPageTest.php:38

Caused by
PHPUnit\Framework\Exception: User Deprecated: Specifying types in urls has been deprecated in /var/www/html/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Endpoints/Bulk.php:44.

/var/www/html/dev/tests/quick-integration/framework/bootstrap.php:201
/var/www/html/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Endpoints/Bulk.php:44
/var/www/html/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Client.php:1926
/var/www/html/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Client.php:347
/var/www/html/vendor/magento/module-elasticsearch-7/Model/Client/Elasticsearch.php:173
/var/www/html/vendor/magento/module-elasticsearch/Model/Adapter/Elasticsearch.php:291
/var/www/html/vendor/magento/module-elasticsearch/Model/Indexer/IndexerHandler.php:186
/var/www/html/vendor/magento/module-catalog-search/Model/Indexer/Fulltext.php:220
/var/www/html/vendor/magento/module-catalog-search/Model/Indexer/Fulltext.php:198
/var/www/html/vendor/magento/module-catalog-search/Model/Indexer/Fulltext.php:152
/var/www/html/vendor/magento/module-catalog-search/Model/Indexer/Fulltext.php:250
/var/www/html/vendor/magento/framework/Interception/Interceptor.php:58
/var/www/html/vendor/magento/framework/Interception/Interceptor.php:138
/var/www/html/vendor/magento/framework/Interception/Interceptor.php:153
/var/www/html/generated/code/Magento/CatalogSearch/Model/Indexer/Fulltext/Interceptor.php:32
/var/www/html/vendor/magento/module-indexer/Model/Indexer.php:533
/var/www/html/vendor/magento/module-indexer/Model/Indexer/DependencyDecorator.php:294
/var/www/html/vendor/magento/framework/Indexer/AbstractProcessor.php:69
/var/www/html/vendor/magento/module-inventory-catalog-search/Plugin/InventoryIndexer/Indexer/SourceItem/Strategy/Sync/FulltextIndexUpdater.php:77
/var/www/html/vendor/magento/framework/Interception/Interceptor.php:135
/var/www/html/vendor/magento/framework/Interception/Interceptor.php:153
/var/www/html/generated/code/Magento/InventoryIndexer/Indexer/SourceItem/Strategy/Sync/Interceptor.php:23
/var/www/html/vendor/magento/module-inventory-indexer/Indexer/SourceItem/SourceItemReindexStrategy.php:61
/var/www/html/vendor/magento/module-inventory-indexer/Indexer/SourceItem/SourceItemIndexer.php:65
/var/www/html/vendor/magento/module-inventory-indexer/Plugin/InventoryApi/ReindexAfterSourceItemsSavePlugin.php:54
/var/www/html/vendor/magento/framework/Interception/Interceptor.php:146
/var/www/html/vendor/magento/framework/Interception/Interceptor.php:153
/var/www/html/generated/code/Magento/Inventory/Model/SourceItem/Command/SourceItemsSaveWithoutLegacySynchronization/Interceptor.php:23
/var/www/html/vendor/magento/module-inventory-catalog/Model/UpdateSourceItemBasedOnLegacyStockItem.php:89
/var/www/html/vendor/magento/module-inventory-catalog/Plugin/CatalogInventory/UpdateSourceItemAtLegacyStockItemSavePlugin.php:152
/var/www/html/vendor/magento/framework/Interception/Interceptor.php:135
/var/www/html/vendor/magento/framework/Interception/Interceptor.php:153
/var/www/html/generated/code/Magento/CatalogInventory/Model/ResourceModel/Stock/Item/Interceptor.php:23
/var/www/html/vendor/magento/module-catalog-inventory/Model/Stock/StockItemRepository.php:193
/var/www/html/vendor/magento/module-catalog-inventory/Model/StockRegistry.php:181
/var/www/html/vendor/magento/framework/Interception/Interceptor.php:58
/var/www/html/vendor/magento/framework/Interception/Interceptor.php:138
/var/www/html/vendor/magento/framework/Interception/Interceptor.php:153
/var/www/html/generated/code/Magento/CatalogInventory/Model/StockRegistry/Interceptor.php:59
/var/www/html/vendor/magento/module-catalog-inventory/Observer/SaveInventoryDataObserver.php:125
/var/www/html/vendor/magento/framework/Event/Invoker/InvokerDefault.php:88
/var/www/html/vendor/magento/framework/Event/Invoker/InvokerDefault.php:74
/var/www/html/vendor/magento/framework/Event/Manager.php:65
/var/www/html/generated/code/Magento/Framework/Event/Manager/Proxy.php:95
/var/www/html/vendor/magento/framework/Model/AbstractModel.php:832
/var/www/html/vendor/magento/module-catalog/Model/Product.php:985
/var/www/html/vendor/magento/framework/EntityManager/Observer/AfterEntitySave.php:34
/var/www/html/vendor/magento/framework/Event/Invoker/InvokerDefault.php:88
/var/www/html/vendor/magento/framework/Event/Invoker/InvokerDefault.php:74
/var/www/html/vendor/magento/framework/Event/Manager.php:65
/var/www/html/generated/code/Magento/Framework/Event/Manager/Proxy.php:95
/var/www/html/vendor/magento/framework/EntityManager/EventManager.php:50
/var/www/html/vendor/magento/framework/EntityManager/Operation/Create.php:123
/var/www/html/vendor/magento/framework/EntityManager/EntityManager.php:106
/var/www/html/vendor/magento/module-catalog/Model/ResourceModel/Product.php:777
/var/www/html/vendor/magento/framework/Interception/Interceptor.php:58
/var/www/html/vendor/magento/framework/Interception/Interceptor.php:138
/var/www/html/vendor/magento/module-catalog-search/Model/Indexer/Fulltext/Plugin/Product.php:58
/var/www/html/vendor/magento/module-catalog-search/Model/Indexer/Fulltext/Plugin/Product.php:28
/var/www/html/vendor/magento/framework/Interception/Interceptor.php:135
/var/www/html/vendor/magento/framework/Interception/Interceptor.php:153
/var/www/html/generated/code/Magento/Catalog/Model/ResourceModel/Product/Interceptor.php:32
/var/www/html/vendor/magento/module-catalog/Model/ProductRepository.php:886
/var/www/html/vendor/magento/module-catalog/Model/ProductRepository.php:634
/var/www/html/vendor/magento/framework/Interception/Interceptor.php:58
/var/www/html/vendor/magento/framework/Interception/Interceptor.php:138
/var/www/html/vendor/magento/framework/Interception/Interceptor.php:153
/var/www/html/generated/code/Magento/Catalog/Model/ProductRepository/Interceptor.php:32
/var/www/html/vendor/tddwizard/magento2-fixtures/src/Catalog/ProductBuilder.php:341
/var/www/html/vendor/tddwizard/magento2-fixtures/src/Catalog/ProductBuilder.php:303
/var/www/html/magento2-plugin/module-registry/Test/Integration/Controller/ProductPageTest.php:151
/var/www/html/magento2-plugin/module-registry/Test/Integration/Controller/ProductPageTest.php:38

...
paales commented 1 year ago

Maybe an elasticsearch version mismatch?

PHPUnit\Framework\Exception: User Deprecated: Specifying types in urls has been deprecated in /var/www/html/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Endpoints/Bulk.php:44.

Vinai commented 1 year ago

This is actually a core issue. PHPUnit changes the error handler, that is why the issue becomes visible in the tests. I don't remember how I worked around that - I think by adding some custom error handler wrapper...

klevu commented 1 year ago

Thank you both for the feedback. We'll look at creating a custom error handler wrapper for this.

klevu commented 1 year ago

On further investigation, there is a small difference in the setCustomErrorHandler between ReachDigital bootstrap.php compared to the Magento Integration bootstrap.php

ReachDigital

function setCustomErrorHandler()
{
    set_error_handler(function ($errNo, $errStr, $errFile, $errLine) {
        if (error_reporting()) {
            $errorNames = [

https://github.com/ho-nl/magento2-ReachDigital_TestFramework/blob/master/framework/bootstrap.php#L180


Magento

function setCustomErrorHandler()
{
   set_error_handler(
        function ($errNo, $errStr, $errFile, $errLine) {
            $errLevel = error_reporting();
            if (($errLevel & $errNo) !== 0) {
                $errorNames = [

https://github.com/magento/magento2/blob/2.4-develop/dev/tests/integration/framework/bootstrap.php#L138

That difference is letting the tests pass in the core Magento integration tests, but failing in the Reach Digital framework. If I change those lines in Reach Digital bootstrap to match Magento the tests are passing as expected.

PascalBrouwers commented 1 year ago

Seems to have been introduced in 2.4.4-p1 https://github.com/magento/magento2/commit/2b9b6d81caaedf21f747c28187fe8244b08fa8ef Including some extra changes to support php 8. These changes have to be added to this repository then.

PascalBrouwers commented 1 year ago

New version fixes this issue. Thank you for the PR!