Changeset: 75970a2bc94e for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/75970a2bc94e Added Files: sql/test/BugTracker-2024/Tests/7536-mclient-forgets-to-flush.SQL.py Modified Files: clients/mapiclient/mclient.c sql/test/BugTracker-2024/Tests/All Branch: Aug2024 Log Message:
mclient: close redirected output stream before exiting Fixes #7536 diffs (60 lines): diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c --- a/clients/mapiclient/mclient.c +++ b/clients/mapiclient/mclient.c @@ -3879,6 +3879,8 @@ main(int argc, char **argv) } mapi_destroy(mid); + if (toConsole != stdout_stream && toConsole != stderr_stream) + close_stream(toConsole); mnstr_destroy(stdout_stream); mnstr_destroy(stderr_stream); if (priv.buf != NULL) diff --git a/sql/test/BugTracker-2024/Tests/7536-mclient-forgets-to-flush.SQL.py b/sql/test/BugTracker-2024/Tests/7536-mclient-forgets-to-flush.SQL.py new file mode 100644 --- /dev/null +++ b/sql/test/BugTracker-2024/Tests/7536-mclient-forgets-to-flush.SQL.py @@ -0,0 +1,35 @@ +import gzip +import os +import tempfile +import subprocess + + +# This SQL script redirects the output to a file (the %s). +# We will check that all output arrives there, even if it's a gzipped file. +SCRIPT = f"""\ +\>%s +SELECT 'Donald Knuth'; +""" + + +with tempfile.TemporaryDirectory('mtest') as dir: + dir = '/tmp/jvr' + outputfile = os.path.join(dir, 'output.txt.gz') + inputfile = os.path.join(dir, 'input.sql') + + with open(inputfile, 'w') as f: + f.write(SCRIPT % outputfile) + + with open(inputfile) as f: + subprocess.check_call([ + 'mclient', '-i', + inputfile, + '-p', os.environ['MAPIPORT'], + ]) + + with gzip.open(outputfile, 'rt', encoding='utf-8') as f: + content = f.read() + + # print(content) + + assert 'Donald Knuth' in content diff --git a/sql/test/BugTracker-2024/Tests/All b/sql/test/BugTracker-2024/Tests/All --- a/sql/test/BugTracker-2024/Tests/All +++ b/sql/test/BugTracker-2024/Tests/All @@ -63,3 +63,4 @@ 7524-right-outer-join 7528-jarowinkler-null 7534-is-distinct-from 7535-create-view-groupby-func +7536-mclient-forgets-to-flush _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org