diff --git a/code/processes/rdb.q b/code/processes/rdb.q index d9e36dd1a..0a22f98aa 100644 --- a/code/processes/rdb.q +++ b/code/processes/rdb.q @@ -204,7 +204,9 @@ notpconnected:{[] /-resets timeout to 0 before EOD writedown timeoutreset:{.rdb.timeout:system"T";system"T 0"}; -restoretimeout:{system["T ", string .rdb.timeout]}; +/-(only where timeoutreset has run: an end of day which the timer above did not prepare, such as one forced on the +/-tickerplant, leaves the timeout as it is, and without the check the end of day stopped here on an undefined variable) +restoretimeout:{if[`timeout in key `.rdb;system["T ", string .rdb.timeout]]}; \d . /- make sure that the process will make a connection to each of the gateways and hdb types diff --git a/code/processes/wdb.q b/code/processes/wdb.q index f67a1a77b..44de1cbfb 100644 --- a/code/processes/wdb.q +++ b/code/processes/wdb.q @@ -397,10 +397,8 @@ endofdaymerge:{[dir;pt;tablist;mergelimits;hdbsettings;mergemethod;writedownmode $[tempfix2 and ((system "s")<0); [.lg.o[`merge;"merging on worker"]; {(neg x)(`.wdb.reloadsymfile;y);(neg x)(::)}[;.Q.dd[hdbsettings `hdbdir;`sym]] each .z.pd[]; - /-upsert .merge.partsize data to sort workers, only needed for part and hybrid method - if[(mergemode~`hybrid)or(mergemode~`part); - {(neg x)(upsert;`.merge.partsizes;y);(neg x)(::)}[;.merge.partsizes] each .z.pd[]; - ]; + /-upsert .merge.partsize data to sort workers, whatever the merge method: merge only merges the partitions listed there + {(neg x)(upsert;`.merge.partsizes;y);(neg x)(::)}[;.merge.partsizes] each .z.pd[]; merge[dir;pt;;mergelimits;hdbsettings;mergemethod;writedownmode] peach flip (key tablist;value tablist); /-clear out in memory table, .merge.partsizes, and call sort worker processes to do the same .lg.o[`eod;"Delete from partsizes"]; @@ -513,10 +511,8 @@ informgateway:{[message] informsortandreload:{[dir;pt;tablist;writedownmode;mergelimits;hdbsettings;mergemethod] .lg.o[`informsortandreload;"attempting to contact sort process to initiate data ",$[writedownmode~`default;"sort";"merge"]]; $[count sortprocs:.servers.getservers[`proctype;sorttypes;()!();1b;0b]; - [if[(mergemode~`hybrid)or(mergemode~`part); - // for part and hybrid method sort procs need access to partsizes table data - upsert data tp sort procs - {(neg x)(upsert;`.merge.partsizes;y);(neg x)(::)}[;.merge.partsizes] each exec w from sortprocs; - ]; + // sort procs need the partsizes table data whatever the merge method: merge only merges the partitions listed there + [{(neg x)(upsert;`.merge.partsizes;y);(neg x)(::)}[;.merge.partsizes] each exec w from sortprocs; {.[{neg[y]@x;neg[y][]};(x;y);{.lg.e[`informsortandreload;"unable to run command on sort and reload process"];'x}]}[(`.wdb.endofdaysort;dir;pt;tablist;writedownmode;mergelimits;hdbsettings;mergemethod);] each exec w from sortprocs; ]; [.lg.e[`informsortandreload;"can't connect to the sortandreload - no sortandreload process detected"]; diff --git a/code/segmentedtickerplant/stplog.q b/code/segmentedtickerplant/stplog.q index b587c7311..7ad4feaf4 100644 --- a/code/segmentedtickerplant/stplog.q +++ b/code/segmentedtickerplant/stplog.q @@ -5,12 +5,19 @@ currlog:([tbl:`symbol$()]logname:`symbol$();handle:`int$()) // View of log file handles for faster lookups loghandles::exec tbl!handle from currlog +// Re-establish the view above. A chained tickerplant which is not creating logs replaces it with a dictionary of +// no-ops (see init); without this, switching that process to create its own logs opened them but wrote nothing +restoreloghandles:{value "loghandles::exec tbl!handle from currlog"}; \d .stplg // Name of error log file errorlogname:@[value;`.stplg.errorlogname;`segmentederrorlogfile] +// Whether this process writes logs of its own: a tickerplant with createlogs on, or a chained tickerplant creating its +// own (loggingmode create). init opens them; dayrollover and .z.exit close them only where init opened them +haslogs:{(value `..createlogs) or .sctp.loggingmode=`create}; + // Create stp log directory // Log structure `:stplogs/date/tabname_time createdld:{[name;date] @@ -184,10 +191,12 @@ endofdaydata:@[value;`.stplg.endofdaydata;{ {`proctype`procname`tables!(.proc.pr // passes on eop messages to subscribers and rolls logs endofperiod:{[currentpd;nextpd;data] .lg.o[`endofperiod;"flushing remaining data to subscribers and clearing tables"]; - .stpps.pubclear[.stplg.t]; + // the published tables only: pubclear resets a table from the publish schemas, which have no entry for logmsg + .stpps.pubclear[.stpps.t]; .lg.o[`endofperiod;"executing end of period for ",.Q.s1 `currentperiod`nextperiod!(currentpd;nextpd)]; .stpps.endp[currentpd;nextpd;data]; // sends endofperiod message to subscribers currperiod::nextpd; // increments current period + nextperiod::nextpd+nextpd-currentpd; // and the next one: the SCTP rolls when its parent does if[.sctp.loggingmode=`create;periodrollover[data]] // logs only rolled if in create mode }; @@ -195,7 +204,7 @@ endofperiod:{[currentpd;nextpd;data] // eop log roll is stopped if eod is also going to be triggered (roll is not stopped in SCTP) stpeoperiod:{[currentpd;nextpd;data;rolllogs] .lg.o[`endofperiod;"flushing remaining data to subscribers and clearing tables"]; - .stpps.pubclear[.stplg.t]; + .stpps.pubclear[.stpps.t]; .lg.o[`stpeoperiod;"passing on endofperiod message to subscribers"]; .stpps.endp[currentpd;nextpd;data]; // sends endofperiod message to subscribers currperiod::nextperiod; // increments current period @@ -215,7 +224,7 @@ periodrollover:{[data] // common eod for STP and SCTP to send out eod messages and roll logs endofday:{[date;data] .lg.o[`endofday;"flushing remaining data to subscribers and clearing tables"]; - .stpps.pubclear[.stplg.t]; + .stpps.pubclear[.stpps.t]; .lg.o[`endofday;"executing end of day for ",.Q.s1 .eodtime.d]; .stpps.end[date;data]; // sends endofday message to subscribers dayrollover[data]; @@ -227,9 +236,12 @@ dayrollover:{[data] system"t 0";'"next roll is in the past"]; // timer off getnextendUTC[]; // grabs next end time .eodtime.d+:1; // increment current day - .stpm.updmeta[multilog][`close;logtabs;(data`p)+.eodtime.dailyadj]; // update meta tables - .stpm.metatable:0#.stpm.metatable; - closelog each logtabs; // close current day logs + // only a process with logs of its own has logs to close: a chained tickerplant in loggingmode none or parent has no + // log directory (.stplg.dldir), and closing failed there before the process was reinitialised + if[haslogs[]; + .stpm.updmeta[multilog][`close;logtabs;(data`p)+.eodtime.dailyadj]; // update meta tables + .stpm.metatable:0#.stpm.metatable; + closelog each logtabs]; // close current day logs init[string .proc.procname]; // reinitialise process .lg.o[`dayrollover;"end of day complete, new value for date is ",.Q.s1 .eodtime.d]; } @@ -258,7 +270,8 @@ init:{[dbname] i::1; seqnum::0; - if[(value `..createlogs) or .sctp.loggingmode=`create; + if[haslogs[]; + if[.sctp.chainedtp;`.[`restoreloghandles][]]; createdld[dbname;.eodtime.d]; openlog[multilog;dldir;;.z.p+.eodtime.dailyadj]each logtabs; // If appropriate, roll error log @@ -291,9 +304,9 @@ init:{[dbname] .lg.o[`stpexit; "Complete!"] ]; - // exit before logs are touched if process is an sctp NOT in create mode - if[.sctp.chainedtp and not .sctp.loggingmode=`create; :()]; + // exit before logs are touched if the process has none (an sctp NOT in create mode, or an stp with createlogs off) + if[not .stplg.haslogs[]; :()]; .lg.o[`stpexit;"Closing off log files"]; - .stpm.updmeta[.stplg.multilog][`close;.stpps.t;.z.p]; - .stplg.closelog each .stpps.t; + .stpm.updmeta[.stplg.multilog][`close;.stplg.logtabs;.z.p]; + .stplg.closelog each .stplg.logtabs; }] diff --git a/tests/helperfunctions.q b/tests/helperfunctions.q index b8ad95f21..84f66d970 100644 --- a/tests/helperfunctions.q +++ b/tests/helperfunctions.q @@ -16,6 +16,18 @@ isalive:{[proc] any "q" in' @[system;"pgrep -lf ",proc," -u $USER";" "]}; // Have slightly more fluid handle opening mechanic - update: force it to open a new handle each time gethandle:{[name] - .z.pc exec first w from .servers.SERVERS where procname=name; + .z.pc h:exec first w from .servers.SERVERS where procname=name; + // close the old handle as well: .z.pc only marks it closed, and a process can run out of connections + if[not null h;@[hclose;h;()]]; exec first w from .servers.getservers[`procname;name;()!();1b;1b] }; + +// Wait up to 30 seconds for a process to accept a connection, and return its handle (null if it never did): a fixed +// sleep after starting several processes at once is not always long enough +waitforhandle:{[name] t:.z.p+0D00:00:30; while[(null h:gethandle name) and .z.pabs "i"$logperiod-mends-mstarts,1,,"Check that the new metatable periods are within 1 microsec of the stated period" +true,0,0,q,all 1e6>abs "i"$logperiod-mends-mstarts,1,,"Check that the new metatable periods are within 1 millisecond of the stated period" true,0,0,q,(mseq+1h)~sctpHandle"exec last seq from .stpm.metatable",1,,"Check that the sequence number has incremented by 1" -true,0,0,q,tabs~raze sctpHandle"exec neg[count .stpps.t]#tbls from .stpm.metatable",1,,"Check that the correct tables are incremented" +true,0,0,q,tabs~raze sctpHandle"exec neg[count .stplg.logtabs]#tbls from .stpm.metatable",1,,"Check that the correct tables are incremented" true,0,0,q,("T"$-6#string currlog[`trade;`logname])~"t"$period`next,1,,"Check trade log name rolled" after,0,0,q,"system ""rm -rf "",1_string sctpHandle(`.stplg.dldir)",1,,"Delete logs folder" \ No newline at end of file diff --git a/tests/stp/chainedperiodend/run.sh b/tests/stp/chainedperiodend/run.sh index 0a2c08825..0d553355f 100755 --- a/tests/stp/chainedperiodend/run.sh +++ b/tests/stp/chainedperiodend/run.sh @@ -14,10 +14,10 @@ ${TORQHOME}/torq.sh start discovery1 stp1 sctp1 rdball rdbsymfilt rdbonetab -cs -proctype test -procname test1 \ -test ${testpath} \ -load ${KDBTESTS}/helperfunctions.q ${testpath}/settings.q \ - -results ${KDBTESTS}/stp/results/ \ + -testresults ${KDBTESTS}/stp/results/ \ -procfile ${testpath}/process.csv \ -runtime $run \ - $debug $stop $quiet + $debug $stop $write $quiet # Shut down procs ${TORQHOME}/torq.sh stop discovery1 stp1 sctp1 rdball rdbsymfilt rdbonetab -csv ${testpath}/process.csv diff --git a/tests/stp/chainedperiodend/settings.q b/tests/stp/chainedperiodend/settings.q index 8616e5db0..6b6883874 100644 --- a/tests/stp/chainedperiodend/settings.q +++ b/tests/stp/chainedperiodend/settings.q @@ -14,4 +14,8 @@ testquote:(10?`4;(5?50.0),50+5?50.0;10?100.0;10?100i;10?100i;10?.Q.A;10?.Q.A;10# endp:{[x;y;z] .tst.endp:@[{1+value x};`.tst.endp;0]}; // Flag to save tests to disk -.k4.savetodisk:1b; \ No newline at end of file +.k4.savetodisk:1b; + +// Wait up to 15 s for the tickerplant on handle h to roll its logs, so that the period the test measures is a whole +// one: the log opened at start-up (or by .stplg.init) starts part-way through a period +waitroll:{[h] i:h".stplg.i"; do[150; if[i.z.p+.eodtime.dailyadj",1,,"Check logging period times" true,0,0,q,stpHandle".stplg.nextperiod~.stplg.currperiod+.stplg.multilogperiod",1,,"Check logging period times" -run,0,0,q,"stpHandle @/: `.u.upd ,/: ((`trade;testtrade);(`quote;testquote);(`heartbeat;`error))",1,,"Send trade,quote and bad updates to STP" +run,0,0,q,"stpHandle @/: `.u.upd ,/: ((`trade;testtrade);(`quote;testquote);(`heartbeat;enlist`error))",1,,"Send trade,quote and bad updates to STP" run,0,0,q,system "sleep 1",1,,"Wait for updates to publish" run,0,0,q,![-11;] each stpHandle"exec logname from currlog where tbl in `trade`quote`segmentederrorlogfile",1,,"Get log contents" true,0,0,q,(c1+10)~rdbHandle @/: ("count trade";"count quote"),1,,"Check tables updated in the RDB" true,0,0,q,(l1+10)~count each (trade;quote),1,,"Check tables updated correctly in logs" -true,0,0,q,`error~.tst.err,1,,"Check error logs updated" -after,0,0,q,stpHandle(setenv;`KDBTPLOG;deflogs),1,,"Change STP logging directory to default" +true,0,0,q,`error~first .tst.err,1,,"Check error logs updated" +after,0,0,q,stpHandle({.stplg.kdbtplog:`$x};deflogs),1,,"Change STP logging directory to default" after,0,0,q,stpHandle(system;"t 1000"),1,,"Turn on timer" after,0,0,q,"system""rm -r "",tstlogs",1,,"Clear log directory" \ No newline at end of file diff --git a/tests/stp/custommode/metaroll.csv b/tests/stp/custommode/metaroll.csv index 9712d9ad9..0471b7e75 100644 --- a/tests/stp/custommode/metaroll.csv +++ b/tests/stp/custommode/metaroll.csv @@ -1,6 +1,6 @@ action,ms,bytes,lang,code,repeat,minver,comment before,0,0,q,.servers.startup[],1,,"Set up connection management" -before,0,0,q,stpHandle(setenv;`KDBTPLOG;tstlogs),1,,"Change STP logging directory" +before,0,0,q,stpHandle({.stplg.kdbtplog:`$x};tstlogs),1,,"Change STP logging directory" before,0,0,q,stpHandle"delete from `.stpm.metatable",1,,"Delete meta table" before,0,0,q,stpHandle"setup[`defaultbatch]",1,,"Re-init STP" before,0,0,q,stpHandle".stplg.init[string .proc.procname]",1,,"Re-init STP" @@ -37,5 +37,5 @@ true,0,0,q,period[`next]~stpHandle".stplg.currperiod",1,,"Check period rolled co true,0,0,q,all ("T"$-6#'string exec logname from clog where tbl in `trade`heartbeat)="t"$period[`next],1,,"Check trade/heartbeat log names rolled" true,0,0,q,qlog~clog[`quote;`logname],1,,"Check quote log not rolled" true,0,0,q,not (~/) exec logname from clog where tbl in `trade`quote,1,,"Check trade and quote writing to different logs" -after,0,0,q,stpHandle(setenv;`KDBTPLOG;deflogs),1,,"Change STP logging directory to default" +after,0,0,q,stpHandle({.stplg.kdbtplog:`$x};deflogs),1,,"Change STP logging directory to default" after,0,0,q,"system""rm -r "",tstlogs",1,,"Clear log directory" \ No newline at end of file diff --git a/tests/stp/custommode/process.csv b/tests/stp/custommode/process.csv index f7d8ec663..0c5383285 100644 --- a/tests/stp/custommode/process.csv +++ b/tests/stp/custommode/process.csv @@ -1,4 +1,4 @@ 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 -.stplg.multilog custom -.stplg.customcsv ${KDBTESTS}/stpcustom.csv,q +localhost,{KDBBASEPORT}+101,segmentedtickerplant,stp1,${TORQHOME}/appconfig/passwords/accesslist.txt,1,0,,,${KDBCODE}/processes/segmentedtickerplant.q,1,-schemafile ${KDBTESTS}/stp/custommode/database.q -.stplg.multilog custom -.stplg.customcsv ${KDBTESTS}/stpcustom.csv,q localhost,{KDBBASEPORT}+102,rdb,rdb1,${TORQHOME}/appconfig/passwords/accesslist.txt,1,1,180,,${KDBCODE}/processes/rdb.q,1,-.rdb.replaylog 0b,q diff --git a/tests/stp/eod/eodroutine.csv b/tests/stp/eod/eodroutine.csv index fc2708984..4cc7c2616 100644 --- a/tests/stp/eod/eodroutine.csv +++ b/tests/stp/eod/eodroutine.csv @@ -6,14 +6,14 @@ before,0,0,q,stpHandle:gethandle[`stp1],1,,"Get STP handle" before,0,0,q,rdbHandle:gethandle[`rdb1],1,,"Get RDB handle" before,0,0,q,rdbHandle"endofday:{[x;y] .tst.eod:1b}",1,,"Overwrite RDB endofday function" before,0,0,q,meta1:stpHandle".stpm.metatable",1,,"Get initial meta table" -before,0,0,q,tcount:count stpHandle".stpps.t",1,,"Get table count" +before,0,0,q,tcount:count stpHandle".stplg.logtabs",1,,"Get table count" before,0,0,q,adj:stpHandle".eodtime.dailyadj",1,,"Get time adjustment" before,0,0,q,eod1:stpHandle".eodtime.d",1,,"Get initial date" before,0,0,q,dir1:stpHandle".stplg.dldir",1,,"Get initial log directory" before,0,0,q,db:stpHandle"string .proc.procname",1,,"Get dbname" run,0,0,q,now:.z.p,1,,"Get current time" run,0,0,q,eoddata: stpHandle".stplg.endofdaydata[]",1,,"Get eod data to send" -run,0,0,q,"stpHandle(`.stplg.stpeod;.eodtime.d;eoddata,(enlist `p)!enlist now)",1,,"Run EoD function on STP" +run,0,0,q,"stpHandle(`.stplg.endofday;.eodtime.d;eoddata,(enlist `p)!enlist now)",1,,"Run EoD function on STP" run,0,0,q,meta2:get .Q.dd[dir1;`stpmeta],1,,"Get meta table from disk" run,0,0,q,eod2:stpHandle".eodtime.d",1,,"Get new date" run,0,0,q,dir2:stpHandle".stplg.dldir",1,,"Get new log directory" diff --git a/tests/stp/idbdefault/idbdefault.csv b/tests/stp/idbdefault/idbdefault.csv index 6c32642be..894c99234 100644 --- a/tests/stp/idbdefault/idbdefault.csv +++ b/tests/stp/idbdefault/idbdefault.csv @@ -2,32 +2,34 @@ action,ms,bytes,lang,code,repeat,minver,comment before,0,0,q,.servers.startup[],1,,"Start TorQ connection management" before,0,0,q,startproc["stp1"],1,,"Start STP" before,0,0,q,.proc.sys "sleep 3",1,,"Wait for proc to start" -before,0,0,q,stpHandle:gethandle[`stp1],1,,"Open STP handle" +before,0,0,q,stpHandle:waitforhandle[`stp1],1,,"Open STP handle, once the STP has started" before,0,0,q,logdir:1_string stpHandle(`.stplg.dldir),1,,"Get location of log directory" before,0,0,q,.proc.sys "sleep 3",1,,"Wait for connections to get set up" before,0,0,q,.os.md hdbdir,1,,"Creating HDB directory" -before,0,0,q,startproc each ("wdbdefault";"hdb1";"gateway1";"idbdefault"),1,,"Start WDB, HDB, GW and IDB" -before,0,0,q,.proc.sys "sleep 3",1,,"Wait for procs to start" -before,0,0,q,wdbHandle:gethandle[`wdbdefault],1,,"Open WDB handle" -before,0,0,q,idbHandle:gethandle[`idbdefault],1,,"Open IDB handle" -before,0,0,q,gwHandle:gethandle[`gateway1],1,,"Open GW handle" +before,0,0,q,startproc each ("wdbdefault";"hdb1";"idbdefault"),1,,"Start WDB, HDB and IDB" +before,0,0,q,wdbHandle:waitforhandle[`wdbdefault],1,,"Open WDB handle, once the WDB has started" +before,0,0,q,idbHandle:waitforhandle[`idbdefault],1,,"Open IDB handle, once the IDB has started" +before,0,0,q,waitforhandle[`hdb1],1,,"Wait for hdb1 to start" +before,0,0,q,startproc "gateway1",1,,"Start GW once the processes it connects to are up, so it finds them" +before,0,0,q,gwHandle:waitforhandle[`gateway1],1,,"Open GW handle, once the gateway has started" +before,0,0,q,waitforgateway[gwHandle;`idb`hdb!1 1],1,,"Wait for the gateway to connect to the IDB and the HDB" before,0,0,q,wdbHandle(set;`.wdb.numtab;`quote`trade!7 8),1,,"Set low treshold numbers for merging" -true,0,0,q,neg[gwHandle](`.gw.asyncexec;"select from trade where date=.z.D";`idb);0~count gwHandle[],1,,"Check if trade table initialised correctly with 0 rows" +true,0,0,q,neg[gwHandle](`.gw.asyncexec;"select from trade where date=.z.d";`idb);0~count gwHandle[],1,,"Check if trade table initialised correctly with 0 rows" run,0,0,q,"stpHandle @/: `.u.upd ,/: ((`trade;testtrade);(`quote;testquote))",1,,"Send trade and quote updates to STP" run,0,0,q,.proc.sys "sleep 3",1,,"Wait for updates to get published" -true,0,0,q,"neg[gwHandle](`.gw.asyncexec;""select from trade where date=.z.D, sym=`GOOG"";`idb);5~count gwHandle[]",1,,"Check trade update was correctly published" -true,0,0,q,"neg[gwHandle](`.gw.asyncexec;""select from quote_iex where date=.z.D"";`idb);0~count gwHandle[]",1,,"Check if table that not have been published has 0 rows" +true,0,0,q,"neg[gwHandle](`.gw.asyncexec;""select from trade where date=.z.d, sym=`GOOG"";`idb);5~count gwHandle[]",1,,"Check trade update was correctly published" +true,0,0,q,"neg[gwHandle](`.gw.asyncexec;""select from packets where date=.z.d"";`idb);0~count gwHandle[]",1,,"Check if table that not have been published has 0 rows" run,0,0,q,wdbHandle(`.u.end;`.wdb.currentpartition),1,,"Trigger EOD on WDB" run,0,0,q,.proc.sys "sleep 3",1,,"Wait for merge to HDB to happen" true,0,0,q,neg[gwHandle](`.gw.asyncexec;"select from trade where sym in `GOOG";`hdb);5~count gwHandle[],1,,"Check if HDB has the merged data" true,0,0,q,0=sum idbHandle@/: {raze ("count select from ";x)} each string wdbHandle(`.wdb.tablelist;()),1,,"Check if all tables have been correctly initilised with 0 rows after eod trigger" -true,0,0,q,neg[gwHandle](`.gw.asyncexec;"select from trade where date=.z.D+1";`idb);0~count gwHandle[],1,,"Check if IDB has been emptied." +true,0,0,q,neg[gwHandle](`.gw.asyncexec;"select from trade where date=.z.d+1";`idb);0~count gwHandle[],1,,"Check if IDB has been emptied." run,0,0,q,"stpHandle @/: `.u.upd ,/: ((`trade;testtrade);(`quote;testquote))",1,,"Send trade and quote updates to STP" run,0,0,q,.proc.sys "sleep 3",1,,"Wait for updates to get published" -true,0,0,q,"neg[gwHandle](`.gw.asyncexec;""select from trade where date=.z.D+1, sym=`GOOG"";`idb);5~count gwHandle[]",1,,"Check trade update was correctly published" +true,0,0,q,"neg[gwHandle](`.gw.asyncexec;""select from trade where date=.z.d+1, sym=`GOOG"";`idb);5~count gwHandle[]",1,,"Check trade update was correctly published" run,0,0,q,"stpHandle @/: `.u.upd ,/: ((`trade;enlist[(count[testtrade[0]]#`round2)],1_testtrade);(`quote;testquote))",1,,"Publish some new data to the tickplant with new symbol" run,0,0,q,.proc.sys "sleep 3",1,,"Wait for updates to get published" -true,0,0,q,"neg[gwHandle](`.gw.asyncexec;""select from trade where date=.z.D+1, sym=`round2"";`idb);10~count gwHandle[]",1,,"Check if IDB was reloaded and is aware if the new symbol" +true,0,0,q,"neg[gwHandle](`.gw.asyncexec;""select from trade where date=.z.d+1, sym=`round2"";`idb);10~count gwHandle[]",1,,"Check if IDB was reloaded and is aware if the new symbol" true,0,0,q,20~idbHandle"count trade",1,,"Check if row counts in IDB was reloaded correctly" after,0,0,q,hclose each (wdbHandle;gwHandle;idbHandle);,1,,"Close handles" after,0,0,q,stopproc each ("idbdefault";"wdbdefault";"hdb1";"gateway1";"stp1"),1,,"Stop all procs" diff --git a/tests/stp/idbpartbyenum/idbenum.csv b/tests/stp/idbpartbyenum/idbenum.csv index 41e563725..023ac338c 100644 --- a/tests/stp/idbpartbyenum/idbenum.csv +++ b/tests/stp/idbpartbyenum/idbenum.csv @@ -2,21 +2,24 @@ action,ms,bytes,lang,code,repeat,minver,comment before,0,0,q,.servers.startup[],1,,"Start TorQ connection management" before,0,0,q,startproc["stp1"],1,,"Start STP" before,0,0,q,.proc.sys "sleep 3",1,,"Wait for proc to start" -before,0,0,q,stpHandle:gethandle[`stp1],1,,"Open STP handle" +before,0,0,q,stpHandle:waitforhandle[`stp1],1,,"Open STP handle, once the STP has started" before,0,0,q,logdir:1_string stpHandle(`.stplg.dldir),1,,"Get location of log directory" before,0,0,q,.proc.sys "sleep 3",1,,"Wait for connections to get set up" before,0,0,q,.os.md hdbdir,1,,"Creating HDB directory" -before,0,0,q,startproc each ("wdbenum";"hdb1";"gateway1";"idbenum";"idbenum2"),1,,"Start WDB, HDB, GW, IDB and IDB2" -before,0,0,q,.proc.sys "sleep 3",1,,"Wait for procs to start" -before,0,0,q,wdbHandle:gethandle[`wdbenum],1,,"Open WDB handle" -before,0,0,q,idbHandle:gethandle[`idbenum],1,,"Open IDB handle" -before,0,0,q,gwHandle:gethandle[`gateway1],1,,"Open GW handle" +before,0,0,q,startproc each ("wdbenum";"hdb1";"idbenum";"idbenum2"),1,,"Start WDB, HDB and IDBs" +before,0,0,q,wdbHandle:waitforhandle[`wdbenum],1,,"Open WDB handle, once the WDB has started" +before,0,0,q,idbHandle:waitforhandle[`idbenum],1,,"Open IDB handle, once the IDB has started" +before,0,0,q,waitforhandle[`idbenum2],1,,"Wait for idbenum2 to start" +before,0,0,q,waitforhandle[`hdb1],1,,"Wait for hdb1 to start" +before,0,0,q,startproc "gateway1",1,,"Start GW once the processes it connects to are up, so it finds them" +before,0,0,q,gwHandle:waitforhandle[`gateway1],1,,"Open GW handle, once the gateway has started" +before,0,0,q,waitforgateway[gwHandle;`idb`hdb!2 1],1,,"Wait for the gateway to connect to the IDBs and the HDB" before,0,0,q,wdbHandle(set;`.wdb.numtab;`quote`trade!7 8),1,,"Set low treshold numbers for merging" true,0,0,q,neg[gwHandle](`.gw.asyncexec;"select from trade";`idb);0~count gwHandle[],1,,"Check if trade table initialised correctly with 0 rows" run,0,0,q,"stpHandle @/: `.u.upd ,/: ((`trade;testtrade);(`quote;testquote))",1,,"Send trade and quote updates to STP" run,0,0,q,.proc.sys "sleep 3",1,,"Wait for updates to get published" true,0,0,q,neg[gwHandle](`.gw.asyncexec;"select from trade where int=maptoint[`GOOG]";`idb);5~count gwHandle[],1,,"Check trade update was correctly published and maptoint works" -true,0,0,q,neg[gwHandle](`.gw.asyncexec;"select from quote_iex";`idb);0~count gwHandle[],1,,"Check if table that not have been published has 0 rows" +true,0,0,q,neg[gwHandle](`.gw.asyncexec;"select from packets";`idb);0~count gwHandle[],1,,"Check if table that not have been published has 0 rows" run,0,0,q,wdbHandle(`.u.end;`.wdb.currentpartition),1,,"Trigger EOD on WDB" run,0,0,q,.proc.sys "sleep 3",1,,"Wait for merge to HDB to happen" true,0,0,q,neg[gwHandle](`.gw.asyncexec;"select from trade where sym=`GOOG";`hdb);5~count gwHandle[],1,,"Check if HDB has the merged data" diff --git a/tests/stp/periodend/endp.csv b/tests/stp/periodend/endp.csv index 03cbdc72c..ed771592d 100644 --- a/tests/stp/periodend/endp.csv +++ b/tests/stp/periodend/endp.csv @@ -2,20 +2,21 @@ action,ms,bytes,lang,code,repeat,minver,comment beforeany,0,0,q,system "sleep 5",1,,"Wait for all procs to go up" before,0,0,q,.servers.startup[],1,,"Get connection management set up" before,0,0,q,stpHandle:gethandle[`stp1],1,,"Get STP handle" +before,0,0,q,waitroll stpHandle,1,,"Wait for a log roll, so that the period measured below is a whole one" before,0,0,q,rdbHandles:`all`sym`tab!gethandle each `rdball`rdbsymfilt`rdbonetab,1,,"Get RDB handles" before,0,0,q,(value rdbHandles) @\: (set;`endofperiod;endp),1,,"Set dummy endofperiod function on each sub" -before,0,0,q,tcount:count tabs:stpHandle".stpps.t",1,,"Get number of tables" +before,0,0,q,tcount:count tabs:stpHandle".stplg.logtabs",1,,"Get number of tables" before,0,0,q,logperiod:stpHandle".stplg.multilogperiod",1,,"Get logging period" before,0,0,q,metacount:stpHandle"count .stpm.metatable",1,,"Get initial table count" -before,0,0,q,mstarts:stpHandle"neg[count .stpps.t]#exec start from .stpm.metatable",1,,"Get most recent start times" +before,0,0,q,mstarts:stpHandle"neg[count .stplg.logtabs]#exec start from .stpm.metatable",1,,"Get most recent start times" before,0,0,q,mseq:stpHandle"exec last seq from .stpm.metatable",1,,"Get most recent sequence number" before,0,0,q,period:`curr`next!stpHandle".stplg[`currperiod`nextperiod]",1,,"Get current and next roll periods" before,0,0,q,system "sleep 11",1,,"Wait for a full period" -run,0,0,q,mends:(stpHandle"neg[2*count .stpps.t]#exec end from .stpm.metatable") except 0Np,1,,"Get previous period end times" +run,0,0,q,mends:(stpHandle"neg[2*count .stplg.logtabs]#exec end from .stpm.metatable") except 0Np,1,,"Get previous period end times" run,0,0,q,currlog:stpHandle"currlog",1,,"Get currlog table" true,0,0,q,all 0=(value rdbHandles) @\: (`.tst.endp),1,,"Check the endofperiod function has been triggered once on all subs" true,0,0,q,(metacount+tcount)~stpHandle"count .stpm.metatable",1,,"Check that the STP metatable count has increased correctly" -true,0,0,q,all 1e6>abs "i"$logperiod-mends-mstarts,1,,"Check that the new metatable periods are within 1 microsec of the stated period" +true,0,0,q,all 1e6>abs "i"$logperiod-mends-mstarts,1,,"Check that the new metatable periods are within 1 millisecond of the stated period" true,0,0,q,(mseq+1h)~stpHandle"exec last seq from .stpm.metatable",1,,"Check that the sequence number has incremented by 1" -true,0,0,q,tabs~raze stpHandle"exec neg[count .stpps.t]#tbls from .stpm.metatable",1,,"Check that the correct tables are incremented" +true,0,0,q,tabs~raze stpHandle"exec neg[count .stplg.logtabs]#tbls from .stpm.metatable",1,,"Check that the correct tables are incremented" true,0,0,q,("T"$-6#string currlog[`trade;`logname])~"t"$period`next,1,,"Check trade log name rolled" \ No newline at end of file diff --git a/tests/stp/periodend/settings.q b/tests/stp/periodend/settings.q index 34eb51309..dde680ee1 100644 --- a/tests/stp/periodend/settings.q +++ b/tests/stp/periodend/settings.q @@ -10,4 +10,8 @@ testtrade:((5#`GOOG),5?`4;10?100.0;10?100i;10#0b;10?.Q.A;10?.Q.A;10#`buy); testquote:(10?`4;(5?50.0),50+5?50.0;10?100.0;10?100i;10?100i;10?.Q.A;10?.Q.A;10#`3); // End period function to send to subs -endp:{[x;y;z] .tst.endp:@[{1+value x};`.tst.endp;0]}; \ No newline at end of file +endp:{[x;y;z] .tst.endp:@[{1+value x};`.tst.endp;0]}; + +// Wait up to 15 s for the tickerplant on handle h to roll its logs, so that the period the test measures is a whole +// one: the log opened at start-up (or by .stplg.init) starts part-way through a period +waitroll:{[h] i:h".stplg.i"; do[150; if[i