Skip to content

L1 tests refactoring#76

Merged
davidstrauss merged 24 commits intolcache:masterfrom
ndobromirov:l1-tests-refactoring
Dec 27, 2016
Merged

L1 tests refactoring#76
davidstrauss merged 24 commits intolcache:masterfrom
ndobromirov:l1-tests-refactoring

Conversation

@ndobromirov
Copy link
Copy Markdown
Contributor

Overview

This pull request implements the described L1 testing changes in #43 for APCu, Static and SQLite drivers.

Summary

There is a new L1CacheTest abstract base class.
There are 3 successors for it, 1 for each driver (APCu, Static, SQLite).

There were some incompatibilities between L1 Implementations and tests:

  • Pool sharing between instances was tested only for SQLite. Whe ported to test against all L1s, the tests for the static implementation failed. This is fixed in the driver, so all are currently passing.
  • APCu had a comment that it clears the whole APCu data on flush. This is re-implemented with an iterator, so now it should be safe.

This is based on top of #73, as the changes here depend on:

  • Unified L1 creation interface.
  • Factory for all L1 drivers.

Description

All the pure L1 tests are moved to the L1 testing hierarchy.
TODO: L2 and Integrations.

ndobromirov and others added 22 commits December 9, 2016 15:49
…ween L1 cache implementations and their respective state handlers.
…tored 2 loops in StaticL2 to reduce code indentation.
…ial L1 concrete classes for APCu, Static and SQLite.
…s to reduce danger in using the library (maybe added overhead on cache clear).
…l L1 drivers. Had to Refactor StaticL1 for that.
@coveralls
Copy link
Copy Markdown

coveralls commented Dec 27, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling 5ba363a on ndobromirov:l1-tests-refactoring into a11946d on lcache:master.

@davidstrauss davidstrauss self-requested a review December 27, 2016 17:31
@davidstrauss davidstrauss added this to the v1.0.0 milestone Dec 27, 2016
Copy link
Copy Markdown
Member

@davidstrauss davidstrauss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is getting very, very close.

* @param string $pool
* @return \LCache\APCuL1
*/
protected function createApcu($pool)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we call this createAPCu?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

* @param string $pool
* @return \LCache\SQLiteL1
*/
protected function createSqlite($pool)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we call this createSQLite?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

* @return bool
* True on success, false otherwise.
*/
private function _recordEvent($key)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason this has an underscore prefix?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a personal preference. I like to have all private stuff prefixed with underscore old habit left from development on Yii framework. If it's not ok with the project's naming conventions it fairly easy to change. Though the code sniffer did not complained for that :).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Also changed the new static variable in the static cache instance.

{
apcu_store($this->statusKeyHits, 0);
apcu_store($this->statusKeyMisses, 0);
// TODO: Decide on how to handle the last applied event state on clear?
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think resetting statistics and resetting the last applied event ID should be separate. The latter should, generally, only get flushed when the entire local cache gets flushed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it's ok as it is. I'll just remove the comment.

*
* @author ndobromirov
*/
class StateL1Null extends StateL1Static implements StateL1Interface
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm concerned about how this splits the PHP_INT_MAX for getLastAppliedEventID away from NullL1. It allows incorrect behavior when someone uses this state implementation with a stateful L1. As a rule, it should be possible to combine any StateL1 with any L1 and have correct (but maybe not ideal) behavior.

Perhaps, we should just not have a StateL1Null and use StateL1Static with NullL1 when testing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I felt something was off when I was implementing this. The only state implementation that caused issues was the NULL one. I think that state should be ok to be the static one. Will change it so.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

State NULL is deleted. On all places the static one is used now. The PHP_INT_MAX was moved back to the NullL1.

@coveralls
Copy link
Copy Markdown

coveralls commented Dec 27, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling d011c69 on ndobromirov:l1-tests-refactoring into a11946d on lcache:master.

@ndobromirov
Copy link
Copy Markdown
Contributor Author

ndobromirov commented Dec 27, 2016

I think I've missed the NullL1 cache to have it's own L1 test class.

@davidstrauss
Copy link
Copy Markdown
Member

I think I've missed the NullL1 cache to have it's own L1 test class.

I'm not sure what you mean. Should I hold off on merging until you make some more changes?

@coveralls
Copy link
Copy Markdown

coveralls commented Dec 27, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling 60af8a8 on ndobromirov:l1-tests-refactoring into a11946d on lcache:master.

@ndobromirov
Copy link
Copy Markdown
Contributor Author

That's it for L1s (for now).

I have started working on the L2 but it is going to be tricky there, as I am still getting to know the API and tests for it.

You can decide how to do it.

  1. Merge as it is now and have L2 + integration added as separate PRs.
  2. One huge PR (so this will get bigger).

@davidstrauss
Copy link
Copy Markdown
Member

Merge as it is now and have L2 + integration added as separate PRs.

I always prefer working incrementally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants