Skip to content

Commit 11ebe47

Browse files
authored
add scripts for manual testing (#14)
* scaffold script organization * formatting * add manual scripts. ignore bpython from typechecking * add step function to manual scripts for convenience * add manual scripts * abstract step function to separate module
1 parent 35a10d8 commit 11ebe47

File tree

9 files changed

+91
-1
lines changed

9 files changed

+91
-1
lines changed

pyproject.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,13 @@ convention = "google"
115115
python_version = "3.10"
116116
warn_return_any = true
117117
warn_unused_configs = true
118-
files = ["src", "tests"]
118+
files = ["src", "tests", "scripts"]
119119
exclude = [
120120
'(^|.*/)__pycache__/', # matches __pycache__ at any depth
121121
'(^|.*/).ruff_cache/',
122122
'(^|.*/).mypy_cache/',
123123
]
124+
125+
[[tool.mypy.overrides]]
126+
module = ["bpython"]
127+
ignore_missing_imports = true

scripts/auto/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""__init__.py: nothing to see here..."""

scripts/auto/anchor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""anchor.py: creates and starts an anchor node for testing."""

scripts/auto/joiner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""joiner.py: creates a joining node for debugging."""

scripts/manual/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""__init__.py: nothing to see here..."""

scripts/manual/anchor.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""anchor.py: creates and starts an anchor node for testing."""
2+
import sys
3+
4+
import bpython
5+
from step import step #type: ignore
6+
7+
from chordnet import Node as ChordNode
8+
9+
10+
def main() -> None:
11+
"""Creates a new ring with this computer as the only node."""
12+
if len(sys.argv) != 3:
13+
print("usage: [uv run] python anchor.py ip_addr port_no")
14+
exit(1)
15+
16+
ip = sys.argv[1]
17+
port = int(sys.argv[2])
18+
19+
node = ChordNode(ip, port)
20+
# create (start) the ring
21+
node.create()
22+
print(f"Node created as \"node\": {node.address}", file=sys.stderr)
23+
repl_locals = {
24+
'node': node,
25+
'step': step,
26+
}
27+
print("starting repl. access `node`, advance with `step(node)`")
28+
bpython.embed(locals_=repl_locals)
29+
node.stop()
30+
31+
32+
if __name__ == '__main__':
33+
main()

scripts/manual/joiner.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""joiner.py: creates a joining node for debugging."""
2+
import sys
3+
4+
import bpython
5+
from step import step #type: ignore
6+
7+
from chordnet import Node as ChordNode
8+
9+
10+
def main() -> None:
11+
"""Creates a new ring with this computer as the only node."""
12+
if len(sys.argv) != 5:
13+
print("usage: [uv run] python " \
14+
"joiner.py this_ip this_port target_ip target_port")
15+
exit(1)
16+
17+
# Get IP and port from command line arguments
18+
ip = sys.argv[1]
19+
port = int(sys.argv[2])
20+
target_ip = sys.argv[3]
21+
target_port = int(sys.argv[4])
22+
23+
# Create and join node
24+
node = ChordNode(ip, port)
25+
node.join(target_ip, target_port)
26+
repl_locals = {
27+
'node': node,
28+
'step': step,
29+
}
30+
print("starting repl. access `node`, advance with `step(node)`")
31+
bpython.embed(locals_=repl_locals)
32+
node.stop()
33+
34+
35+
if __name__ == '__main__':
36+
main()

scripts/manual/step.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""step.py: helper for manual scripts."""
2+
3+
from chordnet import Node as ChordNode
4+
5+
6+
def step(node: ChordNode) -> None:
7+
"""Runs the periodic tasks for the node once."""
8+
node.stabilize()
9+
node.fix_fingers()
10+
11+
print(f"pred: {node.predecessor} succ: {node.successor()}")
12+
print(node.finger_table)

src/chordnet/address.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def __eq__(self, other: object) -> bool:
5858
"""
5959
if not isinstance(other, Address):
6060
return NotImplemented
61+
6162
return (self.ip == other.ip and
6263
self.port == other.port and
6364
self.key == other.key)

0 commit comments

Comments
 (0)