mirror of https://github.com/nucypher/nucypher.git
Demonstrates a method to test self-availablity checks in successful conditions
parent
2b8533abb8
commit
5c9fb6823f
|
@ -244,12 +244,10 @@ class AvailabilitySensor:
|
|||
ursulas = self.sample(quantity=self.sample_size)
|
||||
succeeded, failed = 0, 0
|
||||
for ursula in ursulas:
|
||||
response = self._ursula.network_middleware.check_rest_availability(requesting_ursula=self._ursula,
|
||||
responding_ursula=ursula)
|
||||
if response.status_code == 200:
|
||||
available = self._ursula.network_middleware.check_rest_availability(requesting_ursula=self._ursula,
|
||||
responding_ursula=ursula)
|
||||
if available:
|
||||
succeeded += 1
|
||||
else:
|
||||
failed += 1
|
||||
return failed >= self.measurement_sensitivity
|
||||
|
||||
|
||||
|
|
|
@ -145,22 +145,25 @@ def make_rest_app(
|
|||
if request_address != requesting_ursula_address:
|
||||
return Response(status=400)
|
||||
|
||||
# Make a sandwich
|
||||
# Fetch and store teacher certificate
|
||||
certificate = this_node.network_middleware.get_certificate(host=requesting_ursula_address,
|
||||
port=requesting_ursula_port)
|
||||
certificate_filepath = this_node.node_storage.store_node_certificate(certificate=certificate)
|
||||
|
||||
# Make a Sandwich
|
||||
try:
|
||||
result = requests.get(f"https://{requesting_ursula.rest_interface}/public_information")
|
||||
result = requests.get(f"https://{requesting_ursula.rest_interface}/public_information", verify=certificate_filepath)
|
||||
except requests.exceptions.ConnectionError:
|
||||
return Response(status=400)
|
||||
|
||||
if result.status_code != 200:
|
||||
return Response(status=400)
|
||||
return Response(status=200)
|
||||
|
||||
# TODO
|
||||
# # Compare the results of the outer POST with the inner GET... yum
|
||||
# if result.content == request.data:
|
||||
# return Response(status=200)
|
||||
# else:
|
||||
# return Response(status=400)
|
||||
# Compare the results of the outer POST with the inner GET... yum
|
||||
if result.content == request.data:
|
||||
return Response(status=200)
|
||||
else:
|
||||
return Response(status=400)
|
||||
|
||||
@rest_app.route('/node_metadata', methods=["GET"])
|
||||
def all_known_nodes():
|
||||
|
|
|
@ -5,21 +5,15 @@ from twisted.internet import threads
|
|||
|
||||
@pt.inlineCallbacks
|
||||
def test_availability_sensor(blockchain_ursulas):
|
||||
|
||||
# Start up self-services
|
||||
ursula = blockchain_ursulas.pop()
|
||||
start_pytest_ursula_services(ursula=ursula)
|
||||
|
||||
def start_local_services():
|
||||
start_pytest_ursula_services(ursula=ursula)
|
||||
|
||||
def measure(result):
|
||||
def measure():
|
||||
ursula._availability_sensor.measure()
|
||||
assert True
|
||||
|
||||
def more(result):
|
||||
assert True
|
||||
|
||||
# Run the Callbacks
|
||||
d = threads.deferToThread(start_local_services)
|
||||
d.addCallback(measure)
|
||||
d.addCallback(more)
|
||||
|
||||
d = threads.deferToThread(measure)
|
||||
yield d
|
||||
|
|
Loading…
Reference in New Issue