SWI-Prolog / packages-mqi

Machine Query Interface
13 stars 5 forks source link

MQI test writing to global directory #15

Closed dmchurch closed 2 years ago

dmchurch commented 2 years ago

On a multi-user system, running the MQI test suite fails if you're the second user to do that.

[ctest] % PL-Unit: py_mqi_fast 
[ctest] % swipl in dir '/home/dchurch/swipl-devel/build.clang11/src'; Packed args: '-p~|~foreign=:/home/dchurch/swipl-devel/build.clang11/packages/plunit~|~-f~|~none~|~--no-packs~|~--on-error=status~|~-s~|~/home/dchurch/swipl-devel/packages/mqi/test_mqi.pl~|~-g~|~test_mqi~|~-t~|~halt'
[ctest] test_async_query (test_prologserver.TestPrologMQI) ... **** Note that some builds of Prolog will print out messages about
[ctest] 'Execution Aborted' or 'did not clear exception...' when running tests.  Ignore them.
[ctest] skipped ok
[ctest] test_async_query_slow (test_prologserver.TestPrologMQI) ... skipped ok
[ctest] test_connection_close_with_running_query (test_prologserver.TestPrologMQI) ... skipped ok
[ctest] test_connection_failure (test_prologserver.TestPrologMQI) ... ok
[ctest] test_debugging_options (test_prologserver.TestPrologMQI) ... skipped ok
[ctest] test_goal_thread_failure (test_prologserver.TestPrologMQI) ... skipped ok
[ctest] test_json_to_prolog (test_prologserver.TestPrologMQI) ... ok
[ctest] test_multiple_connections (test_prologserver.TestPrologMQI) ... skipped ok
[ctest] test_multiple_serial_connections (test_prologserver.TestPrologMQI) ... skipped ok
[ctest] test_protocol_edge_cases (test_prologserver.TestPrologMQI) ... skipped ok
[ctest] test_python_classes (test_prologserver.TestPrologMQI) ... ok
[ctest] test_quit (test_prologserver.TestPrologMQI) ... ok
[ctest] test_server_options_and_shutdown (test_prologserver.TestPrologMQI) ... ok
[ctest] test_server_options_and_shutdown_slow (test_prologserver.TestPrologMQI) ... skipped ok
[ctest] test_sync_query (test_prologserver.TestPrologMQI) ... skipped ok
[ctest] test_sync_query_slow (test_prologserver.TestPrologMQI) ... skipped ok
[ctest] test_unix_domain_socket_embedded (test_prologserver.TestPrologMQI) ... ok
[ctest] test_unknown_command (test_prologserver.TestPrologMQI) ... ok
[ctest] test_write_output_to_file_in_embedded_mode (test_prologserver.TestPrologMQI) ... Prolog: ERROR: Cannot access file /tmp/swiplserveroutput.txt for writing
[ctest] ERROR

The problem is in test_write_output_to_file_in_embedded_mode, here:

https://github.com/SWI-Prolog/packages-mqi/blob/6a25a6896c2c716c13cf186ec3ee6b16cf18e09a/python/test_prologserver.py#L1231

Recommend you use tempfile.NamedTemporaryFile in the with clause instead of crafting the path manually.

EricZinda commented 2 years ago

Thanks for reporting @dmchurch! I'll try to get a fixed pushed today

EricZinda commented 2 years ago

Fixed: https://github.com/SWI-Prolog/packages-mqi/commit/b24dd213c027e49764577347c8ef0405b30d4ddc

Looks like tempfile.NamedTemporaryFile can't be used since it doesn't allow the file to be reopened on Windows as the swiplserver library will try to do when the path is passed to it.

So I went with just using a guid:

tempDir = gettempdir()
tempFile = os.path.join(tempDir, str(uuid.uuid1()) + ".txt")

There was another place a predictable filename was being used (in a test that is off by default) so I fixed that too.