1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
|
;;======================================================================
;; QUEUE UP META, TEST STATUS AND STEPS
;;======================================================================
(define (db:updater)
(let loop ((start-time (current-time)))
(thread-sleep! 0.5) ;; move save time around to minimize regular collisions?
(db:write-cached-data)
(loop start-time)))
(define (cdb:test-set-status-state test-id status state #!key (msg #f))
(debug:print 4 "INFO: Adding status/state to queue: " status "/" state)
(mutex-lock! *incoming-mutex*)
(if msg
(set! *incoming-data* (cons (vector 'state-status-msg
(current-seconds)
(list state status msg test-id))
*incoming-data*))
(set! *incoming-data* (cons (vector 'state-status
(current-seconds)
(list state status test-id)) ;; run-id test-name item-path minutes cpuload diskfree tmpfree)
*incoming-data*)))
(mutex-unlock! *incoming-mutex*)
(if *cache-on*
(debug:print 6 "INFO: *cache-on* is " *cache-on* ", skipping cache write")
(db:write-cached-data)))
;; (define (remote:test-update-meta-info db test-id minutes cpuload diskfree tmpfree)
;; (mutex-lock! *incoming-mutex*)
;; (set! *incoming-data* (cons (vector 'meta-info
;; (current-seconds)
;; (list cpuload
;; diskfree
;; minutes
;; test-id)) ;; run-id test-name item-path minutes cpuload diskfree tmpfree)
;; *incoming-data*))
;; (mutex-unlock! *incoming-mutex*)
;; (if *cache-on*
;; (debug:print 6 "INFO: *cache-on* is " *cache-on* ", skipping cache write as part of test-update-meta-info")
;; (db:write-cached-data db)))
;; 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
;;
(define (db:write-cached-data)
(open-run-close
(lambda (db . params)
(let ((meta-stmt (sqlite3:prepare db "UPDATE tests SET cpuload=?,diskfree=?,run_duration=?,state='RUNNING' WHERE id=? AND state NOT IN ('COMPLETED','KILLREQ','KILLED');"))
(state-status-stmt (sqlite3:prepare db "UPDATE tests SET state=?,status=? WHERE id=?;"))
(state-status-msg-stmt (sqlite3:prepare db "UPDATE tests SET state=?,status=?,comment=? WHERE id=?;"))
(step-stmt (sqlite3:prepare db "INSERT OR REPLACE into test_steps (test_id,stepname,state,status,event_time,comment,logfile) VALUES(?,?,?,?,?,?,?);")) ;; strftime('%s','now')#f)
(data #f))
(mutex-lock! *incoming-mutex*)
(set! data (sort *incoming-data* (lambda (a b)(< (vector-ref a 1)(vector-ref b 1)))))
(set! *incoming-data* '())
(mutex-unlock! *incoming-mutex*)
(if (> (length data) 0)
(debug:print 4 "INFO: Writing cached data " data))
(sqlite3:with-transaction
db
(lambda ()
(for-each (lambda (entry)
(debug:print 4 "INFO: flushing " entry " to db")
(case (vector-ref entry 0)
((meta-info)
(apply sqlite3:execute meta-stmt (vector-ref entry 2)))
((step-status)
(apply sqlite3:execute step-stmt (vector-ref entry 2)))
((state-status)
(apply sqlite3:execute state-status-stmt (vector-ref entry 2)))
((state-status-msg)
(apply sqlite3:execute state-status-msg-stmt (vector-ref entry 2)))
(else
(debug:print 0 "ERROR: Queued entry not recognised " entry))))
data)))
(sqlite3:finalize! meta-stmt) ;; sqlite is the bottleneck, clear the statements asap?
(sqlite3:finalize! step-stmt)
(sqlite3:finalize! state-status-stmt)
(sqlite3:finalize! state-status-msg-stmt)
))
#f))
;; (define (db:write-cached-data db)
;; (let ((meta-stmt (sqlite3:prepare db "UPDATE tests SET cpuload=?,diskfree=?,run_duration=?,state='RUNNING' WHERE id=? AND state NOT IN ('COMPLETED','KILLREQ','KILLED');"))
;; (step-stmt (sqlite3:prepare db "INSERT OR REPLACE into test_steps (test_id,stepname,state,status,event_time,comment,logfile) VALUES(?,?,?,?,?,?,?);")) ;; strftime('%s','now')#f)
;; (data (sort *incoming-data* (lambda (a b)(< (vector-ref a 1)(vector-ref b 1))))))
;; (if (> (length data) 0)
;; (debug:print 4 "Writing cached data " data))
;; (mutex-lock! *incoming-mutex*)
;; (sqlite3:with-transaction
;; db
;; (lambda ()
;; (for-each (lambda (entry)
;; (case (vector-ref entry 0)
;; ((meta-info)
;; (apply sqlite3:execute meta-stmt (vector-ref entry 2)))
;; ((step-status)
;; (apply sqlite3:execute step-stmt (vector-ref entry 2)))
;; (else
;; (debug:print 0 "ERROR: Queued entry not recognised " entry))))
;; data)))
;; (sqlite3:finalize! meta-stmt) ;; sqlite is the bottleneck, clear the statements asap?
;; (sqlite3:finalize! step-stmt)
;; (set! *incoming-data* '())
;; (mutex-unlock! *incoming-mutex*)))
(define (db:roll-up-pass-fail-counts db run-id test-name item-path status)
(if (and (not (equal? item-path ""))
(or (equal? status "PASS")
(equal? status "WARN")
(equal? status "FAIL")
(equal? status "WAIVED")
(equal? status "RUNNING")))
|
|
|
>
|
|
|
|
<
<
<
|
|
|
|
|
<
|
|
>
>
>
>
>
>
>
>
|
|
<
<
<
<
|
|
|
|
>
>
|
|
<
|
|
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
|
;;======================================================================
;; QUEUE UP META, TEST STATUS AND STEPS
;;======================================================================
(define (db:updater)
(let loop ((start-time (current-time)))
(thread-sleep! 15) ;; move save time around to minimize regular collisions?
(db:write-cached-data)
(loop start-time)))
(define (cdb:test-set-status-state test-id status state #!key (msg #f))
(debug:print 4 "INFO: Adding status/state to queue: " status "/" state)
(mutex-lock! *incoming-mutex*)
(if msg
(set! *incoming-data* (cons (vector 'state-status-msg
(current-seconds)
(list state status msg test-id))
*incoming-data*))
(set! *incoming-data* (cons (vector 'state-status
(current-seconds)
(list state status test-id)) ;; run-id test-name item-path minutes cpuload diskfree tmpfree)
*incoming-data*)))
(mutex-unlock! *incoming-mutex*)
(if *cache-on*
(debug:print 6 "INFO: *cache-on* is " *cache-on* ", skipping cache write")
(db:write-cached-data)))
(define (cdb:test-rollup-iterated-pass-fail test-id)
(debug:print 4 "INFO: Adding " test-id " for iterated rollup to the queue")
(mutex-lock! *incoming-mutex*)
(set! *incoming-data* (cons (vector 'iterated-p/f-rollup
(current-seconds)
(list test-id test-id test-id test-id))
*incoming-data*))
(mutex-unlock! *incoming-mutex*)
(if *cache-on*
(debug:print 6 "INFO: *cache-on* is " *cache-on* ", skipping cache write")
(db:write-cached-data)))
;; 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
;;
(define (db:write-cached-data)
(open-run-close
(lambda (db . params)
(let ((state-status-stmt (sqlite3:prepare db "UPDATE tests SET state=?,status=? WHERE id=?;"))
(state-status-msg-stmt (sqlite3:prepare db "UPDATE tests SET state=?,status=?,comment=? WHERE id=?;"))
(iterated-rollup-stmt (sqlite3:prepare db "UPDATE tests
SET status=CASE WHEN (SELECT fail_count FROM tests WHERE id=?) > 0
THEN 'FAIL'
WHEN (SELECT pass_count FROM tests WHERE id=?) > 0 AND
(SELECT status FROM tests WHERE id=?) NOT IN ('WARN','FAIL')
THEN 'PASS'
ELSE status
END WHERE id=?;"))
(data #f))
(mutex-lock! *incoming-mutex*)
(set! data (sort *incoming-data* (lambda (a b)(< (vector-ref a 1)(vector-ref b 1)))))
(set! *incoming-data* '())
(mutex-unlock! *incoming-mutex*)
(if (> (length data) 0)
(debug:print 4 "INFO: Writing cached data " data))
(sqlite3:with-transaction
db
(lambda ()
(for-each (lambda (entry)
(let ((params (vector-ref entry 2)))
(debug:print 4 "INFO: flushing " entry " to db")
(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))
((iterated-p/f-rollup)
(apply sqlite3:execute iterated-rollup-stmt params))
(else
(debug:print 0 "ERROR: Queued entry not recognised " entry)))))
data)))
(sqlite3:finalize! state-status-stmt)
(sqlite3:finalize! state-status-msg-stmt)
(sqlite3:finalize! iterated-rollup-stmt)
))
#f))
(define (db:roll-up-pass-fail-counts db run-id test-name item-path status)
(if (and (not (equal? item-path ""))
(or (equal? status "PASS")
(equal? status "WARN")
(equal? status "FAIL")
(equal? status "WAIVED")
(equal? status "RUNNING")))
|
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
|
(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
(sqlite3:execute db "UPDATE tests SET fail_count=?,pass_count=? WHERE id=?;" fail-count pass-count test-id)
(thread-sleep! 0.1) ;; play nice with other tests
;; if the test is not FAIL then set status based on the fail and pass counts.
(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'
WHEN (SELECT pass_count FROM tests WHERE id=?) > 0 AND
(SELECT status FROM tests WHERE id=?) NOT IN ('WARN','FAIL')
THEN 'PASS'
ELSE status
END WHERE id=?;"
test-id test-id test-id test-id)))))
(define (db:get-prev-tol-for-test db test-id category variable)
;; Finish me?
(values #f #f #f))
;;======================================================================
;; S T E P S
|
|
|
>
|
|
|
|
|
|
|
|
|
|
|
>
|
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
|
(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
(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 one second later than the set
;; if the test is not FAIL then set status based on the fail and pass counts.
(cdb:test-rollup-iterated-pass-fail 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'
;; WHEN (SELECT pass_count FROM tests WHERE id=?) > 0 AND
;; (SELECT status FROM tests WHERE id=?) NOT IN ('WARN','FAIL')
;; THEN 'PASS'
;; ELSE status
;; END WHERE id=?;"
;; test-id test-id test-id test-id)
))))
(define (db:get-prev-tol-for-test db test-id category variable)
;; Finish me?
(values #f #f #f))
;;======================================================================
;; S T E P S
|