Index: db.scm ================================================================== --- db.scm +++ db.scm @@ -60,11 +60,11 @@ (dbexists (file-exists? dbpath)) (db (sqlite3:open-database dbpath)) ;; (never-give-up-open-db dbpath)) (handler (make-busy-timeout (if (args:get-arg "-override-timeout") (string->number (args:get-arg "-override-timeout")) 136000)))) ;; 136000))) ;; 136000 = 2.2 minutes - (debug:print-info 11 "open-db, dbpath=" dbpath) + (debug:print-info 11 "open-db, dbpath=" dbpath " argv=" (argv)) (sqlite3:set-busy-handler! db handler) (if (not dbexists) (db:initialize db)) (db:set-sync db) db)) @@ -1133,11 +1133,11 @@ (mutex-lock! *incoming-mutex*) (set! *last-db-access* (current-seconds)) (set! *incoming-data* (cons (vector qry-name (current-milliseconds) - params) + remparam) *incoming-data*)) (mutex-unlock! *incoming-mutex*) ;; NOTE: if cached? is #f then this call must be run immediately ;; but first all calls in the queue are run first in the order ;; of their time stamp @@ -1154,33 +1154,36 @@ (define (cdb:client-call zmq-socket . params) (debug:print-info 11 "cdb:client-call zmq-socket=" zmq-socket " params=" params) (let ((zdat (db:obj->string params)) ;; (with-output-to-string (lambda ()(serialize params)))) (res #f)) - (print "cdb:client-call before send message") + (print "cdb:client-call before send message, params=" params) (send-message zmq-socket zdat) (print "cdb:client-call after send message") (set! res (db:string->obj (receive-message zmq-socket zdat))) (debug:print-info 11 "zmq-socket " (car params) " res=" res) res)) (define (cdb:test-set-status-state zmqsocket test-id status state msg) (if msg - (cdb:client-call zmqsocket 'state-status-msg state status msg test-id) - (cdb:client-call zmqsocket 'state-status state status test-id))) ;; run-id test-name item-path minutes cpuload diskfree tmpfree) + (cdb:client-call zmqsocket 'state-status-msg #t state status msg test-id) + (cdb:client-call zmqsocket 'state-status #t state status test-id))) ;; run-id test-name item-path minutes cpuload diskfree tmpfree) (define (cdb:test-rollup-test_data-pass-fail zmqsocket test-id) (cdb:client-call zmqsocket 'test_data-pf-rollup #t test-id test-id test-id)) (define (cdb:pass-fail-counts zmqsocket test-id fail-count pass-count) - (cdb:client-call zmqsocket 'pass-fail-counts fail-count pass-count test-id)) + (cdb:client-call zmqsocket 'pass-fail-counts #t fail-count pass-count test-id)) -(define (cdb:tests-register-test zmqsocket db run-id test-name item-path) +(define (cdb:tests-register-test zmqsocket run-id test-name item-path) (let ((item-paths (if (equal? item-path "") (list item-path) (list item-path "")))) - (cdb:client-call zmqsocket 'register-test run-id test-name item-path))) + (cdb:client-call zmqsocket 'register-test #t run-id test-name item-path))) + +(define (cdb:flush-queue zmqsocket) + (cdb:client-call zmqsocket 'flush #f)) ;; The queue is a list of vectors where the zeroth slot indicates the type of query to ;; apply and the second slot is the time of the query and the third entry is a list of ;; values to be applied ;; @@ -1211,11 +1214,11 @@ db (lambda () (debug:print-info 4 "flushing " data " to db") (for-each (lambda (entry) (let ((params (vector-ref entry 2))) - (debug:print-info 4 "Applying " entry " to params " params) + ;; (debug:print-info 4 "Applying " entry " to params " params) (case (vector-ref entry 0) ((state-status) (apply sqlite3:execute state-status-stmt params)) ((state-status-msg) (apply sqlite3:execute state-status-msg-stmt params)) @@ -1243,26 +1246,12 @@ (if (> cache-size *max-cache-size*) (set! *max-cache-size* cache-size))) )) #f)) -(define cdb:flush-queue db:write-cached-data) - (define (db:roll-up-pass-fail-counts db run-id test-name item-path status) - - - - - - ;; NEEDED!? - ;; (rdb:flush-queue) - - - - - - + (cdb:flush-queue *runremote*) (if (and (not (equal? item-path "")) (or (equal? status "PASS") (equal? status "WARN") (equal? status "FAIL") (equal? status "WAIVED") @@ -1286,10 +1275,11 @@ ELSE 'COMPLETED' END, status=CASE WHEN fail_count > 0 THEN 'FAIL' WHEN pass_count > 0 AND fail_count=0 THEN 'PASS' ELSE 'UNKNOWN' END WHERE run_id=? AND testname=? AND item_path='';" run-id test-name run-id test-name)) #f) + #f)) ;;====================================================================== ;; Tests meta data ;;====================================================================== @@ -1421,18 +1411,18 @@ (SELECT count(id) FROM test_data WHERE test_id=? AND status like 'pass') AS pass_count;" test-id test-id) (sqlite3:finalize! tdb) ;; Now rollup the counts to the central megatest.db - (rdb:pass-fail-counts test-id fail-count pass-count) + (cdb:pass-fail-counts *remoterun* test-id fail-count pass-count) ;; (sqlite3:execute db "UPDATE tests SET fail_count=?,pass_count=? WHERE id=?;" ;; fail-count pass-count test-id) (thread-sleep! 1) ;; play nice with the queue by ensuring the rollup is at least 10ms later than the set ;; if the test is not FAIL then set status based on the fail and pass counts. - (rdb:test-rollup-test_data-pass-fail test-id) + (cdb:test-rollup-test_data-pass-fail *remoterun* test-id) ;; (sqlite3:execute ;; db ;;; NOTE: Should this be WARN,FAIL? A WARN is not a FAIL????? BUG FIXME ;; "UPDATE tests ;; SET status=CASE WHEN (SELECT fail_count FROM tests WHERE id=?) > 0 ;; THEN 'FAIL' Index: megatest.scm ================================================================== --- megatest.scm +++ megatest.scm @@ -258,29 +258,12 @@ ;;====================================================================== ;; Start the server - can be done in conjunction with -runall or -runtests (one day...) ;; we start the server if not running else start the client thread ;;====================================================================== (if (args:get-arg "-server") - (let* ((toppath (setup-for-run)) - (db (if toppath (open-db) #f))) - (debug:print-info 0 "Starting the standalone server") - (if db - (let* ((th2 (make-thread (lambda () - (server:run (args:get-arg "-server"))))) - (th3 (make-thread (lambda () - (server:keep-running db))))) - (thread-start! th3) - (thread-start! th2) - (thread-join! th3) - (set! *didsomething* #t)) - (debug:print 0 "ERROR: Failed to setup for megatest"))) - ;; not starting server? then start the client - (if (server:client-setup) - (debug:print-info 0 "connected as client") - (begin - (debug:print 0 "ERROR: Failed to connect as client") - (exit)))) + (server:launch) + (server:client-launch)) ;;====================================================================== ;; Remove old run(s) ;;====================================================================== @@ -849,10 +832,14 @@ (set! *didsomething* #t))) ;;====================================================================== ;; Exit and clean up ;;====================================================================== + +;; this is the socket if we are a client +(if (socket? *runremote*) + (close-socket *runremote*)) (if (not *didsomething*) (debug:print 0 help)) ;; (if *runremote* (rpc:close-all-connections!)) Index: server.scm ================================================================== --- server.scm +++ server.scm @@ -76,30 +76,33 @@ (loop))))))) ;; run server:keep-running in a parallel thread to monitor that the db is being ;; used and to shutdown after sometime if it is not. ;; -(define (server:keep-running db) +(define (server:keep-running) ;; if none running or if > 20 seconds since ;; server last used then start shutdown - (let loop () - (thread-sleep! 20) ;; no need to do this very often - (let ((numrunning (db:get-count-tests-running db))) - (if (or (> numrunning 0) - (> (+ *last-db-access* 60)(current-seconds))) - (begin - (debug:print-info 0 "Server continuing, tests running: " numrunning ", seconds since last db access: " (- (current-seconds) *last-db-access*)) - (loop)) - (begin - (debug:print-info 0 "Starting to shutdown the server side") - ;; need to delete only *my* server entry (future use) - (db:del-var db "SERVER") - (thread-sleep! 10) - (debug:print-info 0 "Max cached queries was " *max-cache-size*) - (debug:print-info 0 "Server shutdown complete. Exiting") - ;; (exit))) - ))))) + (let loop ((count 0)) + (thread-sleep! 1) ;; no need to do this very often + (db:write-cached-data) + (if (< count 100) + (loop 0) + (let ((numrunning (open-run-close db:get-count-tests-running #f))) + (if (or (> numrunning 0) + (> (+ *last-db-access* 60)(current-seconds))) + (begin + (debug:print-info 0 "Server continuing, tests running: " numrunning ", seconds since last db access: " (- (current-seconds) *last-db-access*)) + (loop (+ count 1))) + (begin + (debug:print-info 0 "Starting to shutdown the server side") + ;; need to delete only *my* server entry (future use) + (open-run-close db:del-var #f "SERVER") + (thread-sleep! 10) + (debug:print-info 0 "Max cached queries was " *max-cache-size*) + (debug:print-info 0 "Server shutdown complete. Exiting") + ;; (exit))) + )))))) (define (server:find-free-port-and-open host s port) (let ((s (if s s (make-socket 'rep))) (p (if (number? port) port 5555))) (handle-exceptions @@ -150,6 +153,25 @@ "") " &")) (sleep 5) (server:client-setup))))) +(define (server:launch) + (let* ((toppath (setup-for-run))) + (debug:print-info 0 "Starting the standalone server") + (if *toppath* + (let* ((th2 (make-thread (lambda () + (server:run (args:get-arg "-server"))))) + (th3 (make-thread (lambda () + (server:keep-running))))) + (thread-start! th3) + (thread-start! th2) + (thread-join! th3) + (set! *didsomething* #t)) + (debug:print 0 "ERROR: Failed to setup for megatest")))) +(define (server:client-launch) + (if (server:client-setup) + (debug:print-info 0 "connected as client") + (begin + (debug:print 0 "ERROR: Failed to connect as client") + (exit)))) Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -65,12 +65,12 @@ cd ..;make install rm -f fullrun/logging.db touch cleanprep fullprep : cleanprep - cd fullrun;$(MEGATEST) -server - & - sleep 5;cd fullrun;$(MEGATEST) -remove-runs :runname $(RUNNAME)% -target %/%/% -testpatt % -itempatt % + cd fullrun;$(MEGATEST) -server - -debug $(DEBUG) & + sleep 5;cd fullrun;$(MEGATEST) -remove-runs :runname $(RUNNAME)% -target %/%/% -testpatt %/% cd fullrun;$(BINPATH)/dboard -rows 15 & dashboard : cleanprep cd fullrun && $(BINPATH)/dashboard -rows 25 & Index: tests/tests.scm ================================================================== --- tests/tests.scm +++ tests/tests.scm @@ -112,11 +112,11 @@ (test "get all legal tests" (list "test1" "test2") (sort (get-all-legal-tests) string<=?)) (test "register-test, test info" "NOT_STARTED" (begin - (rdb:tests-register-test *db* 1 "nada" "") + (cdb:tests-register-test *remoterun* 1 "nada" "") ;; (rdb:flush-queue) (vector-ref (db:get-test-info *db* 1 "nada" "") 3))) (test #f "NOT_STARTED" (begin @@ -143,10 +143,11 @@ (define keys (db:get-keys *db*)) ;;====================================================================== ;; D B ;;====================================================================== + (test #f "FOO LIKE 'abc%def'" (db:patt->like "FOO" "abc%def")) (test #f (vector '("SYSTEM" "RELEASE" "id" "runname" "state" "status" "owner" "event_time") '()) (runs:get-runs-by-patt db keys "%")) (test #f "SYSTEM,RELEASE,id,runname,state,status,owner,event_time" (car (runs:get-std-run-fields keys '("id" "runname" "state" "status" "owner" "event_time")))) (test #f #t (runs:operate-on 'print "%" "%" "%")) @@ -254,18 +255,22 @@ ;; R E M O T E C A L L S ;;====================================================================== ;; start a server process (set! *verbosity* 10) -(define server-pid (process-run "../../bin/megatest" (list "-server" "-" "-debug" (conc *verbosity*)))) -(sleep 2) +;; (define server-pid (process-run "../../bin/megatest" (list "-server" "-" "-debug" (conc *verbosity*)))) +;; (sleep 2) + +(define th1 (make-thread server:launch)) +(thread-start! th1) + (define start-wait (current-seconds)) (server:client-setup) (print "Starting intensive cache and rpc test") (for-each (lambda (params) ;;; (rdb:tests-register-test #f 1 (conc "test" (random 20)) "") - (apply rdb:test-set-status-state test-id params) + (apply cdb:test-set-status-state *remoterun* test-id params) (rdb:pass-fail-counts test-id (random 100) (random 100)) (rdb:test-rollup-test_data-pass-fail test-id) (thread-sleep! 0.01)) ;; cache ordering granularity is at the second level. Should really be at the ms level '(("COMPLETED" "PASS" #f) ("NOT_STARTED" "FAIL" "Just testing")