Index: apimod.scm ================================================================== --- apimod.scm +++ apimod.scm @@ -204,10 +204,11 @@ ;; SERVERS ;; ((start-server) (apply server:kind-run params)) ((kill-server) (set! *server-run* #f)) ((get-server) (api:start-server dbstruct params)) + ((get-server-info) (apply db:get-server-info dbstruct params)) ((register-server) (apply db:register-server dbstruct params) );; dbstruct host port servkey pid ipaddr dbpath) ((deregister-server) (apply db:deregister-server dbstruct params) );; dbstruct host port servkey pid ipaddr dbpath) ((get-count-servers) (apply db:get-count-servers dbstruct params)) ;; TESTS Index: rmtmod.scm ================================================================== --- rmtmod.scm +++ rmtmod.scm @@ -412,10 +412,13 @@ (rmt:send-receive 'kill-server run-id (list run-id))) (define (rmt:start-server run-id) (rmt:send-receive 'start-server 0 (list run-id))) +(define (rmt:get-server-info apath dbname) + (rmt:send-receive 'get-server-info 0 (list 0 apath dbname))) + ;;====================================================================== ;; M I S C ;;====================================================================== (define (rmt:login run-id) @@ -1681,18 +1684,18 @@ (set! *server-info* (make-servdat host: ipaddrstr port: portnum))) (debug:print-info 0 *default-log-port* "rmt:try-start-server time=" (seconds->time-string (current-seconds)) " ipaddrsstr=" ipaddrstr " portnum=" portnum) - (if (is-port-in-use portnum) - (begin - (portlogger:open-run-close portlogger:set-failed portnum) - (debug:print 0 *default-log-port* "WARNING: failed to start on portnum: " portnum ", trying next port") - ;; (thread-sleep! 0.1) - (rmt:try-start-server ipaddrstr - (portlogger:open-run-close - portlogger:find-port))) +;;(if (is-port-in-use portnum) +;; (begin +;; (portlogger:open-run-close portlogger:set-failed portnum) +;; (debug:print 0 *default-log-port* "WARNING: failed to start on portnum: " portnum ", trying next port") +;; ;; (thread-sleep! 0.1) +;; (rmt:try-start-server ipaddrstr +;; (portlogger:open-run-close +;; portlogger:find-port))) (begin (if (not *server-info*) (set! *server-info* (make-servdat host: ipaddrstr port: portnum))) @@ -1719,11 +1722,11 @@ (rmt:try-start-server ipaddrstr (portlogger:open-run-close portlogger:find-port))) (begin (print "ERROR: Tried and tried but could not start the server, stopping at port "portnum)))) (nng-listen rep (conc "tcp://*:" portnum)) - rep))))) + rep)))) ;;) ;;====================================================================== ;; S E R V E R U T I L I T I E S ;;====================================================================== @@ -2198,13 +2201,21 @@ (let ((res (rmt:register-server *rmt:remote* *toppath* iface port server-key dbname))) (if res ;; we are the server (servdat-status-set! *server-info* 'have-interface-and-db) - (begin - (debug:print 0 *default-log-port* "We are not the server for "dbname", exiting.") - (exit))))) + (let* ((serv-info (rmt:get-server-info *toppath* dbname))) + (match serv-info + ((host port servkey pid ipaddr apath dbpath) + (if (not (server-ready? host port servkey)) + (begin + (debug:print-info 0 *default-log-port* "Server registered but not alive. Removing and trying again.") + (rmt:deregister-server host port servkey pid ipaddr apath dbpath) + (loop (+ count 1) bad-sync-count start-time)))) + (else + (debug:print 0 *default-log-port* "We are not the server for "dbname", exiting. Server info is: "serv-info) + (exit))))))) (debug:print 0 *default-log-port* "SERVER: running, db "dbname" opened, megatest version: " (common:get-full-version)) ;; start the watchdog Index: tests/tests.scm ================================================================== --- tests/tests.scm +++ tests/tests.scm @@ -15,11 +15,18 @@ ;; You should have received a copy of the GNU General Public License ;; along with Megatest. If not, see . ;; ;; strftime('%m/%d/%Y %H:%M:%S','now','localtime') -(import srfi-18 test) +(import srfi-18 + test + chicken.string + chicken.process-context + chicken.file + chicken.pretty-print + commonmod + ) (define test-work-dir (current-directory)) ;; given list of lists ;; ( ( msg expected param1 param2 ...)