Skip to content

Commit 941a3aa

Browse files
author
Mikhail Podtserkovskiy
committed
benchmark fixes
1 parent dbe9e5e commit 941a3aa

File tree

7 files changed

+45
-27
lines changed

7 files changed

+45
-27
lines changed

config/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ type Grid struct {
1818
ClientType string `json:"client_type"`
1919
Port int `json:"port"`
2020
StrategyList []Strategy `json:"strategy_list"`
21-
BusyNodeDuration string `json:"busy_node_duration"` // duration string format ex. 12m, see time.ParseDuration()
21+
BusyNodeDuration string `json:"busy_node_duration"` // duration string format ex. 12m, see time.ParseDuration()
2222
// todo: выпилить и сделать равным дедлайну http запроса
23-
ReservedDuration string `json:"reserved_node_duration"` // duration string format ex. 12m, see time.ParseDuration()
23+
ReservedDuration string `json:"reserved_node_duration"` // duration string format ex. 12m, see time.ParseDuration()
2424
}
2525

2626
type Strategy struct {

handlers/createSession.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"encoding/json"
66
"errors"
7+
"fmt"
78
log "github.com/Sirupsen/logrus"
89
"github.com/qa-dev/jsonwire-grid/jsonwire"
910
"github.com/qa-dev/jsonwire-grid/pool"
@@ -13,7 +14,6 @@ import (
1314
"net/http"
1415
"net/http/httputil"
1516
"net/url"
16-
"fmt"
1717
)
1818

1919
type CreateSession struct {

jsonwire/jsonwire.go

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,28 @@ type Sessions struct {
2626
}
2727

2828
type Register struct {
29-
Class string `json:"class"`
30-
Configuration *Configuration `json:"configuration"`
31-
CapabilitiesList []Capabilities `json:"capabilities"` // selenium 3
29+
Class string `json:"class,omitempty"`
30+
Configuration *Configuration `json:"configuration,omitempty"`
31+
CapabilitiesList []Capabilities `json:"capabilities,omitempty"` // selenium 3
3232
}
3333

3434
type Capabilities map[string]interface{}
3535

3636
type Configuration struct {
37-
Proxy string
38-
Role string
39-
Hub string
40-
Port int
41-
RemoteHost string
42-
Host string
43-
MaxSession int
44-
HubHost string
45-
RegisterCycle int
46-
HubPort int
47-
URL string
48-
Register bool
49-
CapabilitiesList []Capabilities `json:"capabilities"` // selenium 2
37+
Id string `json:"id,omitempty"`
38+
Proxy string `json:"proxy,omitempty"`
39+
Role string `json:"role,omitempty"`
40+
Hub string `json:"hub,omitempty"`
41+
Port int `json:"port,omitempty"`
42+
RemoteHost string `json:"remoteHost,omitempty"`
43+
Host string `json:"host,omitempty"`
44+
MaxSession int `json:"maxSession,omitempty"`
45+
HubHost string `json:"hubHost,omitempty"`
46+
RegisterCycle int `json:"registerCycle,omitempty"`
47+
HubPort int `json:"hubPort,omitempty"`
48+
URL string `json:"url,omitempty"`
49+
Register bool `json:"register,omitempty"`
50+
CapabilitiesList []Capabilities `json:"capabilities,omitempty"` // selenium 2
5051
}
5152

5253
type APIProxy struct {

logger/logger.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package logger
33
import (
44
"github.com/Sirupsen/logrus"
55

6-
"github.com/qa-dev/jsonwire-grid/config"
76
"fmt"
7+
"github.com/qa-dev/jsonwire-grid/config"
88
)
99

1010
func Init(logger config.Logger) error {

proxy/transport.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func NewCreateSessionTransport(pool *pool.Pool, node *pool.Node) *CreateSessionT
2727

2828
func (t *CreateSessionTransport) RoundTrip(request *http.Request) (*http.Response, error) {
2929
var err error
30-
defer func() {t.Error = err}() // dirty hack, for get error from round trip
30+
defer func() { t.Error = err }() // dirty hack, for get error from round trip
3131
response, err := http.DefaultTransport.RoundTrip(request)
3232
if err != nil {
3333
return nil, errors.New("round trip to node: " + err.Error())

testing/webdriver-node-mock/handlers.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func createSession(rw http.ResponseWriter, r *http.Request) {
5151
time.Sleep(time.Millisecond * time.Duration(rand.Intn(maxDuration)))
5252
}
5353
rw.Header().Set("Accept", "application/json")
54+
rw.Header().Set("Content-type", "application/json; charset=utf-8")
5455
rw.Header().Set("Accept-charset", "utf-8")
5556

5657
if r.Method != http.MethodPost {
@@ -106,10 +107,21 @@ func useSession(rw http.ResponseWriter, r *http.Request) {
106107
responseMessage.Value = errorMassage
107108
case parsedUrl[2] == "" && r.Method == http.MethodDelete: // session closed by client
108109
currentSessionID = ""
110+
default:
111+
responseMessage.Value = RandStringRunes(10000)
109112
}
110-
111113
err := json.NewEncoder(rw).Encode(responseMessage)
112114
if err != nil {
113115
http.Error(rw, "Error encode response to json, rawMessage: "+fmt.Sprintf("%+v", responseMessage), http.StatusInternalServerError)
114116
}
115117
}
118+
119+
var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
120+
121+
func RandStringRunes(n int) string {
122+
b := make([]rune, n)
123+
for i := range b {
124+
b[i] = letterRunes[rand.Intn(len(letterRunes))]
125+
}
126+
return string(b)
127+
}

testing/webdriver-node-mock/webdriver-node-mock.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"time"
1717
)
1818

19-
var currentSessionID, host, hubUrl string
19+
var currentSessionID, host, hubUrl, id string
2020
var maxDuration, port int
2121

2222
func main() {
@@ -38,6 +38,7 @@ func main() {
3838
log.Infof("port: %v", port)
3939
log.Infof("maxDuration: %v", maxDuration)
4040

41+
id = "http://" + host + ":" + strconv.Itoa(port)
4142
register()
4243

4344
go func() {
@@ -82,8 +83,11 @@ func getIpv4() (string, error) {
8283
func register() {
8384
log.Info("Try register")
8485
register := jsonwire.Register{
85-
Configuration: &jsonwire.Configuration{Host: host, Port: port},
86-
CapabilitiesList: []jsonwire.Capabilities{{"browserName": "firefox"}},
86+
Configuration: &jsonwire.Configuration{
87+
Id: id,
88+
Host: host,
89+
Port: port,
90+
CapabilitiesList: []jsonwire.Capabilities{{"browserName": "firefox"}}},
8791
}
8892
b, err := json.Marshal(register)
8993
if err != nil {
@@ -130,8 +134,8 @@ func register() {
130134

131135
// sendApiProxy check "is server know me" and register if server return false
132136
func sendApiProxy() error {
133-
b := strings.NewReader("{}")
134-
req, err := http.NewRequest(http.MethodPost, hubUrl+"/grid/api/proxy?id=http://"+host+":"+strconv.Itoa(port), b)
137+
b := strings.NewReader(`{id:"` + id + `"}`)
138+
req, err := http.NewRequest(http.MethodPost, hubUrl+"/grid/api/proxy?id="+id, b)
135139
if err != nil {
136140
return fmt.Errorf("create request error, %s", err)
137141
}
@@ -163,6 +167,7 @@ func sendApiProxy() error {
163167
}
164168
if !respStruct.Success {
165169
log.Info("Node not registered on hub")
170+
log.Info(string(respBytes))
166171
register()
167172
}
168173
return nil

0 commit comments

Comments
 (0)