fix: unittest

This commit is contained in:
徐聪
2022-07-11 12:31:52 +08:00
parent 0b60b7a507
commit 2cdebbf448
7 changed files with 15 additions and 10 deletions

View File

@@ -1,4 +1,4 @@
# NOTE: Generated By hrp v4.1.5, DO NOT EDIT!
# NOTE: Generated By hrp v4.1.6, DO NOT EDIT!
import sys
import os

View File

@@ -1,13 +1,13 @@
package cmd
import (
"golang.org/x/net/context"
"os"
"strings"
"time"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"golang.org/x/net/context"
"github.com/httprunner/httprunner/v4/hrp"
"github.com/httprunner/httprunner/v4/hrp/internal/boomer"
@@ -39,7 +39,7 @@ var boomCmd = &cobra.Command{
// if set profile, the priority is higher than the other commands
if boomArgs.profile != "" {
err := builtin.LoadFile(boomArgs.profile, &boomArgs.profile)
err := builtin.LoadFile(boomArgs.profile, &boomArgs.Profile)
if err != nil {
log.Error().Err(err).Msg("failed to load profile")
os.Exit(1)
@@ -134,9 +134,9 @@ func init() {
boomCmd.Flags().BoolVar(&boomArgs.ignoreQuit, "ignore-quit", false, "ignores quit from master (only when --worker is used)")
boomCmd.Flags().StringVar(&boomArgs.masterHost, "master-host", "127.0.0.1", "Host or IP address of hrp master for distributed load testing.")
boomCmd.Flags().IntVar(&boomArgs.masterPort, "master-port", 5557, "The port to connect to that is used by the hrp master for distributed load testing.")
boomCmd.Flags().BoolVar(&boomArgs.autoStart, "autostart", false, "Starts the test immediately (without disabling the web UI). Use --spawn-count and --spawn-rate to control user count and increase rate")
boomCmd.Flags().BoolVar(&boomArgs.autoStart, "auto-start", false, "Starts the test immediately. Use --spawn-count and --spawn-rate to control user count and increase rate")
boomCmd.Flags().IntVar(&boomArgs.expectWorkers, "expect-workers", 1, "How many workers master should expect to connect before starting the test (only when --autostart is used)")
boomCmd.Flags().IntVar(&boomArgs.expectWorkersMaxWait, "expect-workers-max-wait", 0, "How many workers master should expect to connect before starting the test (only when --autostart is used")
boomCmd.Flags().IntVar(&boomArgs.expectWorkersMaxWait, "expect-workers-max-wait", 120, "How many workers master should expect to connect before starting the test (only when --autostart is used")
}
func makeHRPBoomer() *hrp.HRPBoomer {

View File

@@ -392,7 +392,7 @@ var (
gaugeState = prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "state",
Help: "The current runner state, 1=initializing, 2=spawning, 3=running, 4=quitting, 5=stopped",
Help: "The current runner state, 1=initializing, 2=spawning, 3=running, 4=stopping, 5=stopped, 6=quitting, 7=missing",
},
)
gaugeDuration = prometheus.NewGauge(

View File

@@ -43,7 +43,7 @@ func getStateName(state int32) (stateName string) {
case StateQuitting:
stateName = "quitting"
case StateMissing:
stateName = "stopped"
stateName = "missing"
}
return
}
@@ -840,9 +840,12 @@ func (r *workerRunner) run() {
log.Warn().Msg("Timeout waiting for sending quit message to master, boomer will quit any way.")
}
if err = r.client.signOut(r.client.config.ctx); err != nil {
log.Error().Err(err).Msg("failed to sign out")
if r.getState() != StateMissing {
if err = r.client.signOut(r.client.config.ctx); err != nil {
log.Error().Err(err).Msg("failed to sign out")
}
}
r.client.close()
}
}()

View File

@@ -196,7 +196,7 @@ func TestSpawnWorkersWithManyTasks(t *testing.T) {
const numToSpawn int64 = 30
go runner.spawnWorkers(numToSpawn, float64(numToSpawn), runner.stopChan, runner.spawnComplete)
time.Sleep(2 * time.Second)
time.Sleep(3 * time.Second)
currentClients := runner.controller.getCurrentClientsNum()

View File

@@ -1,3 +1,4 @@
//go:build !windows
// +build !windows
package boomer

View File

@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package boomer