-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
58 lines (49 loc) · 1.04 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"context"
"fmt"
"os"
"time"
"github.com/ryo-yamaoka/otchkiss"
"github.com/ryo-yamaoka/otchkiss/setting"
)
type SampleRequester struct{}
func (sr *SampleRequester) Init() error {
return nil
}
func (sr *SampleRequester) RequestOne(_ context.Context) error {
time.Sleep(10 * time.Millisecond) // Substitute for HTTP request
return nil
}
func (sr *SampleRequester) Terminate() error {
return nil
}
func main() {
if err := run(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
os.Exit(0)
}
func run() error {
st := &setting.Setting{
RunDuration: 3 * time.Second,
WarmUpTime: 2 * time.Second,
MaxConcurrent: 2,
MaxRPS: 2,
}
ot, err := otchkiss.FromConfig(&SampleRequester{}, st, 1_000_000)
if err != nil {
return fmt.Errorf("init error: %w", err)
}
ctx := context.Background()
if err := ot.Start(ctx); err != nil {
return fmt.Errorf("start error: %w", err)
}
rep, err := ot.Report()
if err != nil {
return fmt.Errorf("report error: %w", err)
}
fmt.Println(rep)
return nil
}