Skip to content

Commit 62699d2

Browse files
committed
support to the interval on batch mode
1 parent 8773fb8 commit 62699d2

File tree

5 files changed

+582
-550
lines changed

5 files changed

+582
-550
lines changed

console/atest-ui/src/views/TestCase.vue

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ const sendRequest = async () => {
6060
}
6161
Magic.Keys(sendRequest, ['Alt+S', 'Alt+ß'])
6262
63+
const runTestCaseResultHandler = (e: any) => {
64+
requestLoading.value = false
65+
handleTestResult(e)
66+
}
6367
const runTestCase = () => {
6468
requestLoading.value = true
6569
const name = props.name
@@ -73,20 +77,17 @@ const runTestCase = () => {
7377
if (batchRunMode.value) {
7478
API.BatchRunTestCase({
7579
count: batchRunCount.value,
80+
interval: batchRunInterval.value,
7681
request: request
77-
}, (d) => {
82+
}, runTestCaseResultHandler, (e) => {
83+
parameters.value = []
84+
7885
requestLoading.value = false
79-
ElMessage({
80-
showClose: true,
81-
message: d,
82-
type: 'success'
83-
})
86+
UIAPI.ErrorTip(e)
87+
parseResponseBody(e.body)
8488
})
8589
} else {
86-
API.RunTestCase(request, (e) => {
87-
handleTestResult(e)
88-
requestLoading.value = false
89-
}, (e) => {
90+
API.RunTestCase(request, runTestCaseResultHandler, (e) => {
9091
parameters.value = []
9192
9293
requestLoading.value = false
@@ -168,6 +169,7 @@ function responseBodyFilter() {
168169
const parameterDialogOpened = ref(false)
169170
const batchRunMode = ref(false)
170171
const batchRunCount = ref(1)
172+
const batchRunInterval = ref('1s')
171173
const openBatchRunDialog = () => {
172174
batchRunMode.value = true
173175
openParameterDialog()
@@ -1269,7 +1271,15 @@ Magic.Keys(() => {
12691271
Count:
12701272
</el-col>
12711273
<el-col :span="18">
1272-
<el-input v-model="batchRunCount" type="number" />
1274+
<el-input v-model="batchRunCount" type="number" min="1" max="100"/>
1275+
</el-col>
1276+
</el-row>
1277+
<el-row>
1278+
<el-col :span="6">
1279+
Interval:
1280+
</el-col>
1281+
<el-col :span="18">
1282+
<el-input v-model="batchRunInterval" />
12731283
</el-col>
12741284
</el-row>
12751285
</div>

console/atest-ui/src/views/net.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ interface RunTestCaseRequest {
284284

285285
interface BatchRunTestCaseRequest {
286286
count: number
287+
interval: string
287288
request: RunTestCaseRequest
288289
}
289290

@@ -306,7 +307,8 @@ function RunTestCase(request: RunTestCaseRequest,
306307
.then(callback).catch(emptyOrDefault(errHandle))
307308
}
308309

309-
const BatchRunTestCase = (request: BatchRunTestCaseRequest, callback: (d: any) => void) => {
310+
const BatchRunTestCase = (request: BatchRunTestCaseRequest,
311+
callback: (d: any) => void, errHandle?: (e: any) => void | null) => {
310312
const requestOptions = {
311313
method: 'POST',
312314
headers: {
@@ -319,26 +321,29 @@ const BatchRunTestCase = (request: BatchRunTestCaseRequest, callback: (d: any) =
319321
caseName: request.request.name,
320322
parameters: request.request.parameters,
321323
count: request.count,
324+
interval: request.interval,
322325
})
323326
}
324327
fetch(`/api/v1/batchRun`, requestOptions)
325328
.then((response: any) => {
326329
if (response.ok) {
327-
const reader = response.body.getReader();
328-
let { done, value } = reader.read();
329-
while (!done) {
330-
const chunk = new TextDecoder().decode(value, { stream: true });
331-
332-
console.log(chunk);
333-
// callback(chunk);
334-
335-
({ done, value } = reader.read());
330+
const read = (reader: any) => {
331+
reader.read().then((data: any) => {
332+
if (data.done) {
333+
return;
334+
}
335+
336+
const value = data.value;
337+
const chunk = new TextDecoder().decode(value, { stream: true });
338+
callback(JSON.parse(chunk).result.testCaseResult[0]);
339+
read(reader);
340+
});
336341
}
337-
callback('');
342+
read(response.body.getReader());
338343
} else {
339-
throw new Error('Network response was not ok.');
344+
return DefaultResponseProcess(response)
340345
}
341-
})
346+
}).catch(emptyOrDefault(errHandle))
342347
}
343348

344349
function DuplicateTestCase(sourceSuiteName: string, targetSuiteName: string,

pkg/server/remote_server.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,11 @@ func (s *server) BatchRun(srv Runner_BatchRunServer) (err error) {
311311
return err
312312
}
313313

314+
var duration time.Duration
315+
if duration, err = time.ParseDuration(in.Interval); err != nil {
316+
return
317+
}
318+
314319
for i := 0; i < int(in.Count); i++ {
315320
var reply *TestCaseResult
316321
if reply, err = s.RunTestCase(ctx, &TestCaseIdentity{
@@ -326,7 +331,8 @@ func (s *server) BatchRun(srv Runner_BatchRunServer) (err error) {
326331
}); err != nil {
327332
return err
328333
}
329-
time.Sleep(time.Second * 2)
334+
335+
time.Sleep(duration)
330336
}
331337
}
332338
}

0 commit comments

Comments
 (0)