Skip to content

Commit f17e6a7

Browse files
authored
Merge pull request #7 from qa-dev/readme
readme and small fixes
2 parents 5fc9033 + 1d25a05 commit f17e6a7

File tree

10 files changed

+163
-29
lines changed

10 files changed

+163
-29
lines changed

README.md

Lines changed: 115 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,119 @@
11
# ~~jsonwire-grid~~WebDriverGrid [![Build Status](https://travis-ci.org/qa-dev/jsonwire-grid.svg?branch=master)](https://travis-ci.org/qa-dev/jsonwire-grid)
2-
This is scalable Golang implementation of Selenium Grid (hub).
2+
This is high-performance scalable implementation of Selenium Grid (hub),
3+
###### What is Selenium-Grid?
4+
>Selenium-Grid allows you run your tests on different machines against different browsers in parallel. That is, running multiple tests at the same time against different machines running different browsers and operating systems. Essentially, Selenium-Grid support distributed test execution. It allows for running your tests in a distributed test execution environment.
5+
6+
## Features
7+
* One session per one node, no more no less😺
8+
* Scaling grid-instances for fault-tolerance
9+
* Support and effective management over 9000 nodes, for parallel testing👹
10+
* Single entry point for all your test apps
11+
* Send metrics to [statsd](https://github.com/etsy/statsd)
12+
* Support on-demand nodes in Kubernetes cluster (Only if grid running in cluster)
13+
314

415
## HowTo
5-
1. Install MySql
6-
1. Set in config.json your db connesction string `[username[:password]@][protocol[(address)]]/dbname[?param1=value1&...&paramN=valueN]`
7-
1. Run app
8-
#### Run binary file
9-
1. download binary file and
10-
1. `export CONFIG_PATH=./config.json`
11-
1. `./jsonwire-grid`
12-
13-
### Run From Source
14-
#### Requirements
15-
* Go >= 1.8.1
16-
* [go-bindata](https://github.com/jteeuwen/go-bindata)
17-
1. `git clone https://github.com/qa-dev/jsonwire-grid .`
18-
1. `cd jsonwire-grid`
19-
1. `cp config-sample.json config.json`
20-
1. `make run`
21-
22-
## HowToUse
23-
1. Run app
16+
### Run grid
17+
1. [Download last release](https://github.com/qa-dev/jsonwire-grid/releases) and unzip
18+
1. cd to `jsonwire-grid_vXXX`
19+
1. Type `export CONFIG_PATH=./config-local-sample.json`
20+
1. Type `./jsonwire-grid`
21+
1. Grid running!
22+
23+
### Run nodes
24+
1. [Download selenium](http://www.seleniumhq.org/download/)
2425
1. `java -jar selenium-server-standalone-3.4.0.jar -role node -hub http://127.0.0.1:4444/grid/register`
25-
1. try create session `curl -X POST http://127.0.0.1:4444/wd/hub/session -d '{"desiredCapabilities":{"browserName": "firefox"}}'`
26+
1. Repeat!
27+
28+
### Run test
29+
1. Try create session, such as `curl -X POST http://127.0.0.1:4444/wd/hub/session -d '{"desiredCapabilities":{"browserName": "firefox"}}'`
30+
1. If you see something similar with `{"state":null,"sessionId":"515be56a...` all right! If not, submit [issue](https://github.com/qa-dev/jsonwire-grid/issues/new)
31+
32+
33+
## Configuration
34+
Configurations are stored in json files. Example:
35+
```
36+
{
37+
"logger": {
38+
"level": "debug"
39+
},
40+
"db": {
41+
"implementation": "local"
42+
},
43+
"grid": {
44+
"client_type": "selenium",
45+
"port": 4444,
46+
"strategy_list": [
47+
{
48+
"type": "persistent"
49+
}
50+
],
51+
"busy_node_duration": "15m",
52+
"reserved_node_duration": "5m"
53+
}
54+
}
55+
```
56+
57+
### Logger - Configuration of logger.
58+
| Option | Possible values | Description |
59+
| ------------- | ----------------------------------- | ---------------------- |
60+
| logger.level | `debug`, `info`, `warning`, `error` | Logging level. |
61+
62+
### DB - Configuration of storage.
63+
| Option | Possible values | Description |
64+
| ----------------- | --------------- | ------------------------------------------ |
65+
| db.implementation | `mysql`, `local` | Select your favorite db, or local storage. |
66+
| db.connection | see next table | DSN for your db. |
67+
68+
>Note: Note: Local (in-memory) storage does not support common session storage between grid-instances.
69+
70+
| DB implementation | DSN format |
71+
| ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
72+
| mysql | [spec](https://github.com/go-sql-driver/mysql#dsn-data-source-name), example `db_user:db_pass@(db_host:3306)/db_name?parseTime=true` (parseTime=true - required option) |
73+
| local | omit this property, because every instance have its own in-memory storage |
74+
75+
### Statsd - Configuration of metrics.
76+
| Option | Possible values | Description |
77+
| --------------- | --------------- | ---------------------- |
78+
| statsd.host | `string` | Host of statsd server. |
79+
| statsd.port | `int` | Port of statsd server. |
80+
| statsd.protocol | `string` | Network protocol. |
81+
| statsd.prefix | `string` | Prefix of metrics tag. |
82+
| statsd.enable | `bool` | Enable metric. |
83+
84+
### Grid - Configuration of app.
85+
| Option | Possible values | Description |
86+
| --------------------------- | ------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
87+
| grid.client_type | `selenium`, `wda` | Type of used nodes. |
88+
| grid.port | `int` | Grid will run on this port. |
89+
| grid.busy_node_duration | `string` as `12m`, `60s` | Max session lifetime, when timeout was elapsed grid will kill the session. |
90+
| grid.reserved_node_duration | `string` as `12m`, `60s` | Max timeout between send request `POST /session` and opening the browser window. (Deprecated will renamed) |
91+
| grid.strategy_list | `array` | List of strategies, if grid not able create session on first strategy it go to next, until list ends. [Read more about strategies.](#element-of-strategy-list) |
92+
93+
> * `selenium` - [http://www.seleniumhq.org/]()
94+
> * `wda` - [agent](https://github.com/qa-dev/WebDriverAgent) for [WDA](https://github.com/qa-dev/WebDriverAgent)
95+
96+
### Element of strategy list
97+
| Option | Possible values | Description |
98+
| ------------------------------ | --------------------------------------------------------------- | ---------------------------------------------------------------------------- |
99+
| type | `string`, see [type of strategy.](#types-of-strategy) | Host of statsd server. |
100+
| limit | `int`, unlimited if equals `0` | Max count of active nodes on this strategy. |
101+
| params | `object`, dependent on [strategy type](#types-of-strategy) | Object describes available nodes, ex. docker config, kubernetes config, etc. |
102+
| node_list | `array`, dependent on [strategy type](#types-of-strategy) | Array of objects describing available nodes. |
103+
| node_list.[].params | `object`, dependent on [strategy type](#types-of-strategy) | Object of describing node, ex. image_name, etc. |
104+
| node_list.[].capabilities_list | `array`, ex. [{"foo: "bar"}, {"foo: "baz", "ololo": "trololo"}] | array of objects describes available capabilities . |
105+
106+
### Types of strategy
107+
##### `persistent` - using externally started nodes, same as original selenium grid.
108+
| Strategy option | Possible values | Description |
109+
|---------------- | --------------- | ---------------------------------------------------- |
110+
| limit | - | Omit this property, сount of nodes always unlimited. |
111+
| params | - | Omit this property. |
112+
| node_list | - | Omit this property. |
113+
114+
##### `kubernetes` - on-demand nodes in kubernetes cluster.
115+
| Strategy option | Possible values | Description |
116+
|-------------------------- | --------------- | --------------------------- |
117+
| params | - | Omit this property. |
118+
| node_list.[].params.image | - | Docker image with selenium. |
119+
| node_list.[].params.port | - | Port of selenium. |

config-local-sample.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"logger": {
3+
"level": "debug"
4+
},
5+
"db": {
6+
"implementation": "local"
7+
},
8+
"grid": {
9+
"client_type": "selenium",
10+
"port": 4444,
11+
"strategy_list": [
12+
{
13+
"type": "persistent"
14+
}
15+
],
16+
"busy_node_duration": "15m",
17+
"reserved_node_duration": "5m"
18+
}
19+
}

config-sample.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"logger": {
3-
"level": 6
3+
"level": "debug"
44
},
55
"db": {
66
"implementation": "mysql",

config-test.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"logger": {
3-
"level": 3
3+
"level": "warning"
44
},
55
"db": {
66
"implementation": "mysql",

config/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package config
33
import (
44
"encoding/json"
55
"errors"
6-
"github.com/Sirupsen/logrus"
76
log "github.com/Sirupsen/logrus"
87
"os"
98
)
@@ -20,6 +19,7 @@ type Grid struct {
2019
Port int `json:"port"`
2120
StrategyList []Strategy `json:"strategy_list"`
2221
BusyNodeDuration string `json:"busy_node_duration"` // duration string format ex. 12m, see time.ParseDuration()
22+
// todo: выпилить и сделать равным дедлайну http запроса
2323
ReservedDuration string `json:"reserved_node_duration"` // duration string format ex. 12m, see time.ParseDuration()
2424
}
2525

@@ -36,7 +36,7 @@ type Node struct {
3636
}
3737

3838
type Logger struct {
39-
Level logrus.Level `json:"level"`
39+
Level string `json:"level"`
4040
}
4141

4242
type DB struct {

goreleaser.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@ build:
44
- darwin
55
- linux
66
hooks:
7-
pre: make prepare
7+
pre: make prepare
8+
archive:
9+
files:
10+
- config-local-sample.json
11+
- README.md

logger/logger.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@ import (
44
"github.com/Sirupsen/logrus"
55

66
"github.com/qa-dev/jsonwire-grid/config"
7+
"fmt"
78
)
89

9-
func Init(logger config.Logger) {
10-
logrus.SetLevel(logger.Level)
10+
func Init(logger config.Logger) error {
11+
level, err := logrus.ParseLevel(logger.Level)
12+
if err != nil {
13+
return fmt.Errorf("Parse log level, %v", err)
14+
}
15+
logrus.Infof("Set log level to: %v", level)
16+
logrus.SetLevel(level)
17+
return nil
1118
}

main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ func main() {
2727
if err != nil {
2828
log.Fatalf("Problem in loading config from file, %s", err)
2929
}
30-
logger.Init(cfg.Logger)
30+
err = logger.Init(cfg.Logger)
31+
if err != nil {
32+
log.Fatalf("Problem in init logger, %s", err)
33+
}
3134

3235
statsdClient, err := metrics.NewStatsd(
3336
cfg.Statsd.Host,

pool/pool.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
)
1111

1212
const (
13+
// todo: сейчас не используются, совсем удалить или сделать дефолтные параметры для конфига.
1314
defaultBusyNodeDuration = time.Minute * 30
1415
defaultReservedNodeDuration = time.Minute * 5
1516
)

storage/mysql/factory.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ func (f *Factory) Create(config config.Config) (pool.StorageInterface, error) {
2121
return nil, err
2222
}
2323

24+
err = db.Ping()
25+
if err != nil {
26+
err = errors.New("Database connection not establish: " + err.Error())
27+
return nil, err
28+
}
29+
2430
db.SetMaxIdleConns(0) // this is the root problem! set it to 0 to remove all idle connections
2531
db.SetMaxOpenConns(10) // or whatever is appropriate for your setup.
2632

0 commit comments

Comments
 (0)