Skip to content

Commit

Permalink
fixed timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
eddiebrissow committed Nov 20, 2024
1 parent 3830f3c commit 7e81788
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
21 changes: 12 additions & 9 deletions hyperon_das/query_engines/das_node_query_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,26 @@
class DASNodeQueryEngine(QueryEngine):
def __init__(self, backend, cache_controller, system_parameters: Dict[str, Any], **kwargs):
self.next_query_port = randint(60000, 61999)
self.timeout = system_parameters.get("timeout", 0)
self.timeout = kwargs.get("timeout", 0)
self.id = "localhost:" + str(self.next_query_port)
self.host = system_parameters.get("hostname", "localhost")
self.port = system_parameters.get("port", 35700)
self.host = kwargs.get("hostname", "localhost")
self.port = kwargs.get("port", 35700)
self.remote_das_node = ":".join([self.host, str(self.port)])
self.requestor = DASNode(self.id, self.remote_das_node)

def query(
self, query: Query, parameters: dict[str, Any] | None = None
) -> Union[Iterator[QueryAnswer], List[QueryAnswer]]:

def _parse_query(self, query, parameters):
tokenize = parameters.get("untokenize") if parameters else True
if tokenize:
if isinstance(query, list):
query = {"and": query}
print(query)
query = DictQueryTokenizer.tokenize(query).split()
print(query)
return DictQueryTokenizer.tokenize(query).split()
return query

def query(
self, query: Query, parameters: dict[str, Any] | None = None
) -> Union[Iterator[QueryAnswer], List[QueryAnswer]]:
query = self._parse_query(query, parameters)
response: RemoteIterator = self.requestor.pattern_matcher_query(query)
start = time.time()
try:
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/test_node_das.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
from pymongo import timeout

from hyperon_das.das import DistributedAtomSpace

Expand Down Expand Up @@ -119,8 +120,6 @@ def test_query_links_nodes_var(self, nodes, link_type):

for qq in query_answers:
print(qq)
# for nn in n:
# d.get_atom(qq.assignment.mapping[nn])

@pytest.mark.parametrize("query", [
{'atom_type': 'link',
Expand Down Expand Up @@ -151,14 +150,15 @@ def test_query_links_nodes_var(self, nodes, link_type):
{'atom_type': 'node', 'type': 'Symbol', 'name': '"Abd-B"'}]}
])
def test_node_das_query_test(self, query):
das = DistributedAtomSpace(query_engine="grpc", host="localhost", port=35700)
das = DistributedAtomSpace(query_engine="grpc", host="localhost", port=35700, timeout=5)
count = 0
try:
for q in das.query(query):
print(q)
assert isinstance(q, list)
assert len(q) > 0
count += 1
except:
pass
except Exception as e:
print(e)

# assert count == expected

0 comments on commit 7e81788

Please sign in to comment.