forked from LBRYCommunity/lbry-sdk
make DataStore clock mockable
This commit is contained in:
parent
9ed08f8fc9
commit
159e153393
1 changed files with 6 additions and 3 deletions
|
@ -1,5 +1,4 @@
|
||||||
import UserDict
|
import UserDict
|
||||||
import time
|
|
||||||
import constants
|
import constants
|
||||||
from interface import IDataStore
|
from interface import IDataStore
|
||||||
from zope.interface import implements
|
from zope.interface import implements
|
||||||
|
@ -9,17 +8,21 @@ class DictDataStore(UserDict.DictMixin):
|
||||||
""" A datastore using an in-memory Python dictionary """
|
""" A datastore using an in-memory Python dictionary """
|
||||||
implements(IDataStore)
|
implements(IDataStore)
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, getTime=None):
|
||||||
# Dictionary format:
|
# Dictionary format:
|
||||||
# { <key>: (<value>, <lastPublished>, <originallyPublished> <originalPublisherID>) }
|
# { <key>: (<value>, <lastPublished>, <originallyPublished> <originalPublisherID>) }
|
||||||
self._dict = {}
|
self._dict = {}
|
||||||
|
if not getTime:
|
||||||
|
from twisted.internet import reactor
|
||||||
|
getTime = reactor.seconds
|
||||||
|
self._getTime = getTime
|
||||||
|
|
||||||
def keys(self):
|
def keys(self):
|
||||||
""" Return a list of the keys in this data store """
|
""" Return a list of the keys in this data store """
|
||||||
return self._dict.keys()
|
return self._dict.keys()
|
||||||
|
|
||||||
def removeExpiredPeers(self):
|
def removeExpiredPeers(self):
|
||||||
now = int(time.time())
|
now = int(self._getTime())
|
||||||
|
|
||||||
def notExpired(peer):
|
def notExpired(peer):
|
||||||
if (now - peer[2]) > constants.dataExpireTimeout:
|
if (now - peer[2]) > constants.dataExpireTimeout:
|
||||||
|
|
Loading…
Add table
Reference in a new issue