Overview
Comment: | rundb, inmem and main structures written |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | inmem-per-run-db |
Files: | files | file ages | folders |
SHA1: |
b81b7645b999e0de5b339ba3a78d77c2 |
User & Date: | matt on 2013-11-24 20:16:33 |
Other Links: | branch diff | manifest | tags |
Context
2013-11-24
| ||
21:42 | Server now runs check-in: 51983eb150 user: matt tags: inmem-per-run-db | |
20:16 | rundb, inmem and main structures written check-in: b81b7645b9 user: matt tags: inmem-per-run-db | |
18:17 | Merged in string db branch check-in: 3eb9a93e77 user: matt tags: inmem-per-run-db | |
Changes
Modified configf.scm from [59f66d81cc] to [363b2b5fd7].
︙ | ︙ | |||
215 216 217 218 219 220 221 | (loop (configf:read-line inp res allow-system) curr-section-name #f #f))) (configf:key-val-pr ( x key unk1 val unk2 ) (let* ((alist (hash-table-ref/default res curr-section-name '())) (envar (and environ-patt (string-search (regexp environ-patt) curr-section-name))) (realval (if envar (config:eval-string-in-environment val) val))) (debug:print-info 6 "read-config env setting, envar: " envar " realval: " realval " val: " val " key: " key " curr-section-name: " curr-section-name) | | | | > | | | | 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | (loop (configf:read-line inp res allow-system) curr-section-name #f #f))) (configf:key-val-pr ( x key unk1 val unk2 ) (let* ((alist (hash-table-ref/default res curr-section-name '())) (envar (and environ-patt (string-search (regexp environ-patt) curr-section-name))) (realval (if envar (config:eval-string-in-environment val) val))) (debug:print-info 6 "read-config env setting, envar: " envar " realval: " realval " val: " val " key: " key " curr-section-name: " curr-section-name) (if envar (if (and (string? realval)(string? key)) (handle-exceptions exn (debug:print 0 "ERROR: bad value for setenv, key=" key ", value=" realval) (setenv key realval)) (debug:print 0 "ERROR: bad value for setenv, key=" key ", value=" realval))) (hash-table-set! res curr-section-name (config:assoc-safe-add alist key realval)) (loop (configf:read-line inp res allow-system) curr-section-name key #f))) (configf:key-no-val ( x key val) (let* ((alist (hash-table-ref/default res curr-section-name '()))) (hash-table-set! res curr-section-name (config:assoc-safe-add alist key #t)) (loop (configf:read-line inp res allow-system) curr-section-name key #f))) |
︙ | ︙ |
Modified db.scm from [80c8029823] to [7ad6d7a9bd].
︙ | ︙ | |||
42 43 44 45 46 47 48 49 | ;; type: meta-info, step (define *incoming-writes* '()) (define *completed-writes* (make-hash-table)) (define *incoming-last-time* (current-seconds)) (define *incoming-mutex* (make-mutex)) (define *completed-mutex* (make-mutex)) (define (db:get-db dbstruct run-id) | > > > > > > < < < < < < | | | < < | 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | ;; type: meta-info, step (define *incoming-writes* '()) (define *completed-writes* (make-hash-table)) (define *incoming-last-time* (current-seconds)) (define *incoming-mutex* (make-mutex)) (define *completed-mutex* (make-mutex)) ;; Get/open a database ;; if run-id => get run specific db ;; if #f => get main db ;; if db already open - return inmem ;; if db not open, open inmem, rundb and sync then return inmem ;; (define (db:get-db dbstruct run-id) (if run-id (db:open-rundb dbstruct run-id) (db:open-main dbstruct))) (define (db:set-sync db) (let* ((syncval (config-lookup *configdat* "setup" "synchronous")) (val (cond ;; 0 | OFF | 1 | NORMAL | 2 | FULL; ((not syncval) #f) ((string->number syncval) (let ((val (string->number syncval))) (if (member val '(0 1 2)) val #f))) ((string-match (regexp "yes" #t) syncval) 1) ((string-match (regexp "no" #t) syncval) 0) ((string-match (regexp "(off|normal|full)" #t) syncval) syncval) (else (debug:print 0 "ERROR: synchronous must be 0,1,2,OFF,NORMAL or FULL, you provided: " syncval) #f)))) (if val (begin (debug:print-info 9 "db:set-sync, setting pragma synchronous to " val) (sqlite3:execute db (conc "PRAGMA synchronous = '" val "';")))))) ;;====================================================================== ;; K E E P F I L E D B I N dbstruct ;;====================================================================== (define (db:get-filedb dbstruct) (let ((db (vector-ref dbstruct 2))) |
︙ | ︙ | |||
97 98 99 100 101 102 103 | ;; Use to get a path. To get an arbitrary string see next define ;; (define (db:get-path dbstruct id) (let ((fdb (db:get-filedb dbstruct))) (filedb:get-path db id))) | < < < < < < < < | < | > > > | > | | > > > > > | < > > > > | | | | > | < < < < | | | | | | | | | | < < | > | < < > | > | < | < < > | | < < < < < < < | < < | | 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | ;; Use to get a path. To get an arbitrary string see next define ;; (define (db:get-path dbstruct id) (let ((fdb (db:get-filedb dbstruct))) (filedb:get-path db id))) ;; This routine creates the db. It is only called if the db is not already opened ;; (define (db:open-rundb dbstruct run-id) ;; (conc *toppath* "/megatest.db") (car *configinfo*))) (let ((rdb (dbr:dbstruct-get-runrec dbstruct run-id 'inmem))) (if rdb rdb (let* ((toppath (dbr:dbstruct-get-path dbstruct)) (dbpath (conc toppath "/db/" run-id ".db")) (dbexists (file-exists? dbpath)) (inmem (open-inmem-db)) (db (sqlite3:open-database dbpath)) (write-access (file-write-access? dbpath)) (handler (make-busy-timeout 136000))) (if (and dbexists (not write-access)) (set! *db-write-access* #f)) ;; only unset so other db's also can use this control (if write-access (begin (sqlite3:set-busy-handler! db handler) (sqlite3:execute db "PRAGMA synchronous = 0;"))) (if (not dbexists)(db:initialize-run-id-db db run-id)) (dbr:dbstruct-set-runvec! dbstruct run-id 'rundb db) (dbr:dbstruct-set-runvec! dbstruct run-id 'inmem inmem) inmem)))) ;; This routine creates the db. It is only called if the db is not already opened ;; (define (db:open-main dbstruct) ;; (conc *toppath* "/megatest.db") (car *configinfo*))) (let ((mdb (dbr:dbstruct-get-main dbstruct))) (if mdb mdb (let* ((toppath (dbr:dbstruct-get-path dbstruct)) (dbpath (let ((dbdir (conc *toppath* "/db"))) ;; use this opportunity to create our db dir (if (not (directory-exists? dbdir)) (create-direcory dbdir)) (conc *toppath* "/db/main.db"))) (dbexists (file-exists? dbpath)) (db (sqlite3:open-database dbpath)) ;; (never-give-up-open-db dbpath)) (write-access (file-write-access? dbpath)) (handler (make-busy-timeout 136000))) (if (and dbexists (not write-access)) (set! *db-write-access* #f)) (if write-access (begin (sqlite3:set-busy-handler! db handler) (sqlite3:execute db "PRAGMA synchronous = 0;"))) (if (not dbexists) (db:initialize-megatest-db db)) (dbr:dbstruct-set-main! dbstruct db) db)))) ;; close all opened run-id dbs (define (db:close-all-db) (for-each (lambda (db) (finalize! db)) (hash-table-values (vector-ref *open-dbs* 1))) (finalize! (vector-ref *open-dbs* 0))) (define (open-inmem-db) (let* ((db (sqlite3:open-database ":memory:")) (handler (make-busy-timeout 3600))) (db:initialize db) (sqlite3:set-busy-handler! db handler) (set! sdb:qry (make-sdb:qry)) ;; we open the normalization helpers here (set! *fdb* (filedb:open-db (conc *toppath* "/db/paths.db"))) db)) ;; (define (db:sync-table tblname fields fromdb todb) |
︙ | ︙ | |||
310 311 312 313 314 315 316 | (lambda (dat) (let ((tblname (car dat)) (count (cdr dat))) (if (> count 0) (debug:print 0 (format #f " ~10a ~5a" tblname count))))) (sort (hash-table->alist numrecs)(lambda (a b)(> (cdr a)(cdr b)))))))) | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | (lambda (dat) (let ((tblname (car dat)) (count (cdr dat))) (if (> count 0) (debug:print 0 (format #f " ~10a ~5a" tblname count))))) (sort (hash-table->alist numrecs)(lambda (a b)(> (cdr a)(cdr b)))))))) (define (db:sync-back) (db:sync-tables (db:tbls *inmemdb*) *inmemdb* *db*)) ;; (db:sync-to *inmemdb* *db*)) ;; keeping it around for debugging purposes only (define (open-run-close-no-exception-handling proc idb . params) (debug:print-info 11 "open-run-close-no-exception-handling START given a db=" (if idb "yes " "no ") ", params=" params) (if (or *db-write-access* |
︙ | ︙ | |||
1053 1054 1055 1056 1057 1058 1059 | run-id) (debug:print-info 11 "db:get-run-info run-id: " run-id " header: " header " keystr: " keystr) (let ((finalres (vector header res))) ;; (hash-table-set! *run-info-cache* run-id finalres) finalres))) (define (db:set-comment-for-run dbstruct run-id comment) | | | 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 | run-id) (debug:print-info 11 "db:get-run-info run-id: " run-id " header: " header " keystr: " keystr) (let ((finalres (vector header res))) ;; (hash-table-set! *run-info-cache* run-id finalres) finalres))) (define (db:set-comment-for-run dbstruct run-id comment) (sqlite3:execute (db:get-db dbstruct #f) "UPDATE runs SET comment=? WHERE id=?;" (sdb:qry 'getid comment) run-id)) ;; does not (obviously!) removed dependent data. But why not!!? (define (db:delete-run dbstruct run-id) ;; First set any related tests to DELETED (let ((db (db:get-db dbstruct run-id))) (sqlite3:execute db "UPDATE tests SET state='DELETED',comment='';") (sqlite3:execute db "DELETE FROM test_steps;") |
︙ | ︙ |
Modified db_records.scm from [f39e373ffe] to [8100f13571].
1 2 3 4 5 6 7 | (define (make-db:test)(make-vector 20)) (define-inline (db:test-get-id vec) (vector-ref vec 0)) (define-inline (db:test-get-run_id vec) (vector-ref vec 1)) (define-inline (db:test-get-testname vec) (vector-ref vec 2)) (define-inline (db:test-get-state vec) (vector-ref vec 3)) (define-inline (db:test-get-status vec) (vector-ref vec 4)) (define-inline (db:test-get-event_time vec) (vector-ref vec 5)) | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | ;;====================================================================== ;; dbstruct ;;====================================================================== ;; ;; -path-|-megatest.db ;; |-db-|-main.db ;; |-monitor.db ;; |-sdb.db ;; |-fdb.db ;; |-1.db ;; |-<N>.db (define (make-dbr:dbstruct #!key (path #f)) (make-vector #f ;; the main db (contains runs, test_meta etc.) NOT CACHED IN MEM (make-hash-table) ;; run-id => [ rundb inmemdb last-mod last-read last-sync ] #f ;; the global string db (use for state, status etc.) path)) ;; path to database files/megatest area ;; get and set main db (define-inline (dbr:dbstruct-get-main vec) (vector-ref vec 0)) (define-inline (dbr:dbstruct-set-main! vec db)(vector-set! vec 0 db)) ;; get a rundb vector (define (dbr:dbstruct-get-rundb-rec vec run-id) (let* ((dbhash (vector-ref vec 1)) (runvec (hash-table-ref/default dbhash run-id))) (if runvec runvec (begin (hash-table-set! dbhash run-id (vector #f #f -1 -1 -1)) (dbr:dbstruct-get-rundb-rec vec run-id))))) ;; [ rundb inmemdb last-mod last-read last-sync ] (define-inline (dbr:dbstruct-field-name->num field-name) (case field-name ((rundb) 0) ;; the on-disk db ((inmem) 1) ;; the in-memory db ((mtime) 2) ;; last modification time ((rtime) 3) ;; last read time ((stime) 4) ;; last sync time (else -1))) ;; get/set rundb fields (define (dbr:dbstruct-get-runrec vec run-id field-name) (let ((runvec (dbr:dbstruct-get-rundb-rec vec run-id))) (vector-ref runvec (dbr:dbstruct-field-name->num field-name)))) (define (dbr:dbstruct-set-runvec! vec run-id field-name val) (let ((runvec (dbr:dbstruct-get-rundb-rec vec run-id))) (vector-set! runvec (dbr:dbstruct-field-name->num field-name) rundb))) ;; get/set inmemdb (define (dbr:dbstruct-get-inmemdb vec run-id) (let ((runvec (dbr:dbstruct-get-rundb-rec vec run-id))) (vector-ref runvec 1))) (define (dbr:dbstruct-set-inmemdb! vec run-id inmemdb) (let ((runvec (dbr:dbstruct-get-rundb-rec vec run-id))) (vector-set! runvec 1 inmemdb))) ;; the string db (define-inline (dbr:dbstruct-get-strdb vec) (vector-ref vec 2)) (define-inline (dbr:dbstruct-set-strdb! vec db)(vector-set! vec 2 db)) ;; path (define-inline (dbr:dbstruct-set-path! vec path)(vector-set! vec 3)) (define-inline (dbr:dbstruct-get-path vec) (vector-ref vec 3)) (define (make-db:test)(make-vector 20)) (define-inline (db:test-get-id vec) (vector-ref vec 0)) (define-inline (db:test-get-run_id vec) (vector-ref vec 1)) (define-inline (db:test-get-testname vec) (vector-ref vec 2)) (define-inline (db:test-get-state vec) (vector-ref vec 3)) (define-inline (db:test-get-status vec) (vector-ref vec 4)) (define-inline (db:test-get-event_time vec) (vector-ref vec 5)) |
︙ | ︙ |
Modified tests/rununittest.sh from [45ac8d74ef] to [fbc9c72134].
1 2 3 4 5 6 7 8 9 10 11 12 | #!/bin/bash # Usage: rununittest.sh testname debuglevel # # Clean setup # rm -f simplerun/megatest.db simplerun/monitor.db simplerun/db/monitor.db rm -rf simplelinks/ simpleruns/ mkdir -p simplelinks simpleruns (cd simplerun;cp ../../*_records.scm .;perl -pi.bak -e 's/define-inline/define/' *_records.scm) | > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #!/bin/bash # Usage: rununittest.sh testname debuglevel # # Ensure all is made (cd ..;make && make install) # Clean setup # rm -f simplerun/megatest.db simplerun/monitor.db simplerun/db/monitor.db rm -rf simplelinks/ simpleruns/ mkdir -p simplelinks simpleruns (cd simplerun;cp ../../*_records.scm .;perl -pi.bak -e 's/define-inline/define/' *_records.scm) |
︙ | ︙ |
Added tests/unittests/basicserver.scm version [b1c30eb42e].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | ;;====================================================================== ;; S E R V E R ;;====================================================================== ;; Run like this: ;; ;; (cd ..;make && make install) && ./rununittest.sh server 1;(cd simplerun;megatest -stop-server 0) (set! *transport-type* 'http) (test "setup for run" #t (begin (setup-for-run) (string? (getenv "MT_RUN_AREA_HOME")))) (test "server-register, get-best-server" #t (let ((res #f)) (open-run-close tasks:server-register tasks:open-db 1 "bob" 1234 100 'live 'http) (set! res (open-run-close tasks:get-best-server tasks:open-db)) (number? (vector-ref res 3)))) (test "de-register server" #f (let ((res #f)) (open-run-close tasks:server-deregister tasks:open-db "bob" port: 1234) (vector? (open-run-close tasks:get-best-server tasks:open-db)))) (define server-pid #f) ;; Not sure how the following should work, replacing it with system of megatest -server ;; (test "launch server" #t (let ((pid (process-fork (lambda () ;; ;; (daemon:ize) ;; (server:launch 'http))))) ;; (set! server-pid pid) ;; (number? pid))) (system "../../bin/megatest -server - -debug 22 > server.log 2> server.log &") (let loop ((n 10)) (thread-sleep! 1) ;; need to wait for server to start. (let ((res (open-run-close tasks:get-best-server tasks:open-db))) (print "tasks:get-best-server returned " res) (if (and (not res) (> n 0)) (loop (- n 1))))) (test "get-best-server" #t (begin (client:launch) (let ((dat (open-run-close tasks:get-best-server tasks:open-db))) (vector? dat)))) (define *keys* (keys:config-get-fields *configdat*)) (define *keyvals* (keys:target->keyval *keys* "a/b/c")) (test #f #t (string? (car *runremote*))) (test #f '(#t "successful login") (rmt:login)) ;; *runremote* *toppath* *my-client-signature*))) (test #f #f (rmt:get-test-info-by-id 99)) ;; get non-existant test ;; RUNS (test #f 1 (rmt:register-run *keyvals* "firstrun" "new" "n/a" (current-user-name))) (test "get run info" "firstrun" (let ((rinfo (rmt:get-run-info 1))) (vector-ref (vector-ref rinfo 1) 3))) (test "get runname from id" "firstrun" (rmt:get-run-name-from-id 1)) ;; TESTS (test "get tests (no data)" '() (rmt:get-tests-for-run 1 "%" '() '() #f #f #f #f #f #f)) (test "register test" #t (rmt:general-call 'register-test 1 "test1" "")) (test "get tests (some data)" 1 (length (rmt:get-tests-for-run 1 "%" '() '() #f #f #f #f #f #f))) (test "get test id" 1 (rmt:get-test-id 1 "test1" "")) (test "sync back" #t (> (rmt:sync-inmem->db) 0)) (test "get test id from main" 1 (db:get-test-id *db* 1 "test1" "")) (test "get keys" #t (list? (rmt:get-keys))) (test "set comment" #t (begin (rmt:general-call 'set-test-comment "this is a comment" 1) #t)) (test "get comment" "this is a comment" (let ((trec (rmt:get-test-info-by-id 1))) (db:test-get-comment trec))) ;; MORE RUNS (test "get runs" #t (let* ((runs (rmt:get-runs "%" #f #f '())) (header (vector-ref runs 0)) (data (vector-ref runs 1))) (and (list? header) (list? data) (vector? (car data))))) (test "get local testinfo" "test1" (vector-ref (db:get-testinfo-state-status *db* 1) 2)) (test "get testinfo" "test1" (vector-ref (rmt:get-testinfo-state-status 1) 2)) ;;====================================================================== ;; D B ;;====================================================================== (test "pass fail counts" #t (rmt:general-call 'pass-fail-counts 10 9 1)) (test "get pass fail counts" 19 (let ((dat (rmt:get-test-info-by-id 1))) (+ (db:test-get-pass_count dat) (db:test-get-fail_count dat)))) (define testregistry (make-hash-table)) (for-each (lambda (tname) (for-each (lambda (itempath) (let ((tkey (conc tname "/" itempath)) (rpass (random 10)) (rfail (random 10))) (hash-table-set! testregistry tkey (list tname itempath)) (rmt:general-call 'register-test 1 tname itempath) (let* ((tid (rmt:get-test-id 1 tname itempath)) (tdat (rmt:get-test-info-by-id tid))) (rmt:general-call 'pass-fail-counts rpass rfail (db:test-get-id tdat)) (let* ((resdat (rmt:get-test-info-by-id tid))) (test "set/get pass fail counts" (list rpass rfail) (list (db:test-get-pass_count resdat) (db:test-get-fail_count resdat))))))) (list "" "a" "b" "c" "d" "e" "f" "g" "h" "i" "j"))) (list "test1" "test2" "test3" "test4" "test5")) (test #f '(#t "exit process started") (rmt:kill-server)) ;; *toppath* *my-client-signature* #f))) |