<commit_before><?php

/*
 * This file is part of the ONGR package.
 *
 * (c) NFQ Technologies UAB <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace ONGR\ElasticsearchBundle\Test;

use Elasticsearch\Common\Exceptions\ElasticsearchException;
use ONGR\ElasticsearchBundle\Service\Manager;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Base test which creates unique connection to test with.
 */
abstract class AbstractElasticsearchTestCase extends WebTestCase
{
    /**
     * @var Manager[] Holds used managers.
     */
    private $managers = [];

    /**
     * @var ContainerInterface
     */
    private $container;

    /**
     * {@inheritdoc}
     */
    public function runTest()
    {
        if ($this->getNumberOfRetries() < 1) {
            return parent::runTest();
        }

        foreach (range(1, $this->getNumberOfRetries()) as $try) {
            try {
                return parent::runTest();
            } catch (\Exception $e) {
                if (!($e instanceof ElasticsearchException)) {
                    throw $e;
                }
                // If error was from elasticsearch re-setup tests and retry.
                if ($try !== $this->getNumberOfRetries()) {
                    $this->tearDown();
                    $this->setUp();
                }
            }
        }
    }

    /**
     * {@inheritdoc}
     */
    protected function setUp()
    {
        $this->getContainer();
        $this->getManager();
    }
<commit_msg>fixing performance leak to not create index twice on func. tests<commit_after><?php

/*
 * This file is part of the ONGR package.
 *
 * (c) NFQ Technologies UAB <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace ONGR\ElasticsearchBundle\Test;

use Elasticsearch\Common\Exceptions\ElasticsearchException;
use ONGR\ElasticsearchBundle\Service\Manager;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Base test which creates unique connection to test with.
 */
abstract class AbstractElasticsearchTestCase extends WebTestCase
{
    /**
     * @var Manager[] Holds used managers.
     */
    private $managers = [];

    /**
     * @var ContainerInterface
     */
    private $container;

    /**
     * {@inheritdoc}
     */
    public function runTest()
    {
        if ($this->getNumberOfRetries() < 1) {
            return parent::runTest();
        }

        foreach (range(1, $this->getNumberOfRetries()) as $try) {
            try {
                return parent::runTest();
            } catch (\Exception $e) {
                if (!($e instanceof ElasticsearchException)) {
                    throw $e;
                }
                // If error was from elasticsearch re-setup tests and retry.
                if ($try !== $this->getNumberOfRetries()) {
                    $this->tearDown();
                    $this->setUp();
                }
            }
        }
    }

    /**
     * {@inheritdoc}
     */
    protected function setUp()
    {
        $this->getContainer();
    }

{'fraction_non_alphanumeric': 0.11473936488915518, 'fraction_numerical': 0.0011983223487118035, 'mean_word_length': 1.98125, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3937760', 'n_tokens_mistral': 899, 'n_tokens_neox': 880, 'n_words': 237}