Skip to content

Commit

Permalink
Fix bug and update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
justin-jiajia committed May 28, 2023
1 parent 4f5bdf9 commit 6b02bf2
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 8 deletions.
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,43 @@ Send a lot of requests to test a website's stress resistance

- You use this program means you agree to all the terms.

- If you don't agree to these terms, you MUST stop using this program AT ONCE.
- If you don't agree to these terms, you MUST stop using this program AT ONCE.

### Install

You can download from Github Release or build by yourself:

```shell
# Linux
# If you don't have golang, run this. (Ubuntu)
# apt install golang
go build main.go
mv main easystress
# You can also move 'easystress' to a directory in PATH
```

```powershell
# Windows
# If you don't have golang, download from golang.google.cn
go build main.go
mv main.exe easystress.exe
# You can also move 'easystress.exe' to a directory in PATH
```

### Use

```shell
easystress -t 100 -w 5 -f t.csv https://example.com
```

This command will open 5 workers to send 100 requests to https://example.com and record to `t.csv`.

```
GLOBAL OPTIONS:
--licence, -l Show the licence (default: false)
--time value, -t value The time of sending requests
--worker value, -w value The amount of workers to send requests (default: 4)
--file value, -f value The name of the csv file which contains every request's time and error (default: none)
--help, -h show help
--version, -v print the version
```
21 changes: 14 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,23 @@ func start(this_id int) {
_, err := http.Get(website)
// resp, err := http.Get(website)
time_spend := time.Since(time_start).Abs().Milliseconds()
write_mu.Lock()
if err != nil {
csvwriter.Write([]string{fmt.Sprintf("%f", time.Since(time_startrun).Seconds()), "error", fmt.Sprintf("%d", time_spend)})
if use_file {
write_mu.Lock()
if err != nil {
csvwriter.Write([]string{fmt.Sprintf("%f", time.Since(time_startrun).Seconds()), "error", fmt.Sprintf("%d", time_spend)})
} else {
csvwriter.Write([]string{fmt.Sprintf("%f", time.Since(time_startrun).Seconds()), "success", fmt.Sprintf("%d", time_spend)})
}
write_mu.Unlock()
}
if err != nil {
time_err++
print_mu.Lock()
fmt.Print("\033[33mError: \033[0m")
fmt.Println(err)
print_mu.Unlock()
// defer resp.Body.Close()
} else {
csvwriter.Write([]string{fmt.Sprintf("%f", time.Since(time_startrun).Seconds()), "success", fmt.Sprintf("%d", time_spend)})
write_mu.Unlock()
time_ok++
last_time = int(time_spend)
time_used += int(time_spend)
Expand All @@ -76,7 +80,7 @@ func main() {
app := &cli.App{
Name: "EasyStress",
Usage: "Send a lot of requests to test a website's stress resistance",
Version: "v1.1",
Version: "v1.2",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "licence",
Expand Down Expand Up @@ -118,6 +122,10 @@ To use this program, you must agree these terms:
if time_amount == 0 {
return cli.Exit("Required flag \"t\" not set", -1)
}
website = ctx.Args().Get(0)
if website[:8] != "https://" && website[:7] != "http://" {
return cli.Exit("Website should start with 'http://' or 'https://'.", -1)
}
use_file = ctx.String("file") != ""
if use_file {
file_name = ctx.String("file")
Expand All @@ -143,7 +151,6 @@ To use this program, you must agree these terms:
csvwriter = csv.NewWriter(file)
csvwriter.Write([]string{"FinishTime(s)", "Status", "TimeCost(ms)"})
}
website = ctx.Args().Get(0)
worker_amount := ctx.Int("worker")
if worker_amount > time_amount {
fmt.Println("\033[33mWarning:\033[0m workers more than requests")
Expand Down

0 comments on commit 6b02bf2

Please sign in to comment.