mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-10 17:43:00 +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:
2
Makefile
2
Makefile
@@ -28,7 +28,7 @@ build: ## build hrp cli tool
|
||||
# -w : 忽略 DWARF 调试信息
|
||||
# -extldflags "-static" : 传递给外部链接器的标志,强制静态链接
|
||||
@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 "\
|
||||
-s -w \
|
||||
-X 'github.com/httprunner/httprunner/v5/internal/version.GitCommit=$(shell git rev-parse HEAD)' \
|
||||
|
||||
@@ -1 +1 @@
|
||||
v5.0.0-250627
|
||||
v5.0.0-250628
|
||||
|
||||
@@ -728,7 +728,16 @@ func (d *Device) IsPackageInstalled(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 {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -10,8 +10,9 @@ PRE_COMMIT_FILE=.git/hooks/pre-commit
|
||||
|
||||
# install pre-commit hook and make it executable
|
||||
function install() {
|
||||
go get mvdan.cc/gofumpt
|
||||
go get github.com/incu6us/goimports-reviser/v3@latest
|
||||
# Install tools without modifying go.mod to avoid Go toolchain upgrade
|
||||
go install mvdan.cc/gofumpt@latest
|
||||
go install github.com/incu6us/goimports-reviser/v3@latest
|
||||
cat > $PRE_COMMIT_FILE <<'EOF'
|
||||
#!/bin/bash
|
||||
|
||||
@@ -48,7 +49,7 @@ version_file=internal/version/VERSION
|
||||
current_date=$(date +"%y%m%d")
|
||||
|
||||
# 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
|
||||
git add $version_file
|
||||
|
||||
@@ -14,9 +14,13 @@ import (
|
||||
"github.com/httprunner/httprunner/v5/uixt/option"
|
||||
)
|
||||
|
||||
func Version() string {
|
||||
return version.VERSION
|
||||
}
|
||||
|
||||
func NewSummary() *Summary {
|
||||
platForm := &Platform{
|
||||
HttprunnerVersion: version.VERSION,
|
||||
HttprunnerVersion: Version(),
|
||||
GoVersion: runtime.Version(),
|
||||
Platform: fmt.Sprintf("%v-%v", runtime.GOOS, runtime.GOARCH),
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ func (ud *UIA2Driver) Setup() error {
|
||||
localPort, ud.Device.Options.UIA2Port)
|
||||
ud.Session.SetBaseURL(baseURL)
|
||||
|
||||
// uiautomator2 server must be started before
|
||||
// Notice: uiautomator2 server must be started before running test
|
||||
|
||||
// check uiautomator server package installed
|
||||
if !ud.Device.IsPackageInstalled(ud.Device.Options.UIA2ServerPackageName) {
|
||||
@@ -74,19 +74,19 @@ func (ud *UIA2Driver) Setup() error {
|
||||
"%s not installed", ud.Device.Options.UIA2ServerTestPackageName)
|
||||
}
|
||||
|
||||
// TODO: check uiautomator server package running
|
||||
// if dev.IsPackageRunning(UIA2ServerPackageName) {
|
||||
// return nil
|
||||
// }
|
||||
|
||||
// start uiautomator2 server
|
||||
// Todo: keep-alive
|
||||
go func() {
|
||||
if err := ud.startUIA2Server(); err != nil {
|
||||
log.Fatal().Err(err).Msg("start UIA2 failed")
|
||||
}
|
||||
}()
|
||||
time.Sleep(5 * time.Second) // wait for uiautomator2 server start
|
||||
// check uiautomator server package running
|
||||
if ud.Device.IsPackageRunning(ud.Device.Options.UIA2ServerTestPackageName) {
|
||||
log.Info().Str("package", ud.Device.Options.UIA2ServerTestPackageName).
|
||||
Msg("uiautomator2 server is already running, skip starting")
|
||||
} else {
|
||||
// start uiautomator2 server
|
||||
go func() {
|
||||
if err := ud.startUIA2Server(); err != nil {
|
||||
log.Fatal().Err(err).Msg("start UIA2 failed")
|
||||
}
|
||||
}()
|
||||
time.Sleep(5 * time.Second) // wait for uiautomator2 server start
|
||||
}
|
||||
|
||||
// create new session
|
||||
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...")
|
||||
}
|
||||
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