From 5330f60fa16b3de923db197324c4ce52ea3c92c5 Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Mon, 3 Oct 2022 16:34:24 -0400 Subject: [PATCH] parallel testing... (#40) --- cmd/zrokloop/loop.go | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/cmd/zrokloop/loop.go b/cmd/zrokloop/loop.go index fa4996a8..3642fc3b 100644 --- a/cmd/zrokloop/loop.go +++ b/cmd/zrokloop/loop.go @@ -1,6 +1,9 @@ package main import ( + "bytes" + "crypto/rand" + "encoding/base64" "fmt" httptransport "github.com/go-openapi/runtime/client" "github.com/openziti-test-kitchen/zrok/model" @@ -12,7 +15,7 @@ import ( "github.com/openziti/sdk-golang/ziti/edge" "github.com/sirupsen/logrus" "github.com/spf13/cobra" - "math/rand" + "io" "net/http" "time" ) @@ -94,7 +97,32 @@ func (l *looper) run() { logrus.Infof("service: %v, frontend: %v", tunnelResp.Payload.Service, tunnelResp.Payload.ProxyEndpoint) go l.serviceListener(zif, tunnelResp.Payload.Service) - time.Sleep(time.Duration(rand.Intn(10000)) * time.Millisecond) + + time.Sleep(1 * time.Second) + + for i := 0; i < 10; i++ { + outpayload := make([]byte, 64) + outbase64 := base64.StdEncoding.EncodeToString(outpayload) + rand.Read(outpayload) + if req, err := http.NewRequest("POST", tunnelResp.Payload.ProxyEndpoint, bytes.NewBufferString(outbase64)); err == nil { + client := &http.Client{Timeout: time.Second * 10} + if resp, err := client.Do(req); err == nil { + inpayload := new(bytes.Buffer) + io.Copy(inpayload, resp.Body) + inbase64 := inpayload.String() + if inbase64 != outbase64 { + logrus.Errorf("payload mismatch!") + } else { + logrus.Infof("payload match") + } + } else { + logrus.Errorf("error: %v", err) + } + } else { + logrus.Errorf("error creating request: %v", err) + } + } + if l.listener != nil { if err := l.listener.Close(); err != nil { logrus.Errorf("error closing listener: %v", err) @@ -131,5 +159,7 @@ func (l *looper) serviceListener(zitiIdPath string, svcId string) { } func (l *looper) ServeHTTP(w http.ResponseWriter, r *http.Request) { - w.Write([]byte("ok")) + buf := new(bytes.Buffer) + io.Copy(buf, r.Body) + w.Write(buf.Bytes()) }