Skip to content

Commit f4de447

Browse files
committed
add tests for node class, and fix some bugs there
1 parent aa9d5d1 commit f4de447

File tree

2 files changed

+709
-1
lines changed

2 files changed

+709
-1
lines changed

src/chordnet/node.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ def stabilize(self):
264264
if not self.successor():
265265
return
266266

267+
x = None
268+
267269
try:
268270
# Get the predecessor of the current successor
269271
#print(f"stabilize: checking successor {self.successor().key} for predecessor", file=sys.stderr)
@@ -277,11 +279,12 @@ def stabilize(self):
277279
#print(f"stabilize: updated successor to {self.successor().key}", file=sys.stderr)
278280
# otherwise, we just notify them that we exist. This is usually for the first joiner to a ring.
279281

280-
self.notify(self.successor())
281282
#print(f"Node {self.address} - Updated Successor: {self.successor()}, Predecessor: {self.predecessor}", file=sys.stderr)
282283

283284
except Exception as e:
284285
print(f"Stabilize failed: {e}", file=sys.stderr)
286+
finally:
287+
self.notify(self.successor())
285288

286289

287290
def notify(self, potential_successor):
@@ -311,6 +314,7 @@ def notify(self, potential_successor):
311314
return False
312315
except Exception as e:
313316
print(f"Notify failed: {e}", file=sys.stderr)
317+
return False
314318

315319

316320
def start(self):
@@ -368,6 +372,8 @@ def _is_between(self, start, end, key):
368372
Returns:
369373
bool: True if the node is between start and end, False otherwise.
370374
"""
375+
if start == end: # this shouldn't happen
376+
return False
371377
if start < end:
372378
return start < key < end
373379
else: # Wrap around case
@@ -477,6 +483,9 @@ def _process_request(self, method, args):
477483
elif method == 'NOTIFY':
478484
# Parse the notifying node's details
479485
try:
486+
if len(args) < 3:
487+
return "INVALID_NODE"
488+
480489
notifier = self._parse_address(':'.join([args[0], args[1], args[2]]))
481490
return "OK" if self._be_notified(notifier) else "IGNORED"
482491

0 commit comments

Comments
 (0)