Fixed touch(), with time=0 (with tests).#108
Fixed touch(), with time=0 (with tests).#108niconoe wants to merge 1 commit intolinsomniac:masterfrom niconoe:fix_touch
Conversation
|
I'm not sure if the Is it possible to add tests for the debuglog? |
|
About the The |
timgraham
left a comment
There was a problem hiding this comment.
About verifying debuglog -- I think the tests should capture stderr output and check it rather than the test output looking like:
...MemCached: while expecting 'DELETED', got unexpected response 'NOT_FOUND'
MemCached: while expecting 'DELETED', got unexpected response 'NOT_FOUND'
....MemCached: while expecting 'STORED', got unexpected response 'SERVER_ERROR object too large for cache'
......MemCached: MemCache: inet:127.0.0.1:11211: test. Marking dead.
.....MemCached: MemCache: inet:memcached:11211: connection closed in readline(). Marking dead.
MemCached: MemCache: inet:memcached:11211 (dead until 1481895267): connection closed in readline(). Marking dead.
.
It's a separate issues though.
| # Delete with explicit time=0 (can re-set immediately) | ||
| self.mc.set("my_key", "my_val") | ||
| self.mc.delete("my_key", time=0) | ||
| self.assertNotEqual(self.mc.set("my_key", "my_val"), 0) |
There was a problem hiding this comment.
Is this supposed to be a regression test? As far as I can tell, it's passing before the fix is applied (returning True). Why assertNotEqual rather than assertEqual?
There was a problem hiding this comment.
I added this test because that case (delete with time=0) wasn't covered by the test suite before, and there was a risk my touch() fix would change this behaviour. So I considered it as a safety net, with the added benefit of increasing test coverage.
assertNotEqual(self.mc.set("my_key", "my_val"), 0) to be consistent with the docstrings in memcache.py. It is stated:
- if
delete(time=0), subsequentset()should succeed immediately. - a successful
set()returns nonzero.
| self.mc.touch("my_key2") | ||
| time.sleep(2) | ||
| self.assertEqual(self.mc.get("my_key2"), "my_val") | ||
| # TODO: test it stays forever |
There was a problem hiding this comment.
Doesn't seem feasible. Again, I think we should use mocking to verify the values sent to the server without having to wait around to ensure the server handles those values correctly. I'll give it a try if you're stuck.
There was a problem hiding this comment.
I thought using mocking was larger than this issue and could be solved in another PR, but I can give it a try here!
|
Updated in #137. |
The
touch()method was throwing an error when time=0. The error itself wasn't showed properly because of a byte/string issue in aself.debuglog()call.This PR fix both issues, and provides regression tests.