refactor: move boomer from hrp internal to pkg

This commit is contained in:
debugtalk
2022-10-11 11:17:58 +08:00
parent c81c5841ee
commit 0a0700dda8
41 changed files with 41 additions and 38 deletions

View File

@@ -13,10 +13,10 @@ import (
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"golang.org/x/net/context" "golang.org/x/net/context"
"github.com/httprunner/httprunner/v4/hrp/internal/boomer"
"github.com/httprunner/httprunner/v4/hrp/internal/builtin" "github.com/httprunner/httprunner/v4/hrp/internal/builtin"
"github.com/httprunner/httprunner/v4/hrp/internal/json" "github.com/httprunner/httprunner/v4/hrp/internal/json"
"github.com/httprunner/httprunner/v4/hrp/internal/sdk" "github.com/httprunner/httprunner/v4/hrp/internal/sdk"
"github.com/httprunner/httprunner/v4/hrp/pkg/boomer"
) )
func NewStandaloneBoomer(spawnCount int64, spawnRate float64) *HRPBoomer { func NewStandaloneBoomer(spawnCount int64, spawnRate float64) *HRPBoomer {

View File

@@ -10,8 +10,8 @@ import (
"golang.org/x/net/context" "golang.org/x/net/context"
"github.com/httprunner/httprunner/v4/hrp" "github.com/httprunner/httprunner/v4/hrp"
"github.com/httprunner/httprunner/v4/hrp/internal/boomer"
"github.com/httprunner/httprunner/v4/hrp/internal/builtin" "github.com/httprunner/httprunner/v4/hrp/internal/builtin"
"github.com/httprunner/httprunner/v4/hrp/pkg/boomer"
) )
// boomCmd represents the boom command // boomCmd represents the boom command

View File

@@ -9,8 +9,8 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/httprunner/httprunner/v4/hrp" "github.com/httprunner/httprunner/v4/hrp"
"github.com/httprunner/httprunner/v4/hrp/internal/boomer"
"github.com/httprunner/httprunner/v4/hrp/internal/convert" "github.com/httprunner/httprunner/v4/hrp/internal/convert"
"github.com/httprunner/httprunner/v4/hrp/pkg/boomer"
) )
var runCurlCmd = &cobra.Command{ var runCurlCmd = &cobra.Command{

View File

@@ -1,8 +1,6 @@
package boomer package boomer
import ( import (
"github.com/httprunner/httprunner/v4/hrp/internal/json"
"golang.org/x/net/context"
"math" "math"
"os" "os"
"os/signal" "os/signal"
@@ -11,6 +9,9 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"golang.org/x/net/context"
"github.com/httprunner/httprunner/v4/hrp/internal/json"
) )
// Mode is the running mode of boomer, both standalone and distributed are supported. // Mode is the running mode of boomer, both standalone and distributed are supported.
@@ -156,7 +157,6 @@ func NewWorkerBoomer(masterHost string, masterPort int) *Boomer {
// SetAutoStart auto start to load testing // SetAutoStart auto start to load testing
func (b *Boomer) SetAutoStart() { func (b *Boomer) SetAutoStart() {
b.masterRunner.autoStart = true b.masterRunner.autoStart = true
} }
// RunMaster start to run master runner // RunMaster start to run master runner

View File

@@ -8,6 +8,8 @@ import (
"sync/atomic" "sync/atomic"
"time" "time"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
"golang.org/x/oauth2" "golang.org/x/oauth2"
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/backoff" "google.golang.org/grpc/backoff"
@@ -15,10 +17,8 @@ import (
"google.golang.org/grpc/credentials/oauth" "google.golang.org/grpc/credentials/oauth"
"google.golang.org/grpc/metadata" "google.golang.org/grpc/metadata"
"github.com/httprunner/httprunner/v4/hrp/internal/boomer/data" "github.com/httprunner/httprunner/v4/hrp/pkg/boomer/data"
"github.com/httprunner/httprunner/v4/hrp/internal/boomer/grpc/messager" "github.com/httprunner/httprunner/v4/hrp/pkg/boomer/grpc/messager"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
) )
type grpcClient struct { type grpcClient struct {
@@ -247,7 +247,7 @@ func (c *grpcClient) recv() {
msg, err := c.config.getBiStreamClient().Recv() msg, err := c.config.getBiStreamClient().Recv()
if err != nil { if err != nil {
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
//log.Error().Err(err).Msg("failed to get message") // log.Error().Err(err).Msg("failed to get message")
continue continue
} }
if msg == nil { if msg == nil {
@@ -317,7 +317,7 @@ func (c *grpcClient) sendMessage(msg *genericMessage) {
atomic.StoreInt32(&c.failCount, 0) atomic.StoreInt32(&c.failCount, 0)
return return
} }
//log.Error().Err(err).Interface("genericMessage", *msg).Msg("failed to send message") // log.Error().Err(err).Interface("genericMessage", *msg).Msg("failed to send message")
if msg.Type == "heartbeat" { if msg.Type == "heartbeat" {
atomic.AddInt32(&c.failCount, 1) atomic.AddInt32(&c.failCount, 1)
} }

View File

@@ -38,7 +38,6 @@ func init() {
} }
hrpPath = filepath.Join(home, ".hrp") hrpPath = filepath.Join(home, ".hrp")
_ = builtin.EnsureFolderExists(filepath.Join(hrpPath, "x509")) _ = builtin.EnsureFolderExists(filepath.Join(hrpPath, "x509"))
} }
// Path returns the absolute path the given relative file or directory path // Path returns the absolute path the given relative file or directory path

View File

@@ -7,10 +7,11 @@
package messager package messager
import ( import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect" reflect "reflect"
sync "sync" sync "sync"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
) )
const ( const (
@@ -458,17 +459,20 @@ func file_grpc_proto_messager_proto_rawDescGZIP() []byte {
return file_grpc_proto_messager_proto_rawDescData return file_grpc_proto_messager_proto_rawDescData
} }
var file_grpc_proto_messager_proto_msgTypes = make([]protoimpl.MessageInfo, 8) var (
var file_grpc_proto_messager_proto_goTypes = []interface{}{ file_grpc_proto_messager_proto_msgTypes = make([]protoimpl.MessageInfo, 8)
(*StreamRequest)(nil), // 0: message.StreamRequest file_grpc_proto_messager_proto_goTypes = []interface{}{
(*StreamResponse)(nil), // 1: message.StreamResponse (*StreamRequest)(nil), // 0: message.StreamRequest
(*RegisterRequest)(nil), // 2: message.RegisterRequest (*StreamResponse)(nil), // 1: message.StreamResponse
(*RegisterResponse)(nil), // 3: message.RegisterResponse (*RegisterRequest)(nil), // 2: message.RegisterRequest
(*SignOutRequest)(nil), // 4: message.SignOutRequest (*RegisterResponse)(nil), // 3: message.RegisterResponse
(*SignOutResponse)(nil), // 5: message.SignOutResponse (*SignOutRequest)(nil), // 4: message.SignOutRequest
nil, // 6: message.StreamRequest.DataEntry (*SignOutResponse)(nil), // 5: message.SignOutResponse
nil, // 7: message.StreamResponse.DataEntry nil, // 6: message.StreamRequest.DataEntry
} nil, // 7: message.StreamResponse.DataEntry
}
)
var file_grpc_proto_messager_proto_depIdxs = []int32{ var file_grpc_proto_messager_proto_depIdxs = []int32{
6, // 0: message.StreamRequest.data:type_name -> message.StreamRequest.DataEntry 6, // 0: message.StreamRequest.data:type_name -> message.StreamRequest.DataEntry
7, // 1: message.StreamResponse.data:type_name -> message.StreamResponse.DataEntry 7, // 1: message.StreamResponse.data:type_name -> message.StreamResponse.DataEntry

View File

@@ -8,6 +8,7 @@ package messager
import ( import (
context "context" context "context"
grpc "google.golang.org/grpc" grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes" codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status" status "google.golang.org/grpc/status"
@@ -95,15 +96,16 @@ type MessageServer interface {
} }
// UnimplementedMessageServer must be embedded to have forward compatible implementations. // UnimplementedMessageServer must be embedded to have forward compatible implementations.
type UnimplementedMessageServer struct { type UnimplementedMessageServer struct{}
}
func (UnimplementedMessageServer) Register(context.Context, *RegisterRequest) (*RegisterResponse, error) { func (UnimplementedMessageServer) Register(context.Context, *RegisterRequest) (*RegisterResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method Register not implemented") return nil, status.Errorf(codes.Unimplemented, "method Register not implemented")
} }
func (UnimplementedMessageServer) SignOut(context.Context, *SignOutRequest) (*SignOutResponse, error) { func (UnimplementedMessageServer) SignOut(context.Context, *SignOutRequest) (*SignOutResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method SignOut not implemented") return nil, status.Errorf(codes.Unimplemented, "method SignOut not implemented")
} }
func (UnimplementedMessageServer) BidirectionalStreamingMessage(Message_BidirectionalStreamingMessageServer) error { func (UnimplementedMessageServer) BidirectionalStreamingMessage(Message_BidirectionalStreamingMessageServer) error {
return status.Errorf(codes.Unimplemented, "method BidirectionalStreamingMessage not implemented") return status.Errorf(codes.Unimplemented, "method BidirectionalStreamingMessage not implemented")
} }

View File

@@ -15,8 +15,8 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/httprunner/httprunner/v4/hrp/internal/boomer/grpc/messager"
"github.com/httprunner/httprunner/v4/hrp/internal/builtin" "github.com/httprunner/httprunner/v4/hrp/internal/builtin"
"github.com/httprunner/httprunner/v4/hrp/pkg/boomer/grpc/messager"
) )
const ( const (

View File

@@ -6,9 +6,10 @@ import (
"testing" "testing"
"time" "time"
"github.com/httprunner/httprunner/v4/hrp/internal/boomer/grpc/messager"
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
"github.com/httprunner/httprunner/v4/hrp/pkg/boomer/grpc/messager"
) )
type HitOutput struct { type HitOutput struct {

View File

@@ -9,6 +9,7 @@ import (
"sync/atomic" "sync/atomic"
"time" "time"
"github.com/rs/zerolog/log"
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials" "google.golang.org/grpc/credentials"
@@ -17,9 +18,8 @@ import (
"google.golang.org/grpc/reflection" "google.golang.org/grpc/reflection"
"google.golang.org/grpc/status" "google.golang.org/grpc/status"
"github.com/httprunner/httprunner/v4/hrp/internal/boomer/data" "github.com/httprunner/httprunner/v4/hrp/pkg/boomer/data"
"github.com/httprunner/httprunner/v4/hrp/internal/boomer/grpc/messager" "github.com/httprunner/httprunner/v4/hrp/pkg/boomer/grpc/messager"
"github.com/rs/zerolog/log"
) )
type WorkerNode struct { type WorkerNode struct {

View File

@@ -110,7 +110,6 @@ func TestLogError(t *testing.T) {
if err400.occurrences != 2 { if err400.occurrences != 2 {
t.Error("Error occurrences is wrong, expected: 2, got:", err400.occurrences) t.Error("Error occurrences is wrong, expected: 2, got:", err400.occurrences)
} }
} }
func BenchmarkLogError(b *testing.B) { func BenchmarkLogError(b *testing.B) {

View File

@@ -11,7 +11,6 @@ import (
"time" "time"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/shirou/gopsutil/cpu" "github.com/shirou/gopsutil/cpu"
"github.com/shirou/gopsutil/mem" "github.com/shirou/gopsutil/mem"

View File

@@ -32,7 +32,6 @@ func TestRound(t *testing.T) {
if roundOne != roundTwo { if roundOne != roundTwo {
t.Error("round(58360) should be equal to round(58460)") t.Error("round(58360) should be equal to round(58460)")
} }
} }
func TestGenMD5(t *testing.T) { func TestGenMD5(t *testing.T) {

View File

@@ -11,8 +11,8 @@ import (
"github.com/mitchellh/mapstructure" "github.com/mitchellh/mapstructure"
"github.com/httprunner/httprunner/v4/hrp/internal/boomer"
"github.com/httprunner/httprunner/v4/hrp/internal/json" "github.com/httprunner/httprunner/v4/hrp/internal/json"
"github.com/httprunner/httprunner/v4/hrp/pkg/boomer"
) )
const jsonContentType = "application/json; encoding=utf-8" const jsonContentType = "application/json; encoding=utf-8"