From 15a68f8d28445d0222faa6683d91ea05e93c9968 Mon Sep 17 00:00:00 2001 From: Marcos Jaen Date: Tue, 17 Nov 2026 13:55:59 -0500 Subject: [PATCH 1/3] Parse launchprocess.sh arguments one flag at a time The script split its whole command line on '-', so any value with a dash in it (a path such as /opt/torq-prod/...) broke every argument after it, and .sys.bglaunch started a process with a broken -p. It now reads each -flag and the words after it up to the next flag, and builds the same start line as before. tests/bglaunchprocess waited a fixed 2 seconds after launching its second process and then looked it up in discovery, where it was not yet registered. The test process registers with discovery during its own start-up, while it runs the tests, and discovery's register calls back into the registering process (.servers.addw) and waits for the answer. Until the test process next called discovery, discovery could not accept the new process's connection, and that next call was the lookup itself. The suite now asks discovery until the process is there (up to 10 seconds). That process listens on a port of its own choosing (-p 0W), so discovery was the only way the suite could find it, and under a connection limit, such as KDB-X's free licence, TorQ turns discovery off (#727) and the last eight rows failed. With discovery off, the suite's processes now write their port to a file in KDBLOG when they start, and the suite finds the process there; run.sh removes the files. The suite also checks that each launch and kill is logged as successful, through TorQ's logging hook (.lg.ext). Its two checks that a killed process's pid is no longer in use list the user's processes by user id (ps -u $(id -u)): with USER unset, ps -u printed only its header, and the checks passed without checking anything. --- bin/launchprocess.sh | 59 ++++++++------------------------ tests/bglaunchprocess/run.sh | 4 +++ tests/bglaunchprocess/settings.q | 15 ++++++++ tests/bglaunchprocess/test.csv | 12 ++++--- 4 files changed, 42 insertions(+), 48 deletions(-) diff --git a/bin/launchprocess.sh b/bin/launchprocess.sh index 3c3ababcb..31dac85a9 100644 --- a/bin/launchprocess.sh +++ b/bin/launchprocess.sh @@ -6,51 +6,22 @@ #2:process had already been running #all defaults have been assigned in the q wrspper script: cloudutils.q -#for each cmd line argument, extract the argument and assign to relevant variable -cnt=0 -extra_flag_cnt=0 -IFS='-' -read -ra arg_arr <<< "$@" -for arg in "${arg_arr[@]}" -do - if [ "$cnt" -gt 0 ]; then - IFS=' ' - read -ra sub_arg_arr <<< "$arg" - case ${sub_arg_arr[0]} in - procname ) - procname=${sub_arg_arr[1]} - ;; - proctype ) - proctype=${sub_arg_arr[1]} - ;; - U ) - U_arg=${sub_arg_arr[1]} - ;; - localtime ) - localtime_arg=${sub_arg_arr[1]} - ;; - qcmd ) - qcmd_arg=${sub_arg_arr[1]} - ;; - p ) - p_arg=${sub_arg_arr[1]} - ;; - * ) - extra_flag_cnt=$(($extra_flag_cnt + 1)) - ;; +#for each cmd line argument (-name followed by its value, which can be several words), assign it to the relevant variable +#and keep any other flag, with its value, for the start line +#(this used to split the whole line on '-', so a value with a '-' in it, such as a path, broke every argument after it) +extra_arg_arr="" +while [ $# -gt 0 ]; do + key=${1#-}; shift; val="" + while [ $# -gt 0 ] && [ "${1:0:1}" != "-" ]; do val="${val:+$val }$1"; shift; done + case $key in + procname ) procname=$val ;; + proctype ) proctype=$val ;; + U ) U_arg=$val ;; + localtime ) localtime_arg=$val ;; + qcmd ) qcmd_arg=$val ;; + p ) p_arg=$val ;; + * ) extra_arg_arr+=" -$key${val:+ $val}" ;; esac - fi - cnt=$((cnt+1)) -done - -#to deal with any number of extra flags and args, take the last (extra_flag_cnt) arguments from the arg_arr -extra_arg_arr=" " -i=0 -a=$((extra_flag_cnt * -1)) -while [ $i -lt "$extra_flag_cnt" ] -do - extra_arg_arr+="-"${arg_arr[$(( $a+i ))]} - i=$(($i + 1)) done #define the startline diff --git a/tests/bglaunchprocess/run.sh b/tests/bglaunchprocess/run.sh index cc5c34c72..9b0c9cdfe 100644 --- a/tests/bglaunchprocess/run.sh +++ b/tests/bglaunchprocess/run.sh @@ -3,6 +3,9 @@ #path to test directory testpath=${KDBTESTS}/bglaunchprocess/ +#remove any port files left by an earlier run (written when discovery is off: see settings.q) +rm -f ${KDBLOG}/bglaunchprocess_*.port + #start procs ${TORQHOME}/torq.sh start all -csv ${testpath}/process.csv @@ -15,3 +18,4 @@ ${TORQHOME}/torq.sh start all -csv ${testpath}/process.csv #Shut down procs ${TORQHOME}/torq.sh stop all -csv ${testpath}/process.csv +rm -f ${KDBLOG}/bglaunchprocess_*.port diff --git a/tests/bglaunchprocess/settings.q b/tests/bglaunchprocess/settings.q index b66650ed1..1dfdbe9a5 100644 --- a/tests/bglaunchprocess/settings.q +++ b/tests/bglaunchprocess/settings.q @@ -5,3 +5,18 @@ input1:`procname`proctype`U`localtime`p`T`g`w`qcmd`custom`load!("test2";"test";" input2:`procname`proctype`load!("test3";"test";"${TORQHOME}/tests/bglaunchprocess/settings.q"); .servers.startup[]; +/the messages .sys.bglaunch and .sys.bgkill log, kept through TorQ's logging hook (.lg.ext) for the suite to check +bglogged:(); +.lg.ext:{[loglevel;proctype;proc;id;message;dict] if[id in `launchprocess`killprocess; bglogged,::enlist message]}; + +/the process launched with input2 listens on a port of its own choosing (-p 0W), and the suite finds it in discovery. +/Under a connection limit, such as KDB-X's free licence, TorQ turns discovery off and takes connection details from a +/file instead (DISCOVERYCONNECT in config/settings/default.q). Then each process of the suite writes its port to a file +/in KDBLOG when it starts, and the suite finds the process there. run.sh removes the files +portfile:{hsym`$getenv[`KDBLOG],"/bglaunchprocess_",string[x],".port"}; +if[(not .servers.DISCOVERYCONNECT) and 0 Date: Tue, 17 Nov 2026 13:56:00 -0500 Subject: [PATCH 2/3] Keep the name and type of a process started without the handlers; let .os.md create parent folders; fix stp/stripe - When discovery connects to a process it asks for .servers.getdetails, and a process started without TorQ's handlers (every tickerlogreplay process, by default) does not have it. The fallback then sent back a null procname and proctype, and discovery replaced the process.csv entry with one named after the script (torq.q) and with no type, so nothing could find the process by type afterwards. That only happens when discovery reaches the process after it is already listening, so it depended on start-up timing. The fallback now sends .proc.procname and .proc.proctype, which every TorQ process sets whether or not it loads the handlers. - .os.md ran mkdir without -p, so it failed whenever the parent folder did not exist yet. stp/stripe writes its results to tests/stp/results/stripe/, and in a fresh checkout, or when it runs on its own, tests/stp/results is not there yet. Windows' mkdir already creates the parents. - stp/stripe began with cd $HOME/TorQ/deploy/TorQ/latest and sourced setenv.sh from there, so it only ran on the machine it was written on. Like every other run.sh it now expects the environment to be set. Its RDBs subscribe with -.rdb.subfiltered 1, which reads rdbsub/rdbsub.csv, and neither TorQ nor the Starter Pack has those files any more (the Starter Pack's rdb.q used to write them); the suite now has its own, one per RDB, as docs/utilities.md describes, and points each RDB at its file. Two checks read .rdb.procnum, which the Starter Pack no longer defines; they now take the RDB's number from its name, as rdb.q does. After restarting two RDBs the suite reopened their handles before they were up; it now waits for each (up to 30 seconds). It replayed the logs on the restarted RDBs by sending "-11!`" joined to the log path, which q cannot parse when the path has a dash in it; it now sends the path itself. The last check slept one second after each of five batches (up to 100,000 rows); it now waits until each batch has arrived (up to 30 seconds). --- code/common/os.q | 2 +- code/handlers/trackservers.q | 2 +- tests/stp/stripe/process.csv | 8 ++++---- tests/stp/stripe/rdbsub/rdbsub1.csv | 3 +++ tests/stp/stripe/rdbsub/rdbsub2.csv | 3 +++ tests/stp/stripe/rdbsub/rdbsub3.csv | 3 +++ tests/stp/stripe/rdbsub/rdbsub4.csv | 3 +++ tests/stp/stripe/run.sh | 3 --- tests/stp/stripe/stripe.csv | 8 ++++---- 9 files changed, 22 insertions(+), 13 deletions(-) create mode 100644 tests/stp/stripe/rdbsub/rdbsub1.csv create mode 100644 tests/stp/stripe/rdbsub/rdbsub2.csv create mode 100644 tests/stp/stripe/rdbsub/rdbsub3.csv create mode 100644 tests/stp/stripe/rdbsub/rdbsub4.csv diff --git a/code/common/os.q b/code/common/os.q index 877a0c038..eef5b35fb 100644 --- a/code/common/os.q +++ b/code/common/os.q @@ -13,7 +13,7 @@ hdeldir:{[dirpath;pdir] if[not pdir;filelist:1_filelist]; .lg.o[`deldir;"deleting from directory : ",dirpath]; hdel each desc filelist} -md:{if[not Fex x;system"mkdir \"",pth[x],"\""]}; +md:{if[not Fex x;system("mkdir -p \"";"mkdir \"")[NT],pth[x],"\""]}; cpy:{system("cp ";"copy ")[NT],pth[x]," ",pth y} Vex:not 0h~type key`.@ df:{(`$("/";"\\")[NT]sv -1_v;`$-1#v:("/";"\\")[NT]vs pth(string x;x)[10h=type x])} diff --git a/code/handlers/trackservers.q b/code/handlers/trackservers.q index fda2115d3..6f0c05b99 100644 --- a/code/handlers/trackservers.q +++ b/code/handlers/trackservers.q @@ -138,7 +138,7 @@ getdetails:{(.z.f;.z.h;system"p";@[value;`.proc.procname;`];@[value;`.proc.proct / add session behind a handle addhw:{[hpuP;W] // Get the information around a process - info:`f`h`port`procname`proctype`attributes!(@[W;({$[`getdetails in key`.servers;.servers.getdetails[];(.z.f;.z.h;system"p";`;`;$[`getattributes in key`.proc;.proc.getattributes[];()!()])]};`);(`;`;0Ni;`;`;()!())]); + info:`f`h`port`procname`proctype`attributes!(@[W;({$[`getdetails in key`.servers;.servers.getdetails[];(.z.f;.z.h;system"p";@[value;`.proc.procname;`];@[value;`.proc.proctype;`];$[`getattributes in key`.proc;.proc.getattributes[];()!()])]};`);(`;`;0Ni;`;`;()!())]); if[0Ni~info`port;'"remote call failed on handle ",string W]; if[null name:info`procname;name:`$last("/"vs string info`f)except enlist""]; if[0=count name;name:`default]; diff --git a/tests/stp/stripe/process.csv b/tests/stp/stripe/process.csv index 4afdfa7ef..ebc9a4ea9 100644 --- a/tests/stp/stripe/process.csv +++ b/tests/stp/stripe/process.csv @@ -2,7 +2,7 @@ host,port,proctype,procname,U,localtime,g,T,w,load,startwithall,extras,qcmd localhost,{KDBBASEPORT}+100,discovery,discovery1,${TORQHOME}/appconfig/passwords/accesslist.txt,1,0,,,${KDBCODE}/processes/discovery.q,1,,q localhost,{KDBBASEPORT}+101,segmentedtickerplant,stp1,${TORQHOME}/appconfig/passwords/accesslist.txt,1,0,,,${KDBCODE}/processes/segmentedtickerplant.q,1,-schemafile ${TORQHOME}/database.q -.ds.numseg 4,q localhost,{KDBBASEPORT}+101,segmentedtickerplant,stpperf,${TORQHOME}/appconfig/passwords/accesslist.txt,1,0,,,${KDBCODE}/processes/segmentedtickerplant.q ${perfpath}/prep_test.q,0,-schemafile ${TORQHOME}/database.q,q -localhost,{KDBBASEPORT}+102,rdb,rdb1,${TORQHOME}/appconfig/passwords/accesslist.txt,1,1,180,,${KDBCODE}/processes/rdb.q,1,-.rdb.replaylog 0b -.rdb.subfiltered 1 -.ds.numseg 4,q -localhost,{KDBBASEPORT}+103,rdb,rdb2,${TORQHOME}/appconfig/passwords/accesslist.txt,1,1,180,,${KDBCODE}/processes/rdb.q,1,-.rdb.replaylog 0b -.rdb.subfiltered 1 -.ds.numseg 4,q -localhost,{KDBBASEPORT}+104,rdb,rdb3,${TORQHOME}/appconfig/passwords/accesslist.txt,1,1,180,,${KDBCODE}/processes/rdb.q,1,-.rdb.replaylog 0b -.rdb.subfiltered 1 -.ds.numseg 4,q -localhost,{KDBBASEPORT}+105,rdb,rdb4,${TORQHOME}/appconfig/passwords/accesslist.txt,1,1,180,,${KDBCODE}/processes/rdb.q,1,-.rdb.replaylog 0b -.rdb.subfiltered 1 -.ds.numseg 4,q \ No newline at end of file +localhost,{KDBBASEPORT}+102,rdb,rdb1,${TORQHOME}/appconfig/passwords/accesslist.txt,1,1,180,,${KDBCODE}/processes/rdb.q,1,-.rdb.replaylog 0b -.rdb.subfiltered 1 -.rdb.subcsv :${KDBTESTS}/stp/stripe/rdbsub/rdbsub1.csv -.ds.numseg 4,q +localhost,{KDBBASEPORT}+103,rdb,rdb2,${TORQHOME}/appconfig/passwords/accesslist.txt,1,1,180,,${KDBCODE}/processes/rdb.q,1,-.rdb.replaylog 0b -.rdb.subfiltered 1 -.rdb.subcsv :${KDBTESTS}/stp/stripe/rdbsub/rdbsub2.csv -.ds.numseg 4,q +localhost,{KDBBASEPORT}+104,rdb,rdb3,${TORQHOME}/appconfig/passwords/accesslist.txt,1,1,180,,${KDBCODE}/processes/rdb.q,1,-.rdb.replaylog 0b -.rdb.subfiltered 1 -.rdb.subcsv :${KDBTESTS}/stp/stripe/rdbsub/rdbsub3.csv -.ds.numseg 4,q +localhost,{KDBBASEPORT}+105,rdb,rdb4,${TORQHOME}/appconfig/passwords/accesslist.txt,1,1,180,,${KDBCODE}/processes/rdb.q,1,-.rdb.replaylog 0b -.rdb.subfiltered 1 -.rdb.subcsv :${KDBTESTS}/stp/stripe/rdbsub/rdbsub4.csv -.ds.numseg 4,q \ No newline at end of file diff --git a/tests/stp/stripe/rdbsub/rdbsub1.csv b/tests/stp/stripe/rdbsub/rdbsub1.csv new file mode 100644 index 000000000..f6b1c6628 --- /dev/null +++ b/tests/stp/stripe/rdbsub/rdbsub1.csv @@ -0,0 +1,3 @@ +tabname,filters,columns +trade,.ds.stripe[sym;0], +quote,.ds.stripe[sym;0], diff --git a/tests/stp/stripe/rdbsub/rdbsub2.csv b/tests/stp/stripe/rdbsub/rdbsub2.csv new file mode 100644 index 000000000..a7c5ded2e --- /dev/null +++ b/tests/stp/stripe/rdbsub/rdbsub2.csv @@ -0,0 +1,3 @@ +tabname,filters,columns +trade,.ds.stripe[sym;1], +quote,.ds.stripe[sym;1], diff --git a/tests/stp/stripe/rdbsub/rdbsub3.csv b/tests/stp/stripe/rdbsub/rdbsub3.csv new file mode 100644 index 000000000..b948541d0 --- /dev/null +++ b/tests/stp/stripe/rdbsub/rdbsub3.csv @@ -0,0 +1,3 @@ +tabname,filters,columns +trade,.ds.stripe[sym;2], +quote,.ds.stripe[sym;2], diff --git a/tests/stp/stripe/rdbsub/rdbsub4.csv b/tests/stp/stripe/rdbsub/rdbsub4.csv new file mode 100644 index 000000000..e16374c3d --- /dev/null +++ b/tests/stp/stripe/rdbsub/rdbsub4.csv @@ -0,0 +1,3 @@ +tabname,filters,columns +trade,.ds.stripe[sym;3], +quote,.ds.stripe[sym;3], diff --git a/tests/stp/stripe/run.sh b/tests/stp/stripe/run.sh index 4ec4b8807..d46ab9515 100644 --- a/tests/stp/stripe/run.sh +++ b/tests/stp/stripe/run.sh @@ -1,8 +1,5 @@ #!/bin/bash -cd $HOME/TorQ/deploy/TorQ/latest -source setenv.sh - # Handle command-line arguments source $KDBTESTS/flagparse.sh diff --git a/tests/stp/stripe/stripe.csv b/tests/stp/stripe/stripe.csv index 7ab59c43c..84fa6b2f7 100644 --- a/tests/stp/stripe/stripe.csv +++ b/tests/stp/stripe/stripe.csv @@ -33,13 +33,13 @@ run,0,0,q,"startorstopproc[""stop"";"" ""sv string[(),rdbDown];getenv[`testpath] run,0,0,q,"stpHandle @/: `.u.upd ,/: ((`trade;t row);(`quote;q row);(`heartbeat;`error))",1,,"Publish table updates while RDB(s) process is down" run,0,0,q,system "sleep 1",1,,"Wait for update to publish" run,0,0,q,"startorstopproc[""start"";"" ""sv string[(),rdbDown];getenv[`testpath],""/process.csv""]",1,,"Restart RDB(s) process" -run,0,0,q,rdbHandles:rdbNames!gethandle each rdbNames:exec procname from (.proc`readprocs).proc`file where proctype=`rdb,1,,"Reopen handle to RDBs" +run,0,0,q,"rdbHandles:rdbNames!{t:.z.p+0D00:00:30; while[(null h:gethandle x) and .z.p Date: Tue, 17 Nov 2026 13:56:00 -0500 Subject: [PATCH 3/3] Fix .html.wssub, and test the monitor's start wssub called sub, which builds a table schema, and the monitor's start subscribes lmchart, a function, so it stopped with 'type and start never returned its data. wssub now registers the handle against each name as sub does for a table, without building a schema, and ` still subscribes every value. tests/monitor is a new suite which starts a monitor and calls start, as its web page does on every connection. The checks: start runs; calling it twice leaves one subscription each; each subscription is the handle and ` (all syms), as the original wssub registers for a table; wssub ` subscribes every value; an unknown name is still rejected. --- code/common/html.q | 2 +- tests/monitor/monitor.csv | 9 +++++++++ tests/monitor/process.csv | 3 +++ tests/monitor/run.sh | 23 +++++++++++++++++++++++ tests/monitor/settings.q | 7 +++++++ 5 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 tests/monitor/monitor.csv create mode 100644 tests/monitor/process.csv create mode 100755 tests/monitor/run.sh create mode 100644 tests/monitor/settings.q diff --git a/code/common/html.q b/code/common/html.q index c927c8272..cbe6a1262 100644 --- a/code/common/html.q +++ b/code/common/html.q @@ -39,7 +39,7 @@ add:{$[(count w x)>i:w[x;;0]?.z.w;.[`.u.w;(x;i;1);union;y];w[x],:enlist(.z.w;y)] sub:{if[x~`;:sub[;y]each t];if[not x in t;'x];del[x].z.w;add[x;y]} // add wssub method - have to subscribe to everything, don't return anything -wssub:{sub[x;`];} +wssub:{if[x~`;.z.s each t;:(::)];if[not x in t;'x];del[x].z.w;w[x],:enlist(.z.w;`);} end:{(neg union/[w[;;0]])@\:(`.u.end;x)} diff --git a/tests/monitor/monitor.csv b/tests/monitor/monitor.csv new file mode 100644 index 000000000..2210f0283 --- /dev/null +++ b/tests/monitor/monitor.csv @@ -0,0 +1,9 @@ +action,ms,bytes,lang,code,repeat,minver,comment +before,0,0,q,.servers.startup[],1,,"Start TorQ connection management" +before,0,0,q,monHandle:gethandle[`monitor1],1,,"Open monitor handle" +true,0,0,q,@[{monHandle"start[]";1b};::;0b],1,,"start runs: .html.wssub subscribes lmchart, a function (it used to stop with 'type)" +run,0,0,q,"monHandle""start[]""",1,,"Call start again, as a refresh of the page does" +true,0,0,q,(1 1 1)~count each monHandle(`.html.w;monsubs),1,,"Calling start twice leaves one subscription each" +true,0,0,q,"all {(-6h=type x 0) and ` ~ x 1} each raze monHandle(`.html.w;monsubs)",1,,"Each subscription is the handle and ` (all syms), as the original wssub registers for a table" +true,0,0,q,"@[{monHandle(`.html.wssub;`);1b};::;0b]",1,,"wssub ` subscribes every value the monitor publishes (it used to stop with 'type)" +true,0,0,q,"0b~@[{monHandle(`.html.wssub;`nosuch);1b};::;0b]",1,,"wssub of a name the monitor does not publish is rejected, as before" diff --git a/tests/monitor/process.csv b/tests/monitor/process.csv new file mode 100644 index 000000000..3ebdaa08a --- /dev/null +++ b/tests/monitor/process.csv @@ -0,0 +1,3 @@ +host,port,proctype,procname,U,localtime,g,T,w,load,startwithall,extras,qcmd +localhost,{KDBBASEPORT}+100,discovery,discovery1,${TORQHOME}/appconfig/passwords/accesslist.txt,1,0,,,${KDBCODE}/processes/discovery.q,1,,q +localhost,{KDBBASEPORT}+101,monitor,monitor1,${TORQHOME}/appconfig/passwords/accesslist.txt,1,0,,,${KDBCODE}/processes/monitor.q,1,,q diff --git a/tests/monitor/run.sh b/tests/monitor/run.sh new file mode 100755 index 000000000..c0d0260a4 --- /dev/null +++ b/tests/monitor/run.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# Handle command-line arguments +source $KDBTESTS/flagparse.sh + +# Path to test directory +testpath=${KDBTESTS}/monitor + +# Start procs +${TORQHOME}/torq.sh start discovery1 monitor1 -csv ${testpath}/process.csv + +# Start test proc +/usr/bin/rlwrap q ${TORQHOME}/torq.q \ + -proctype test -procname test1 \ + -test ${testpath} \ + -load ${KDBTESTS}/helperfunctions.q ${testpath}/settings.q \ + -testresults ${KDBTESTS}/monitor/results/ \ + -runtime $run \ + -procfile ${testpath}/process.csv \ + $debug $stop $write $quiet + +# Shut down procs +${TORQHOME}/torq.sh stop discovery1 monitor1 -csv ${testpath}/process.csv diff --git a/tests/monitor/settings.q b/tests/monitor/settings.q new file mode 100644 index 000000000..82a716199 --- /dev/null +++ b/tests/monitor/settings.q @@ -0,0 +1,7 @@ +// IPC connection parameters +.servers.CONNECTIONS:`monitor; +.servers.USERPASS:`admin:admin; + +// the monitor's web page calls start on every connection, which subscribes these with .html.wssub +// (heartbeat and logmsg are tables, lmchart is a function) +monsubs:`heartbeat`logmsg`lmchart;