Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
DeryabinSergey opened this issue Jun 2, 2020 · 0 comments
Open

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

DeryabinSergey opened this issue Jun 2, 2020 · 0 comments

Comments

@DeryabinSergey
Copy link
Contributor

DeryabinSergey commented Jun 2, 2020

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

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

# ../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() - там все пиры проверились и удалились из списка.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant