mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 07:26:55 +08:00
Merge 'bugfix-fix' into 'master'
Bugfix:check UIA2 Server running before starting to avoid conflicting See merge request: !108
This commit is contained in:
@@ -28,7 +28,7 @@ build: ## build hrp cli tool
|
|||||||
# -w : 忽略 DWARF 调试信息
|
# -w : 忽略 DWARF 调试信息
|
||||||
# -extldflags "-static" : 传递给外部链接器的标志,强制静态链接
|
# -extldflags "-static" : 传递给外部链接器的标志,强制静态链接
|
||||||
@echo "[info] build hrp cli tool"
|
@echo "[info] build hrp cli tool"
|
||||||
go mod tidy
|
GOTOOLCHAIN=go1.23 go mod tidy
|
||||||
GOOS=${TARGET_OS} GOARCH=${TARGET_ARCH} CGO_ENABLED=0 go build -tags netgo,osusergo -trimpath -ldflags "\
|
GOOS=${TARGET_OS} GOARCH=${TARGET_ARCH} CGO_ENABLED=0 go build -tags netgo,osusergo -trimpath -ldflags "\
|
||||||
-s -w \
|
-s -w \
|
||||||
-X 'github.com/httprunner/httprunner/v5/internal/version.GitCommit=$(shell git rev-parse HEAD)' \
|
-X 'github.com/httprunner/httprunner/v5/internal/version.GitCommit=$(shell git rev-parse HEAD)' \
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
v5.0.0-250627
|
v5.0.0-250628
|
||||||
|
|||||||
+10
-1
@@ -728,7 +728,16 @@ func (d *Device) IsPackageInstalled(packageName string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Device) IsPackageRunning(packageName string) bool {
|
func (d *Device) IsPackageRunning(packageName string) bool {
|
||||||
output, err := d.RunShellCommand("pidof", packageName)
|
packageName = strings.TrimSpace(packageName)
|
||||||
|
if packageName == "" {
|
||||||
|
log.Error().Msg("package name is empty, skip checking package running")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use ps -ef command with grep to check if package is running
|
||||||
|
// ps -ef shows full command line which includes package name as argument
|
||||||
|
// This works for both regular apps and instrumentation test processes
|
||||||
|
output, err := d.RunShellCommand("ps -ef | grep " + packageName + " | grep -v grep")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,8 +10,9 @@ PRE_COMMIT_FILE=.git/hooks/pre-commit
|
|||||||
|
|
||||||
# install pre-commit hook and make it executable
|
# install pre-commit hook and make it executable
|
||||||
function install() {
|
function install() {
|
||||||
go get mvdan.cc/gofumpt
|
# Install tools without modifying go.mod to avoid Go toolchain upgrade
|
||||||
go get github.com/incu6us/goimports-reviser/v3@latest
|
go install mvdan.cc/gofumpt@latest
|
||||||
|
go install github.com/incu6us/goimports-reviser/v3@latest
|
||||||
cat > $PRE_COMMIT_FILE <<'EOF'
|
cat > $PRE_COMMIT_FILE <<'EOF'
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
@@ -48,7 +49,7 @@ version_file=internal/version/VERSION
|
|||||||
current_date=$(date +"%y%m%d")
|
current_date=$(date +"%y%m%d")
|
||||||
|
|
||||||
# update version
|
# update version
|
||||||
sed -i '' "s/[0-9]\{10\}/${current_date}/" "$version_file"
|
sed -i '' "s/[0-9]\{6\}/${current_date}/" "$version_file"
|
||||||
|
|
||||||
# add change to stage
|
# add change to stage
|
||||||
git add $version_file
|
git add $version_file
|
||||||
|
|||||||
+5
-1
@@ -14,9 +14,13 @@ import (
|
|||||||
"github.com/httprunner/httprunner/v5/uixt/option"
|
"github.com/httprunner/httprunner/v5/uixt/option"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func Version() string {
|
||||||
|
return version.VERSION
|
||||||
|
}
|
||||||
|
|
||||||
func NewSummary() *Summary {
|
func NewSummary() *Summary {
|
||||||
platForm := &Platform{
|
platForm := &Platform{
|
||||||
HttprunnerVersion: version.VERSION,
|
HttprunnerVersion: Version(),
|
||||||
GoVersion: runtime.Version(),
|
GoVersion: runtime.Version(),
|
||||||
Platform: fmt.Sprintf("%v-%v", runtime.GOOS, runtime.GOARCH),
|
Platform: fmt.Sprintf("%v-%v", runtime.GOOS, runtime.GOARCH),
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-15
@@ -62,7 +62,7 @@ func (ud *UIA2Driver) Setup() error {
|
|||||||
localPort, ud.Device.Options.UIA2Port)
|
localPort, ud.Device.Options.UIA2Port)
|
||||||
ud.Session.SetBaseURL(baseURL)
|
ud.Session.SetBaseURL(baseURL)
|
||||||
|
|
||||||
// uiautomator2 server must be started before
|
// Notice: uiautomator2 server must be started before running test
|
||||||
|
|
||||||
// check uiautomator server package installed
|
// check uiautomator server package installed
|
||||||
if !ud.Device.IsPackageInstalled(ud.Device.Options.UIA2ServerPackageName) {
|
if !ud.Device.IsPackageInstalled(ud.Device.Options.UIA2ServerPackageName) {
|
||||||
@@ -74,19 +74,19 @@ func (ud *UIA2Driver) Setup() error {
|
|||||||
"%s not installed", ud.Device.Options.UIA2ServerTestPackageName)
|
"%s not installed", ud.Device.Options.UIA2ServerTestPackageName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: check uiautomator server package running
|
// check uiautomator server package running
|
||||||
// if dev.IsPackageRunning(UIA2ServerPackageName) {
|
if ud.Device.IsPackageRunning(ud.Device.Options.UIA2ServerTestPackageName) {
|
||||||
// return nil
|
log.Info().Str("package", ud.Device.Options.UIA2ServerTestPackageName).
|
||||||
// }
|
Msg("uiautomator2 server is already running, skip starting")
|
||||||
|
} else {
|
||||||
// start uiautomator2 server
|
// start uiautomator2 server
|
||||||
// Todo: keep-alive
|
go func() {
|
||||||
go func() {
|
if err := ud.startUIA2Server(); err != nil {
|
||||||
if err := ud.startUIA2Server(); err != nil {
|
log.Fatal().Err(err).Msg("start UIA2 failed")
|
||||||
log.Fatal().Err(err).Msg("start UIA2 failed")
|
}
|
||||||
}
|
}()
|
||||||
}()
|
time.Sleep(5 * time.Second) // wait for uiautomator2 server start
|
||||||
time.Sleep(5 * time.Second) // wait for uiautomator2 server start
|
}
|
||||||
|
|
||||||
// create new session
|
// create new session
|
||||||
err = ud.InitSession(nil)
|
err = ud.InitSession(nil)
|
||||||
@@ -604,7 +604,7 @@ func (ud *UIA2Driver) startUIA2Server() error {
|
|||||||
log.Error().Err(err).Int("retryCount", maxRetries).Msg("start uiautomator server failed, retrying...")
|
log.Error().Err(err).Int("retryCount", maxRetries).Msg("start uiautomator server failed, retrying...")
|
||||||
}
|
}
|
||||||
if strings.Contains(out, "Process crashed") {
|
if strings.Contains(out, "Process crashed") {
|
||||||
log.Error().Msg("uiautomator server crashed, retrying...")
|
log.Error().Str("output", out).Msg("uiautomator server crashed, retrying...")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user