mirror of
https://github.com/openziti/zrok.git
synced 2025-06-21 02:07:44 +02:00
support iterations (#40)
This commit is contained in:
parent
5330f60fa1
commit
4dde90a447
@ -25,8 +25,9 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type run struct {
|
type run struct {
|
||||||
cmd *cobra.Command
|
cmd *cobra.Command
|
||||||
loopers int
|
loopers int
|
||||||
|
iterations int
|
||||||
}
|
}
|
||||||
|
|
||||||
func newRun() *run {
|
func newRun() *run {
|
||||||
@ -38,13 +39,14 @@ func newRun() *run {
|
|||||||
r := &run{cmd: cmd}
|
r := &run{cmd: cmd}
|
||||||
cmd.Run = r.run
|
cmd.Run = r.run
|
||||||
cmd.Flags().IntVarP(&r.loopers, "loopers", "l", 1, "Number of current loopers to start")
|
cmd.Flags().IntVarP(&r.loopers, "loopers", "l", 1, "Number of current loopers to start")
|
||||||
|
cmd.Flags().IntVarP(&r.iterations, "iterations", "i", 1, "Number of iterations per looper")
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *run) run(_ *cobra.Command, _ []string) {
|
func (r *run) run(_ *cobra.Command, _ []string) {
|
||||||
var loopers []*looper
|
var loopers []*looper
|
||||||
for i := 0; i < r.loopers; i++ {
|
for i := 0; i < r.loopers; i++ {
|
||||||
l := newLooper(i)
|
l := newLooper(i, r.iterations)
|
||||||
loopers = append(loopers, l)
|
loopers = append(loopers, l)
|
||||||
go l.run()
|
go l.run()
|
||||||
}
|
}
|
||||||
@ -54,15 +56,17 @@ func (r *run) run(_ *cobra.Command, _ []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type looper struct {
|
type looper struct {
|
||||||
id int
|
id int
|
||||||
done chan struct{}
|
iterations int
|
||||||
listener edge.Listener
|
done chan struct{}
|
||||||
|
listener edge.Listener
|
||||||
}
|
}
|
||||||
|
|
||||||
func newLooper(id int) *looper {
|
func newLooper(id, iterations int) *looper {
|
||||||
return &looper{
|
return &looper{
|
||||||
id: id,
|
id: id,
|
||||||
done: make(chan struct{}),
|
iterations: iterations,
|
||||||
|
done: make(chan struct{}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,8 +104,11 @@ func (l *looper) run() {
|
|||||||
|
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
|
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < l.iterations; i++ {
|
||||||
outpayload := make([]byte, 64)
|
if i > 0 && i%10 == 0 {
|
||||||
|
logrus.Infof("looper #%d: iteration #%d", l.id, i)
|
||||||
|
}
|
||||||
|
outpayload := make([]byte, 10240)
|
||||||
outbase64 := base64.StdEncoding.EncodeToString(outpayload)
|
outbase64 := base64.StdEncoding.EncodeToString(outpayload)
|
||||||
rand.Read(outpayload)
|
rand.Read(outpayload)
|
||||||
if req, err := http.NewRequest("POST", tunnelResp.Payload.ProxyEndpoint, bytes.NewBufferString(outbase64)); err == nil {
|
if req, err := http.NewRequest("POST", tunnelResp.Payload.ProxyEndpoint, bytes.NewBufferString(outbase64)); err == nil {
|
||||||
@ -113,7 +120,7 @@ func (l *looper) run() {
|
|||||||
if inbase64 != outbase64 {
|
if inbase64 != outbase64 {
|
||||||
logrus.Errorf("payload mismatch!")
|
logrus.Errorf("payload mismatch!")
|
||||||
} else {
|
} else {
|
||||||
logrus.Infof("payload match")
|
logrus.Debugf("payload match")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logrus.Errorf("error: %v", err)
|
logrus.Errorf("error: %v", err)
|
||||||
@ -122,6 +129,7 @@ func (l *looper) run() {
|
|||||||
logrus.Errorf("error creating request: %v", err)
|
logrus.Errorf("error creating request: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
logrus.Infof("looper #%d: complete", l.id)
|
||||||
|
|
||||||
if l.listener != nil {
|
if l.listener != nil {
|
||||||
if err := l.listener.Close(); err != nil {
|
if err := l.listener.Close(); err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user