Skip to content

Commit

Permalink
Merge pull request #43 from littleskunk/develop
Browse files Browse the repository at this point in the history
Bugfix for ignored pings
  • Loading branch information
F483 committed Sep 3, 2015
2 parents 84f5e4b + fafc044 commit 9724685
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dataserv/Farmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def ping(self):
"""
farmer = self.lookup()
time_limit = (datetime.utcnow() - farmer.last_seen).seconds <= app.config["MAX_PING"]
time_limit = (datetime.utcnow() - farmer.last_seen).seconds >= app.config["MAX_PING"]

if time_limit:
farmer.last_seen = datetime.utcnow()
Expand Down
10 changes: 6 additions & 4 deletions tests/test_Farmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def test_ping(self):

# get register time, and make sure the ping work
register_time = farmer.last_seen
time.sleep(app.config["MAX_PING"] + 1) # ping faster than max_ping would be ignored
farmer.ping() # update last seen
ping_time = farmer.last_seen
self.assertTrue(register_time < ping_time)
Expand All @@ -69,13 +70,13 @@ def test_ping_time_limit(self):
farmer = Farmer(addresses["beta"])
farmer.register()

farmer.ping()
register_time = farmer.last_seen
time.sleep(2)
farmer.ping()

# should still be around 2
delta_seconds = int((farmer.last_seen - datetime.utcnow()).seconds)
self.assertNotEqual(delta_seconds, 0)
# should still be around 0
delta_seconds = int((farmer.last_seen - register_time).seconds)
self.assertEqual(delta_seconds, 0)

def test_height(self):
farmer = Farmer(addresses["gamma"])
Expand All @@ -101,6 +102,7 @@ def test_audit(self):

# get register time, and make sure the ping work
register_time = farmer.last_seen
time.sleep(app.config["MAX_PING"] + 1) # ping faster than max_ping would be ignored
farmer.audit()
ping_time = farmer.last_seen
self.assertTrue(register_time < ping_time)
Expand Down

0 comments on commit 9724685

Please sign in to comment.