Skip to content

Commit 0d1d64f

Browse files
authored
fix: extension agent cannot quit normally in container (#303)
Co-authored-by: rick <[email protected]>
1 parent d6fde9f commit 0d1d64f

File tree

33 files changed

+245
-99
lines changed

33 files changed

+245
-99
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
[![Codacy Badge](https://app.codacy.com/project/badge/Coverage/3f16717cd6f841118006f12c346e9341)](https://app.codacy.com/gh/LinuxSuRen/api-testing/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
44
![GitHub All Releases](https://img.shields.io/github/downloads/linuxsuren/api-testing/total)
55
![Docker Pulls](https://img.shields.io/docker/pulls/linuxsuren/api-testing)
6-
![](https://sloc.xyz/github/linuxsuren/api-testing)
76
[![LinuxSuRen/open-source-best-practice](https://img.shields.io/static/v1?label=OSBP&message=%E5%BC%80%E6%BA%90%E6%9C%80%E4%BD%B3%E5%AE%9E%E8%B7%B5&color=blue)](https://github.com/LinuxSuRen/open-source-best-practice)
87

98
This is a API testing tool.

cmd/function.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import (
1313
"runtime"
1414
"strings"
1515

16-
"github.com/antonmedv/expr/builtin"
1716
"github.com/cucumber/godog"
17+
"github.com/expr-lang/expr/builtin"
1818
"github.com/linuxsuren/api-testing/pkg/render"
1919
"github.com/spf13/cobra"
2020
)

cmd/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func (o *runOption) startMonitor() (err error) {
194194

195195
execer := fakeruntime.NewDefaultExecerWithContext(o.context)
196196
go func(socketURL, plugin string) {
197-
if err = execer.RunCommandWithIO(plugin, "", os.Stdout, os.Stderr, "server", "--socket", socketURL); err != nil {
197+
if err = execer.RunCommandWithIO(plugin, "", os.Stdout, os.Stderr, nil, "server", "--socket", socketURL); err != nil {
198198
log.Printf("failed to start %s, error: %v", socketURL, err)
199199
}
200200
}(sockFile, monitorBin)

cmd/server.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ func (o *serverOption) runE(cmd *cobra.Command, args []string) (err error) {
207207
}
208208

209209
storeExtMgr := server.NewStoreExtManager(o.execer)
210+
defer storeExtMgr.StopAll()
210211

211212
remoteServer := server.NewRemoteServer(loader, remote.NewGRPCloaderFromStore(), secretServer, storeExtMgr, o.configDir)
212213
kinds, storeKindsErr := remoteServer.GetStoreKinds(ctx, nil)
@@ -219,7 +220,7 @@ func (o *serverOption) runE(cmd *cobra.Command, args []string) (err error) {
219220
}
220221

221222
clean := make(chan os.Signal, 1)
222-
signal.Notify(clean, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
223+
signal.Notify(clean, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGQUIT)
223224

224225
s := o.gRPCServer
225226
go func() {
@@ -233,9 +234,9 @@ func (o *serverOption) runE(cmd *cobra.Command, args []string) (err error) {
233234

234235
go func() {
235236
<-clean
237+
log.Println("stopping the server")
236238
_ = lis.Close()
237239
_ = o.httpServer.Shutdown(ctx)
238-
_ = storeExtMgr.StopAll()
239240
}()
240241

241242
mux := runtime.NewServeMux(runtime.WithMetadata(server.MetadataStoreFunc))

cmd/service.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,9 @@ func (s *podmanService) Install() (output string, err error) {
324324

325325
func (s *podmanService) Start() (output string, err error) {
326326
if s.exist() {
327-
err = s.Execer.RunCommandWithIO(s.client, "", s.stdOut, s.errOut, "start", s.name)
327+
err = s.Execer.RunCommandWithIO(s.client, "", s.stdOut, s.errOut, nil, "start", s.name)
328328
} else {
329-
err = s.Execer.RunCommandWithIO(s.client, "", s.stdOut, s.errOut, s.getStartArgs()...)
329+
err = s.Execer.RunCommandWithIO(s.client, "", s.stdOut, s.errOut, nil, s.getStartArgs()...)
330330
if err == nil {
331331
output, err = s.installService()
332332
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@ interface Secret {
2222
Value: string
2323
}
2424
25-
function loadStores() {
25+
function loadSecrets() {
2626
API.GetSecrets((e) => {
2727
secrets.value = e.data
2828
}, UIAPI.ErrorTip)
2929
}
30-
loadStores()
30+
loadSecrets()
3131
3232
function deleteSecret(name: string) {
3333
API.DeleteSecret(name, () => {
3434
ElMessage({
3535
message: 'Deleted.',
3636
type: 'success'
3737
})
38-
loadStores()
38+
loadSecrets()
3939
}, UIAPI.ErrorTip)
4040
}
4141
@@ -59,10 +59,10 @@ const rules = reactive<FormRules<Secret>>({
5959
})
6060
const submitForm = async (formEl: FormInstance | undefined) => {
6161
if (!formEl) return
62-
await formEl.validate((valid: boolean, fields) => {
62+
await formEl.validate((valid: boolean) => {
6363
if (valid) {
6464
UIAPI.CreateOrUpdateSecret(secret.value, createAction.value, () => {
65-
loadStores()
65+
loadSecrets()
6666
dialogVisible.value = false
6767
formEl.resetFields()
6868
}, creatingLoading)

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

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<script setup lang="ts">
22
import { ElMessage } from 'element-plus'
3-
import { reactive, ref } from 'vue'
3+
import { reactive, ref, watch } from 'vue'
44
import { Edit, Delete } from '@element-plus/icons-vue'
55
import type { FormInstance, FormRules } from 'element-plus'
66
import type { Pair } from './types'
77
import { API } from './net'
8+
import { UIAPI } from './net-vue'
89
import { SupportedExtensions } from './store'
910
import { useI18n } from 'vue-i18n'
1011
@@ -115,44 +116,25 @@ const rules = reactive<FormRules<Store>>({
115116
})
116117
const submitForm = async (formEl: FormInstance | undefined) => {
117118
if (!formEl) return
118-
await formEl.validate((valid: boolean, fields) => {
119+
await formEl.validate((valid: boolean) => {
119120
if (valid) {
120-
creatingLoading.value = true
121-
122-
const requestOptions = {
123-
method: 'POST',
124-
headers: {
125-
'X-Auth': API.getToken()
126-
},
127-
body: JSON.stringify(storeForm)
128-
}
129-
130-
let api = '/server.Runner/CreateStore'
131-
if (!createAction.value) {
132-
api = '/server.Runner/UpdateStore'
133-
}
134-
135-
fetch(api, requestOptions)
136-
.then((response) => {
137-
if (!response.ok) {
138-
throw new Error(response.statusText)
139-
} else {
140-
return response.json()
141-
}
142-
})
143-
.then(() => {
121+
UIAPI.CreateOrUpdateStore(storeForm, createAction.value, () => {
144122
loadStores()
145123
dialogVisible.value = false
146124
formEl.resetFields()
147-
})
148-
.catch((e) => {
149-
ElMessage.error('Oops, ' + e)
150-
})
151-
creatingLoading.value = false
125+
}, creatingLoading)
152126
}
153127
})
154128
}
155129
130+
watch(storeForm, (e) => {
131+
if (e.kind.name === '') {
132+
if (e.url.startsWith('https://github.com') || e.url.startsWith('https://gitee.com')) {
133+
e.kind.name = 'atest-store-git'
134+
}
135+
}
136+
})
137+
156138
function storeVerify(formEl: FormInstance | undefined) {
157139
if (!formEl) return
158140

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ function CreateOrUpdateSecret(payload: any, create: boolean,
4646
})
4747
}
4848

49+
function CreateOrUpdateStore(payload: any, create: boolean,
50+
callback: (d: any) => void,
51+
loadingRef?: Ref<Boolean>) {
52+
API.CreateOrUpdateStore(payload, create, callback, ErrorTip, (e: boolean) => {
53+
if (loadingRef) {
54+
loadingRef.value = e
55+
}
56+
})
57+
}
58+
4959
function ErrorTip(e: {
5060
statusText:''
5161
}) {
@@ -54,5 +64,6 @@ function ErrorTip(e: {
5464

5565
export const UIAPI = {
5666
UpdateTestCase, CreateOrUpdateSecret,
67+
CreateOrUpdateStore,
5768
ErrorTip
5869
}

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,30 @@ function PopularHeaders(callback: (d: any) => void, errHandle?: (e: any) => void
350350
.then(callback).catch(errHandle)
351351
}
352352

353+
function CreateOrUpdateStore(payload: any, create: boolean,
354+
callback: (d: any) => void, errHandle?: (e: any) => void | null,
355+
toggle?: (e: boolean) => void) {
356+
const requestOptions = {
357+
method: 'POST',
358+
headers: {
359+
'X-Auth': getToken()
360+
},
361+
body: JSON.stringify(payload)
362+
}
363+
364+
let api = '/server.Runner/CreateStore'
365+
if (!create) {
366+
api = '/server.Runner/UpdateStore'
367+
}
368+
369+
safeToggleFunc(toggle)(true)
370+
fetch(api, requestOptions)
371+
.then(DefaultResponseProcess)
372+
.then(callback).catch(errHandle).finally(() => {
373+
safeToggleFunc(toggle)(false)
374+
})
375+
}
376+
353377
function GetStores(callback: (d: any) => void,
354378
errHandle?: (e: any) => void | null, final?: () => void | null) {
355379
const requestOptions = {
@@ -499,7 +523,7 @@ export const API = {
499523
CreateTestCase, UpdateTestCase, GetTestCase, ListTestCase, DeleteTestCase, RunTestCase,
500524
GenerateCode, ListCodeGenerator,
501525
PopularHeaders,
502-
GetStores, DeleteStore, VerifyStore,
526+
CreateOrUpdateStore, GetStores, DeleteStore, VerifyStore,
503527
FunctionsQuery,
504528
GetSecrets, DeleteSecret, CreateOrUpdateSecret,
505529
GetSuggestedAPIs,

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
/**
2+
MIT License
3+
4+
Copyright (c) 2023 API Testing Authors.
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
*/
24+
125
import type { Pair } from './types'
226

327
export function SupportedExtensions() {

0 commit comments

Comments
 (0)