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
|
;;======================================================================
;; S E R V E R
;;======================================================================
;; Run like this:
;;
;; ./rununittest.sh server 1;(cd simplerun;megatest -stop-server 0)
(delete-file* "logs/1.log")
(define run-id 1)
(test "setup for run" #t (begin (launch:setup-for-run)
(string? (getenv "MT_RUN_AREA_HOME"))))
;; NON Server tests go here
(test #f #f (db:dbdat-get-path *db*))
(test #f #f (db:get-run-name-from-id *db* run-id))
;; (test #f '("SYSTEM" "RELEASE") (rmt:get-keys))
;; (exit)
;; Server tests go here
(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
(if (> remtries 0)
(begin
(thread-sleep! 1.1)
(loop (- remtries 1)(tasks:get-server (db:delay-if-busy (tasks:open-db)) run-id)))
res)))))
)
(list 0 1))
(define user (current-user-name))
(define runname "mytestrun")
(define keys (rmt:get-keys))
(define runinfo #f)
(define keyvals '(("SYSTEM" "abc")("RELEASE" "def")))
(define header (list "SYSTEM" "RELEASE" "id" "runname" "state" "status" "owner" "event_time"))
;; 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")
(rmt:login-no-auto-client-setup (hash-table-ref/default *runremote* run-id #f) run-id))
(test #f '(#t "successful login")
(rmt:login run-id))
|
|
|
>
>
|
>
>
>
>
>
>
>
>
>
|
|
|
|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
>
|
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
115
116
|
;;======================================================================
;; S E R V E R
;;======================================================================
;; Run like this:
;;
;; ./rununittest.sh server 1;(cd simplerun;megatest -stop-server 0)
(delete-file* "logs/1.log")
(define run-id 1)
(test "setup for run" #t (begin (launch:setup-for-run *area-dat*)
(string? (getenv "MT_RUN_AREA_HOME"))))
;; NON Server tests go here
(test #f #f (db:dbdat-get-path *db*))
(print "db:get-run-name, try one")
(test #f #t (string? (db:get-run-name-from-id *db* *area-dat* run-id)))
(print "db:get-run-name, try two")
(test #f #t (string? (db:get-run-name-from-id *db* *area-dat* run-id)))
(print "db:get-run-name, try three")
(test #f #t (string? (db:get-run-name-from-id *db* *area-dat* run-id)))
(print "db:get-run-name, try four")
(test #f #t (string? (db:get-run-name-from-id *db* *area-dat* run-id)))
;; (test #f '("SYSTEM" "RELEASE") (rmt:get-keys))
;; (exit)
;; Server tests go here
(print "Start server tests")
(for-each
(lambda (run-id)
(test #f #f (tasks:server-running-or-starting? (db:delay-if-busy (tasks:open-db *area-dat*) *area-dat*) run-id))
(server:kind-run run-id *area-dat*)
(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 *area-dat*) *area-dat*)
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 *area-dat*) *area-dat*)
run-id)))))))
(test "did server become available" #t
(let loop ((remtries 10)
(res (tasks:get-server (db:delay-if-busy (tasks:open-db *area-dat*) *area-dat*) run-id)))
(if res
(vector? res)
(begin
(if (> remtries 0)
(begin
(thread-sleep! 1.1)
(loop (- remtries 1)(tasks:get-server (db:delay-if-busy (tasks:open-db *area-dat*) *area-dat*) run-id)))
res)))))
)
(list 0 1))
(define user (current-user-name))
(define runname "mytestrun")
(define keys (rmt:get-keys *area-dat*))
(define runinfo #f)
(define keyvals '(("SYSTEM" "abc")("RELEASE" "def")))
(define header (list "SYSTEM" "RELEASE" "id" "runname" "state" "status" "owner" "event_time"))
;; Stuff to test before running client:setup
;;
(test #f #f (tasks:get-server (db:delay-if-busy (tasks:open-db *area-dat*) *area-dat*) 1))
(server:kind-run 1 *area-dat*)
(let loop ((count 5)
(ok (tasks:get-server (db:delay-if-busy (tasks:open-db *area-dat*) *area-dat*) 1)))
(if (and (> count 0)(not ok))
(begin
(print "Waiting for server to start...")
(thread-sleep! 1)
(loop (- count 1)(tasks:get-server (db:delay-if-busy (tasks:open-db *area-dat*) *area-dat*) 1)))
(print "Server started ....")))
(define *start-res* (let* ((server-dat #f)
(iface #f)
(hostname #f)
(port #f)
(remoteconn #f))
(test #f #t (begin (set! server-dat (tasks:get-server (db:delay-if-busy (tasks:open-db *area-dat*) *area-dat*) 1))
(vector? server-dat)))
(test #f #t (begin (set! iface (tasks:hostinfo-get-interface server-dat))
(string? iface)))
(test #f #t (begin (set! hostname (tasks:hostinfo-get-hostname server-dat))
(string? hostname)))
(test #f #t (begin (set! port (tasks:hostinfo-get-port server-dat))
(number? port)))
(test #f #t (begin (set! remoteconn (http-transport:client-connect iface port))
(vector? remoteconn)))
remoteconn))
;; Setup
;;
(test #f #f (not (client:setup run-id *area-dat*)))
;; Login
;;
(test #f'(#t "successful login")
(rmt:login-no-auto-client-setup (hash-table-ref/default *runremote* run-id #f) run-id))
(test #f '(#t "successful login")
(rmt:login run-id))
|
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
"runname")))
(for-each (lambda (run-id)
;; test killing server
;;
(tasks:kill-server-run-id run-id)
(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
(define start-time (current-seconds))
(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))
|
|
|
|
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
"runname")))
(for-each (lambda (run-id)
;; test killing server
;;
(tasks:kill-server-run-id run-id)
(test #f #f (tasks:server-running-or-starting? (db:delay-if-busy (tasks:open-db *area-dat*) *area-dat*) run-id))
)
(list 0 1))
;; Tests to assess reading/writing while servers are starting/stopping
(define start-time (current-seconds))
(let loop ((test-state 'start))
(let* ((server-dats (tasks:get-server-records (db:delay-if-busy (tasks:open-db *area-dat*) *area-dat*) 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))
|
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
|
;; (set! *transport-type* 'http)
;;
;; (test "setup for run" #t (begin (launch: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*)))
|
|
|
|
|
|
|
|
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
|
;; (set! *transport-type* 'http)
;;
;; (test "setup for run" #t (begin (launch: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 *area-dat* 1 "bob" 1234 100 'live 'http)
;; (set! res (open-run-close tasks:get-best-server tasks:open-db *area-dat*))
;; (number? (vector-ref res 3))))
;;
;; (test "de-register server" #f (let ((res #f))
;; (open-run-close tasks:server-deregister tasks:open-db *area-dat* "bob" port: 1234)
;; (vector? (open-run-close tasks:get-best-server tasks:open-db *area-dat*))))
;;
;; (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 *area-dat*)))
;; (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 *area-dat*)))
;; (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*)))
|