Skip to content

Commit

Permalink
fix test kangle.reload missing resp.body close
Browse files Browse the repository at this point in the history
  • Loading branch information
keengo99 committed Dec 10, 2024
1 parent 68e7b49 commit 596e1a1
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 17 deletions.
2 changes: 1 addition & 1 deletion khttpd
Submodule khttpd updated from 7e8b3d to feb51f
43 changes: 28 additions & 15 deletions test/test_framework/base_suite/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ import (

func check_reload_none_config() {
kangle.CleanExtConfig("not_exsit")
kangle.Reload("ext|not_exsit.xml_")
resp := kangle.Reload("ext|not_exsit.xml_")
common.AssertPort(4444, false)
kangle.CreateExtConfig("not_exsit", `<!--#start 10 -->
<config>
<listen ip='127.0.0.1' port='4444' type='http'/>
</config>
`)
kangle.Reload("ext|not_exsit.xml_")
resp.Body.Close()
resp = kangle.Reload("ext|not_exsit.xml_")
common.AssertPort(4444, true)
resp.Body.Close()

}
func check_listen_config() {
Expand All @@ -34,9 +36,11 @@ func check_listen_config() {
<config>
</config>
`)
resp.Body.Close()
resp = kangle.Reload("ext|10.xml_")
common.AssertSame(resp.StatusCode, 204)
common.AssertPort(7777, false)
resp.Body.Close()
}
func check_vh_config() {
access_file := config.Cfg.BasePath + "/www/access.xml"
Expand All @@ -50,7 +54,7 @@ func check_vh_config() {
</config>
<!--configfileisok-->
`)
kangle.Reload("ext|20.xml_")
resp := kangle.Reload("ext|20.xml_")

kangle.CreateExtConfig("20", `<!--#start 20 -->
<config>
Expand All @@ -60,7 +64,8 @@ func check_vh_config() {
</vh>
</config>
`)
kangle.Reload("ext|20.xml_")
resp.Body.Close()
resp = kangle.Reload("ext|20.xml_")

kangle.CreateExtConfig("20", `<!--#start 20 -->
<config>
Expand All @@ -69,8 +74,9 @@ func check_vh_config() {
</vh>
</config>
`)
kangle.Reload("ext|20.xml_")

resp.Body.Close()
resp = kangle.Reload("ext|20.xml_")
resp.Body.Close()
kangle.ReloadConfig()
}
func create_wrong_ssl_cert() {
Expand Down Expand Up @@ -112,9 +118,11 @@ func check_listen_ssl_config_change() {
<config>
<listen ip='127.0.0.1' port='7766' type='https' certificate='etc/server2.crt' certificate_key='etc/server.key' http2='1' />
</config>`)
kangle.Reload("ext|20.xml_")
resp := kangle.Reload("ext|20.xml_")
resp.Body.Close()
create_right_ssl_cert()
kangle.Reload("ext|20.xml_")
resp = kangle.Reload("ext|20.xml_")
resp.Body.Close()
check_ssl_port_status("", 7766)
}
func check_ssl_port_status(host string, port int) {
Expand All @@ -139,13 +147,15 @@ func check_vh_ssl_config_change() {
</config>
<!--configfileisok-->
`)
kangle.Reload("ext|20.xml_")
resp := kangle.Reload("ext|20.xml_")
resp.Body.Close()
create_right_ssl_cert()
kangle.Reload("ext|20.xml_")
resp = kangle.Reload("ext|20.xml_")
resp.Body.Close()
check_ssl_port_status("", 7767)
kangle.CreateExtConfig("20", `<!--#start 20 --><!--configfileisok-->`)
kangle.Reload("ext|20.xml_")

resp = kangle.Reload("ext|20.xml_")
resp.Body.Close()
}
func check_vh_host_ssl_change() {
create_wrong_ssl_cert()
Expand All @@ -159,12 +169,15 @@ func check_vh_host_ssl_change() {
</config>
<!--configfileisok-->
`)
kangle.Reload("ext|20.xml_")
resp := kangle.Reload("ext|20.xml_")
create_right_ssl_cert()
kangle.Reload("ext|20.xml_")
resp.Body.Close()
resp = kangle.Reload("ext|20.xml_")
resp.Body.Close()
check_ssl_port_status(config.GetLocalhost("testssl"), 7768)
kangle.CreateExtConfig("20", `<!--#start 20 --><!--configfileisok-->`)
kangle.Reload("ext|20.xml_")
resp = kangle.Reload("ext|20.xml_")
resp.Body.Close()
}
func check_config() {

Expand Down
3 changes: 2 additions & 1 deletion test/test_framework/base_suite/config_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ func create_config_file(server_cfg string) {
</config>
<!--configfileisok-->
`, server_cfg))
kangle.Reload("ext|20.xml_")
resp := kangle.Reload("ext|20.xml_")
resp.Body.Close()
}
func check_config_server() {

Expand Down
3 changes: 3 additions & 0 deletions test/test_framework/kangle/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@ func CleanAllCache() {
panic(err)
}
common.Assert("clean_all_cache", resp.StatusCode == 200)
resp.Body.Close()
}
func ReloadConfig() {
resp, _ := common.Http1Client.Get("http://127.0.0.1:9911/reload_config")
common.Assert("reload_config", resp.StatusCode == 200)
resp.Body.Close()
}
func FlushDiskCache() {
resp, _ := common.Http1Client.Get("http://127.0.0.1:9911/flush_disk_cache.km")
common.Assert("reload_config", resp.StatusCode == 200)
resp.Body.Close()
}
func CreateFile(filename string, content string) error {
config_file, err := os.Create(filename)
Expand Down
6 changes: 6 additions & 0 deletions test/test_framework/suite/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func SplitSuiteCase(name string) (suite string, testCase string) {
return name, ""
}
func Init(names []string) {
inited_suite := make(map[string]bool, 0)
for _, name := range names {
s, _ := SplitSuiteCase(name)
suite, ok := suites[s]
Expand All @@ -38,6 +39,11 @@ func Init(names []string) {
panic("")
}
common.AssertSame(ok, true)
_, ok = inited_suite[s]
if ok {
continue
}
inited_suite[s] = true
fmt.Printf("init suite [%s]\n", name)
suite.Init()
}
Expand Down

0 comments on commit 596e1a1

Please sign in to comment.