I started a local Pengines server with an ancestors
app defined as in
I then load the script test_client.pl
with the code below and make the query `test_genealogist_queries`.
The trace I get shows that
- For all the
pengine_ask
queries except the last one, I get a series of success events where all** of them have More = true** (including the last success event for the query). The very last query is the only one for which I get a last success event with More = false. - For the first
pengine_ask
query, (q1 in predicatetest_query
), I get a failure event after I ask for an additional event past the last success (which has a More=true). That failure event is expected. However, right after that failure event I get an error event. This only happens for the first query. - The code shows the only workaround I found which consists of always asking for an additional event after a failure event, using a timeout. If that additional event comes and is an error it is ignored; if it doesn’t come we proceed after a timing out.
Questions, should anybody know:
- Why do I get a success event with
More=true
even for the last answer to the queries? - Why does this happen for all but the last query?
- Why do I get an error event after a failure, but only for the first query?
- Am I dong something fundamentally wrong that I should fix?
- Is there a better workaround, should all this be bug-related?
Thanks in advance.
% test_client.pl
:- use_module(library(pengines)).
% Test specific queries
test_genealogist_queries :-
pengine_create([
server('http://localhost:3030'), % not required if on the same host
application(genealogist),
id(ID),
destroy(false) % keep pengine alive for multiple queries
]),
% Test multiple queries
test_query(ID, q1, 'Find all ancestors of sally', ancestor_descendant(X, sally)),
test_query(ID, q2, 'Find all descendants of mike', ancestor_descendant(mike, X)),
test_query(ID, q3, 'Find all siblings', siblings(X, Y)),
test_query(ID, q4, 'Find all parent-child relationships', parent_child(X, Y)),
pengine_destroy(ID),
writeln('<--- Destroy pengine after all queries').
test_query(ID, QueryName, Description, Query) :-
format('~n--- ~w: ~w ---~n', [QueryName, Description]),
pengine_ask(ID, Query, []),
format('<--- Ask: ~w: ~w~n', [QueryName, Query]),
collect_all_solutions(ID, QueryName).
% in seconds
timeout(0.1).
collect_all_solutions(ID, QueryName) :-
timeout(Timeout),
pengine_event(Event, [listen(ID), timeout(Timeout)]),
format('---> ~w Event: ~w~n', [QueryName, Event]),
( Event = create(ID, Features)
-> format(' Pengine created: ~w: ~w~n', [ID, Features]),
pengine_next(ID, []),
writeln('<--- Next'),
collect_all_solutions(ID, QueryName)
; ( Event = success(_, Bindings, _Projection, _Time, More)
; Event = success(_, Bindings, More)
)
-> format(' Result: ~w, More: ~w~n', [Bindings, More]),
( More = true
-> pengine_next(ID, []),
writeln('<--- Next'),
collect_all_solutions(ID, QueryName)
; true
)
; Event = failure(Term, _Time)
-> format(' No more solutions [~w].~n', [Term]),
% pengine_next(ID, []),
% writeln('<--- Next'),
collect_all_solutions(ID, QueryName) % check for any following (error) event
; Event = error(_, Error)
-> format(' Error: ~w~n', [Error]) % without further event collection or processing
; Event = output(_, Output)
-> format(' Output: ~w~n', [Output]) % without further event collection or processing
; Event = prompt(_, Prompt)
-> format(' Prompt: ~w~n', [Prompt]) % without further event collection or processing
; Event = timeout
-> format(' Timeout~n', []) % without further event collection or processing
; format(' Unknown event: ~w~n', [Event])
).
% Main test runner
main :-
format('Testing pengines server...~n'),
test_genealogist_queries,
format('~nTest completed.~n').