Unclear use of timeout in unit tests

Hi

first of all, thank you for adding timeouts to the PLUnit test library.

I’m using: SWI-Prolog version 9.1.xxx

It is unclear to me how to use the set_test_options/1 predicate in conjunctions with timeouts.

My code looks like this:


:- use_module(library(plunit)).

:- begin_tests(timeout_tests).

test(fail_waking) :-
    sleep(30).

:- end_tests(timeout_tests).

:- set_test_options([timeout(10)]).

However, the test succeeds after 30 seconds. If instead I do not use the set_test_options/1 predicate, but instead I add the [timeout(10)] to the begin_tests(...), I get the desired result.

I am missing something. (Also, the timeout option is not listed among those that can be specified for begin_tests or test).

All the best

Marco

Works fine for me. I can imagine some issues with development environments that use threads. ?- set_test_options([timeout(2)]). in the end is the same as ?- set_prolog_flag(plunit_timeout, 2). If you execute this in a thread, for example by loading the file in a thread, it has no effect in the main thread. This issue affects several development environments when loading a file through the editor. The native PceEmacs as well as the Emacs sweep mode, Eclipse PDT plugin all use threads.

Prolog flags use copy semantics wrt. threads, i.e., setting a flag sets it only for the calling thread and new threads copy (actually implemented using copy-on-write) the flags from their creator.

Hi Jan

that is exactly how I was using it.

I hit the “Compile buffer” menu and it did not work.

This behavior wrt threading should be documented, as it is surprising as it is.

In any case it does not work if you “Consult” the file from the menu and the you issue “run_tests” at the prompt, especially if one of your tests is raising some other exception.

all the best

Marco

Better fixed, although I’m unsure whether that is possible. It probably is for most individual cases.

That also does its work from a background thread. Should work when using

?- [myfile].

from the prompt. It should also work if you open the app using the file, i.e., with the proper association by double clicking the .pl file in the finder/explorer/…