Skip to content

Ошибка в SequentialCacheTest / CyclicAggregateCache #254

Description

@DeryabinSergey

Случайно сломал тесты, сходу не пойму, поэтому оставлю здесь пока

Что бы запустить только этот тест:

# ../vendor/bin/phpunit --filter SequentialCacheTest --verbose AllTests.php

При нормальном окружении тесты отрабатывают. Если memcached вообще не запущен, получаю три ошибки. Первые две ожидаемые - третья как раз таки нет.

There were 3 errors:

1) OnPHP\Tests\Core\SequentialCacheTest::testMultiCacheAliveLast
RuntimeException: All peers are dead

/var/www/onPHP/src/Core/Cache/SequentialCache.php:97
/var/www/onPHP/tests/Core/SequentialCacheTest.php:44

2) OnPHP\Tests\Core\SequentialCacheTest::testMultiCacheAliveFirst
RuntimeException: All peers are dead

/var/www/onPHP/src/Core/Cache/SequentialCache.php:97
/var/www/onPHP/tests/Core/SequentialCacheTest.php:60

3) OnPHP\Tests\Core\SequentialCacheTest::testMultiCacheAliveOnly
OnPHP\Core\Exception\BaseException: Trying to access array offset on value of type bool

/var/www/onPHP/global.inc.php.tpl:16
/var/www/onPHP/src/Core/Cache/CyclicAggregateCache.php:75
/var/www/onPHP/src/Core/Cache/BaseAggregateCache.php:115
/var/www/onPHP/src/Core/Cache/SequentialCache.php:87
/var/www/onPHP/tests/Core/SequentialCacheTest.php:77

ERRORS!
Tests: 4, Assertions: 1, Errors: 3.

Это место CyclicAggregateCache::guessLabel

	protected function guessLabel($key)
	{
		if (!$this->sorted)
			$this->sortPeers();

		$point = hexdec(substr(sha1($key), 0, 5)) % $this->summaryWeight;

		$firstPeer = reset($this->peers);

		while ($peer = current($this->peers)) {

			if ($point <= $peer['mountPoint'])
				return key($this->peers);

			next($this->peers);
		}

		if ($point <= ($firstPeer['mountPoint'] + $this->summaryWeight)) {
			reset($this->peers);

			return key($this->peers);
		}

		Assert::isUnreachable();
	}

откуда на строке

if ($point <= ($firstPeer['mountPoint'] + $this->summaryWeight)) {

получается ошибка, потому что $this->peers пустой массив и reset от него вернул false.
Пустой он стал после попытки ->set( и вызова BaseAggregateCache::checkAlive() - там все пиры проверились и удалились из списка.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions