package ui import ( cfg "go_dreamfactory/cmd/v2/configure/structs" "go_dreamfactory/cmd/v2/lib" "go_dreamfactory/cmd/v2/lib/common" "go_dreamfactory/cmd/v2/lib/storage" "go_dreamfactory/cmd/v2/service" "go_dreamfactory/cmd/v2/service/observer" "go_dreamfactory/comm" "go_dreamfactory/pb" "strings" "time" "fyne.io/fyne/v2" "fyne.io/fyne/v2/container" "fyne.io/fyne/v2/layout" "fyne.io/fyne/v2/theme" "fyne.io/fyne/v2/widget" "github.com/Pallinder/go-randomdata" "github.com/sirupsen/logrus" "google.golang.org/protobuf/proto" ) type perfChoose struct { appAdapter obs observer.Observer conf *storage.Config binduids []string //账号 handler lib.Handler } func (app *perfChoose) LazyInit(ptService service.PttService, obs observer.Observer) error { app.obs = obs app.conf = perfWin.UIImpl.config app.tabItem = container.NewTabItemWithIcon(common.TOOLBAR_PERF_CHOOSE, theme.ContentCopyIcon(), nil) content := container.NewMax() content.Objects = []fyne.CanvasObject{} loginTestBtn := widget.NewButton("登陆(注册)", nil) loginTestBtn.OnTapped = func() { closeApp3(perfWin.tabs, common.TOOLBAR_PERF_CHOOSE) openApp3(perfWin.tabs, common.TOOLBAR_PERF_RES) var err error app.handler, err = service.NewWsCli(app.conf.WsAddr, 2*time.Second) if err != nil { panic(err) } userCount := app.conf.UserCount for i := int32(0); i < userCount; i++ { account := randomdata.SillyName() app.binduids = append(app.binduids, account) // 登录 rqLogin := ReqParams{ Sid: app.conf.SId, Account: account, PbReq: &pb.UserLoginReq{Sid: app.conf.SId, Account: account}, MainType: "user", SubType: "login", } b, err := app.buildReq(rqLogin) if err != nil { logrus.Error(err) return } app.handler.SetReq(b, false) } param := lib.ParamMgr{ Caller: app.handler, Timeout: time.Duration(app.conf.Pressure.TimeoutMs) * time.Millisecond, Lps: uint32(app.conf.Pressure.Concurrency), Duration: time.Duration(app.conf.Pressure.DurationS) * time.Second, ResultCh: make(chan *lib.CallResult, 50), } a, err := lib.NewAssistant(obs, param) if err != nil { logrus.Error(err) } a.Start() a.ShowResult() } createTestBtn := widget.NewButton("创角", func() { closeApp3(perfWin.tabs, common.TOOLBAR_PERF_CHOOSE) openApp3(perfWin.tabs, common.TOOLBAR_PERF_RES) for _, account := range app.binduids { rq := ReqParams{ Sid: app.conf.SId, Account: account, PbReq: &pb.UserCreateReq{NickName: account}, MainType: "user", SubType: "create", } b, err := app.buildReq(rq) if err != nil { logrus.Error(err) return } app.handler.SetReq(b, false) } param := lib.ParamMgr{ Caller: app.handler, Timeout: time.Duration(app.conf.Pressure.TimeoutMs) * time.Millisecond, Lps: uint32(app.conf.Pressure.Concurrency), Duration: time.Duration(app.conf.Pressure.DurationS) * time.Second, ResultCh: make(chan *lib.CallResult, 50), } a, err := lib.NewAssistant(obs, param) if err != nil { logrus.Error(err) } a.Start() a.ShowResult() }) //场景 scenBtn := widget.NewButton("其它场景", nil) scenBtn.OnTapped = func() { // defer openApp3(perfWin.tabs, common.TOOLBAR_PERF_PB) // closeApp3(perfWin.tabs, common.TOOLBAR_PERF_CHOOSE) closeApp3(perfWin.tabs, common.TOOLBAR_PERF_CHOOSE) openApp3(perfWin.tabs, common.TOOLBAR_PERF_RES) if tables, err := cfg.NewTables(common.Loader); err != nil { println(err.Error()) } else { for _, v := range tables.TestFlow.GetDataList() { p, ok := pbMap[v.Route] if !ok { logrus.WithField("route", v.Route).Debug("未注册") continue } routeStr := strings.SplitN(v.Route, ".", 2) for _, account := range app.binduids { rq := ReqParams{ Sid: app.conf.SId, Account: account, PbReq: p, MainType: routeStr[0], SubType: routeStr[1], } b, err := app.buildReq(rq) if err != nil { logrus.Error(err) return } app.handler.SetReq(b, true) } param := lib.ParamMgr{ Caller: app.handler, Timeout: time.Duration(app.conf.Pressure.TimeoutMs) * time.Millisecond, Lps: uint32(app.conf.Pressure.Concurrency), Duration: time.Duration(app.conf.Pressure.DurationS) * time.Second, ResultCh: make(chan *lib.CallResult, 50), } a, err := lib.NewAssistant(obs, param) if err != nil { logrus.Error(err) } a.Start() a.ShowResult() } } } //上一步 preBtn := widget.NewButtonWithIcon("上一步", theme.NavigateBackIcon(), nil) preBtn.OnTapped = func() { defer openApp3(perfWin.tabs, common.TOOLBAR_PERF_CONF) closeApp3(perfWin.tabs, common.TOOLBAR_PERF_CHOOSE) } btns := container.NewVBox(loginTestBtn, createTestBtn, scenBtn) c := container.NewBorder(nil, container.NewHBox(layout.NewSpacer(), preBtn), nil, nil, btns) content.Objects = append(content.Objects, c) app.tabItem.Content = content return nil } func (a *perfChoose) GetAppName() string { return common.TOOLBAR_PERF_CHOOSE } func (a *perfChoose) OnClose() bool { return false } func (a *perfChoose) OnDestroy() bool { return true } type ReqParams struct { Sid string Account string PbReq proto.Message MainType string SubType string } func (a *perfChoose) buildReq(rp ReqParams) ([]byte, error) { head := &pb.UserMessage{MainType: rp.MainType, SubType: rp.SubType} head.Sec = common.BuildSecStr(rp.Sid, rp.Account) if comm.ProtoMarshal(rp.PbReq, head) { data, err := proto.Marshal(head) if err != nil { return nil, err } return data, nil } return nil, nil }