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
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
171
172
173
|
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
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
+
+
+
-
-
-
+
+
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
-
+
-
-
-
+
-
-
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
+
-
-
-
+
-
-
+
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
;; You should have received a copy of the GNU General Public License
;; along with Megatest. If not, see <http://www.gnu.org/licenses/>.
;; Run like this:
;;
;; ./rununittest.sh server 1;(cd simplerun;megatest -stop-server 0)
(import rmtmod trace http-transportmod http-client apimod dbmod)
(trace-call-sites #t)
(trace
(delete-file* "logs/1.log")
(define run-id 1)
;; db:get-dbdat
;; rmt:find-main-server
rmt:send-receive-real
sexpr->string
)
(test "setup for run" #t (begin (launch:setup)
(string? (getenv "MT_RUN_AREA_HOME"))))
(test #f #t (and (server:kind-run *toppath*) #t))
(test #f #t (rmt:remote? (let ((r (make-rmt:remote)))
(set! *rmt:remote* r)
r)))
(test #f #f (rmt:get-connection *rmt:remote* *toppath* ".db/main.db"))
(test #f #f (rmt:find-main-server *toppath* ".db/main.db"))
(test #f #t (rmt:open-main-connection *rmt:remote* *toppath*))
(pp (hash-table->alist (rmt:remote-conns *rmt:remote*)))
(test #f #t (rmt:conn? (rmt:get-connection *rmt:remote* *toppath* ".db/main.db")))
(define *main* (rmt:get-connection *rmt:remote* *toppath* ".db/main.db"))
(define user (current-user-name))
(define runname "mytestrun")
(define keys (rmt:get-keys))
(define runinfo #f)
(for-each (lambda (tdat)
(define keyvals '(("SYSTEM" "abc")("RELEASE" "def")))
(define header (list "SYSTEM" "RELEASE" "id" "runname" "state" "status" "owner" "event_time"))
;; Setup
(test #f tdat (loop-test (rmt:conn-ipaddr *main*)
(rmt:conn-port *main*) tdat)))
(list 'a
'(a "b" 123 1.23 )))
(test #f #f (rmt:send-receive 'ping #f 'hello))
(trace
rmt:send-receive
with-input-from-request
rmt:get-connection
with-input-from-request
)
;;
;; (test #f #f (not (client:setup run-id)))
;; (test #f #f (not (hash-table-ref/default *runremote* run-id #f)))
(define *db* (db:setup #f))
(test #f 'server-started (api:execute-requests *db* 'get-server (list *toppath* ".db/1.db")))
(test #f #f (rmt:general-open-connection *rmt:remote* *toppath* ".db/1.db"))
;; Login
;; (delete-file* "logs/1.log")
;;
(test #f'(#t "successful login")
(rmt:login run-id))
;; (define run-id 1)
;; Keys
;;
;; (test "setup for run" #t (begin (launch:setup)
;; (string? (getenv "MT_RUN_AREA_HOME"))))
;;
(test #f '("SYSTEM" "RELEASE") (rmt:get-keys))
;; No data in db
;;
(test #f '() (rmt:get-all-run-ids))
(test #f #f (rmt:get-run-name-from-id run-id))
(test #f
;; (test #f #t (and (server:kind-run *toppath*) #t))
;;
;;
;; (define user (current-user-name))
;; (define runname "mytestrun")
;; (define keys (rmt:get-keys))
;; (define runinfo #f)
(vector
header
;; (define keyvals '(("SYSTEM" "abc")("RELEASE" "def")))
(vector #f #f #f #f))
(rmt:get-run-info run-id))
;; (define header (list "SYSTEM" "RELEASE" "id" "runname" "state" "status" "owner" "event_time"))
;; Insert data into db
;;
;;
(test #f 1 (rmt:register-run keyvals runname "new" "n/a" user))
;; (test #f #f (rmt:get-runs-by-patt keys runname))
(test #f #t (rmt:general-call 'register-test run-id run-id "test-one" ""))
(define test-one-id #f)
(test #f 1 (let ((test-id (rmt:get-test-id run-id "test-one" "")))
;; ;; Setup
;; ;;
;; ;; (test #f #f (not (client:setup run-id)))
;; ;; (test #f #f (not (hash-table-ref/default *runremote* run-id #f)))
;;
;; ;; Login
;; ;;
;; (test #f'(#t "successful login")
(set! test-one-id test-id)
test-id))
(define test-one-rec #f)
(test #f "test-one" (let ((test-rec (rmt:get-test-info-by-id run-id test-one-id)))
;; (rmt:login run-id))
;;
;; ;; Keys
;; ;;
(set! test-one-rec test-rec)
(vector-ref test-rec 2)))
;; With data in db
;;
;; (test #f '("SYSTEM" "RELEASE") (rmt:get-keys))
;;
;; ;; No data in db
;; ;;
(print "Using runame=" runname)
(test #f '(1) (rmt:get-all-run-ids))
(test #f runname (rmt:get-run-name-from-id run-id))
(test #f
runname
(let ((run-info (rmt:get-run-info run-id)))
(db:get-value-by-header (db:get-rows run-info)
(db:get-header run-info)
;; (test #f '() (rmt:get-all-run-ids))
;; (test #f #f (rmt:get-run-name-from-id run-id))
;; (test #f
;; (vector
;; header
;; (vector #f #f #f #f))
;; (rmt:get-run-info run-id))
;;
;; ;; Insert data into db
;; ;;
;; (test #f 1 (rmt:register-run keyvals runname "new" "n/a" user))
;; ;; (test #f #f (rmt:get-runs-by-patt keys runname))
;; (test #f #t (rmt:general-call 'register-test run-id run-id "test-one" ""))
;; (define test-one-id #f)
;; (test #f 1 (let ((test-id (rmt:get-test-id run-id "test-one" "")))
"runname")))
;; test killing server
;;
;; (set! test-one-id test-id)
;; test-id))
;; (define test-one-rec #f)
;; (test #f "test-one" (let ((test-rec (rmt:get-test-info-by-id run-id test-one-id)))
;; (set! test-one-rec test-rec)
;; (vector-ref test-rec 2)))
;;
;; ;; With data in db
;; ;;
;; (print "Using runame=" runname)
;; (test #f '(1) (rmt:get-all-run-ids))
;; (test #f runname (rmt:get-run-name-from-id run-id))
;; (test #f
;; runname
;; (let ((run-info (rmt:get-run-info run-id)))
;; (db:get-value-by-header (db:get-rows run-info)
;; (db:get-header run-info)
;; "runname")))
;;
;; ;; test killing server
;; ;;
;; (for-each
;; (lambda (run-id)
;; (test #f #t (and (tasks:kill-server-run-id run-id) #t))
;; (test #f #f (tasks:server-running-or-starting? (db:delay-if-busy (tasks:open-db)) run-id)))
;; (list 0 1))
;;
;; ;; Tests to assess reading/writing while servers are starting/stopping
;; ;; NO LONGER APPLICABLE
;;
;; ;; Server tests go here
;; (define (server-tests-dont-run-right-now)
;; (for-each
;; (lambda (run-id)
;; (test #f #f (tasks:server-running-or-starting? (db:delay-if-busy (tasks:open-db)) run-id))
;; (server:kind-run run-id)
;; (test "did server start within 20 seconds?"
;; #t
;; (let loop ((remtries 20)
;; (running (tasks:server-running-or-starting? (db:delay-if-busy
;; (tasks:open-db))
;; run-id)))
;; (if running
;; (> running 0)
;; (if (> remtries 0)
;; (begin
;; (thread-sleep! 1)
;; (loop (- remtries 1)
;; (tasks:server-running-or-starting? (db:delay-if-busy
;; (tasks:open-db))
;; run-id)))))))
;;
(for-each
(lambda (run-id)
(test #f #t (and (tasks:kill-server-run-id run-id) #t))
(test #f #f (tasks:server-running-or-starting? (db:delay-if-busy (tasks:open-db)) run-id)))
(list 0 1))
;; Tests to assess reading/writing while servers are starting/stopping
;; NO LONGER APPLICABLE
;; Server tests go here
(define (server-tests-dont-run-right-now)
(for-each
(lambda (run-id)
(test #f #f (tasks:server-running-or-starting? (db:delay-if-busy (tasks:open-db)) run-id))
(server:kind-run run-id)
(test "did server start within 20 seconds?"
#t
(let loop ((remtries 20)
(running (tasks:server-running-or-starting? (db:delay-if-busy
(tasks:open-db))
run-id)))
(if running
(> running 0)
(if (> remtries 0)
(begin
(thread-sleep! 1)
(loop (- remtries 1)
(tasks:server-running-or-starting? (db:delay-if-busy
(tasks:open-db))
run-id)))))))
(test "did server become available" #t
(let loop ((remtries 10)
(res (tasks:get-server (db:delay-if-busy (tasks:open-db)) run-id)))
(if res
(vector? res)
(begin
;; (test "did server become available" #t
;; (let loop ((remtries 10)
;; (res (tasks:get-server (db:delay-if-busy (tasks:open-db)) run-id)))
;; (if res
;; (vector? res)
;; (begin
;; (if (> remtries 0)
;; (begin
(if (> remtries 0)
(begin
(thread-sleep! 1.1)
(loop (- remtries 1)(tasks:get-server (db:delay-if-busy (tasks:open-db)) run-id)))
res)))))
;; (thread-sleep! 1.1)
;; (loop (- remtries 1)(tasks:get-server (db:delay-if-busy (tasks:open-db)) run-id)))
;; res)))))
)
(list 0 1)))
(define start-time (current-seconds))
(define (reading-writing-while-server-starting-stopping-dont-run-now)
(let loop ((test-state 'start))
(let* ((server-dats (tasks:get-server-records (db:delay-if-busy (tasks:open-db)) run-id))
(first-dat (if (not (null? server-dats))
(car server-dats)
#f)))
(map (lambda (dat)
(apply print (intersperse (vector->list dat) ", ")))
server-dats)
(test #f test-one-rec (rmt:get-test-info-by-id run-id test-one-id))
(thread-sleep! 1)
(case test-state
((start)
(print "Trying to start server")
(server:kind-run run-id)
(loop 'server-started))
((server-started)
(case (if first-dat (vector-ref first-dat 0) 'blah)
((running)
(print "Server appears to be running. Now ask it to shutdown")
(rmt:kill-server run-id)
(loop 'server-shutdown))
((shutting-down)
(loop test-state))
(else (print "Don't know what to do if get here"))))
((server-shutdown)
(loop test-state)))))
)
;; )
;; (list 0 1)))
;;
;; (define start-time (current-seconds))
;; (define (reading-writing-while-server-starting-stopping-dont-run-now)
;; (let loop ((test-state 'start))
;; (let* ((server-dats (tasks:get-server-records (db:delay-if-busy (tasks:open-db)) run-id))
;; (first-dat (if (not (null? server-dats))
;; (car server-dats)
;; #f)))
;; (map (lambda (dat)
;; (apply print (intersperse (vector->list dat) ", ")))
;; server-dats)
;; (test #f test-one-rec (rmt:get-test-info-by-id run-id test-one-id))
;; (thread-sleep! 1)
;; (case test-state
;; ((start)
;; (print "Trying to start server")
;; (server:kind-run run-id)
;; (loop 'server-started))
;; ((server-started)
;; (case (if first-dat (vector-ref first-dat 0) 'blah)
;; ((running)
;; (print "Server appears to be running. Now ask it to shutdown")
;; (rmt:kill-server run-id)
;; (loop 'server-shutdown))
;; ((shutting-down)
;; (loop test-state))
;; (else (print "Don't know what to do if get here"))))
;; ((server-shutdown)
;; (loop test-state)))))
;; )
;;======================================================================
;; END OF TESTS
;;======================================================================
;; (test #f #f (client:setup run-id))
|