From b4acb434d69c8d25d45a8a54a9974d3da629ff3b Mon Sep 17 00:00:00 2001 From: Mic Neale Date: Thu, 25 Jul 2024 18:49:29 +1000 Subject: [PATCH 1/2] trying out running against localhost for test --- impl/concurrencytest/main.go | 56 +++++++++++++++++------------------- impl/integrationtest/main.go | 8 ++---- impl/magefile.go | 21 ++++++++++++++ 3 files changed, 51 insertions(+), 34 deletions(-) diff --git a/impl/concurrencytest/main.go b/impl/concurrencytest/main.go index fd2f4f82..084db2b2 100644 --- a/impl/concurrencytest/main.go +++ b/impl/concurrencytest/main.go @@ -17,7 +17,7 @@ import ( var ( iterationsPerServer = 1000 - servers = []string{"diddht-a", "diddht-b"} + server = "http://localhost:8305" ) func main() { @@ -26,32 +26,30 @@ func main() { programStart := time.Now() var wg sync.WaitGroup - for _, server := range servers { - for i := 0; i < iterationsPerServer; i++ { - log := logrus.WithField("server", server).WithField("i", i) - - s := server - wg.Add(1) - go func() { - putStart := time.Now() - suffix, err := put(s) - if err != nil { - log = log.WithError(err) - } - log.WithField("time", time.Since(putStart)).Info("PUT request completed") - if err != nil { - return - } - - getStart := time.Now() - if err = get(s, suffix); err != nil { - log = log.WithError(err) - } - log.WithField("time", time.Since(getStart)).Info("GET request completed") - - wg.Done() - }() - } + for i := 0; i < iterationsPerServer; i++ { + log := logrus.WithField("server", server).WithField("i", i) + + s := server + wg.Add(1) + go func() { + putStart := time.Now() + suffix, err := put(s) + if err != nil { + log = log.WithError(err) + } + log.WithField("time", time.Since(putStart)).Info("PUT request completed") + if err != nil { + return + } + + getStart := time.Now() + if err = get(s, suffix); err != nil { + log = log.WithError(err) + } + log.WithField("time", time.Since(getStart)).Info("GET request completed") + + wg.Done() + }() } wg.Wait() @@ -70,7 +68,7 @@ func put(server string) (string, error) { return "", err } - req, err := http.NewRequest(http.MethodPut, "http://"+server+":8305/"+suffix, bytes.NewReader(reqData)) + req, err := http.NewRequest(http.MethodPut, server+"/"+suffix, bytes.NewReader(reqData)) if err != nil { return "", err } @@ -94,7 +92,7 @@ func put(server string) (string, error) { } func get(server, suffix string) error { - resp, err := http.Get("http://" + server + ":8305/" + suffix) + resp, err := http.Get(server + "/" + suffix) if err != nil { return err } diff --git a/impl/integrationtest/main.go b/impl/integrationtest/main.go index c842764d..fe632d91 100644 --- a/impl/integrationtest/main.go +++ b/impl/integrationtest/main.go @@ -21,13 +21,11 @@ var ( ticker = time.NewTicker(time.Second * 30) ) +const serverURL = "http://localhost:8305" + func main() { logrus.SetLevel(logrus.DebugLevel) - if len(os.Args) < 2 { - logrus.Fatal("must specify 1 argument (server URL)") - } - - run(os.Args[1]) + run(serverURL) } func run(server string) { diff --git a/impl/magefile.go b/impl/magefile.go index c7c4df40..648d592c 100644 --- a/impl/magefile.go +++ b/impl/magefile.go @@ -260,3 +260,24 @@ func Vuln() error { func installGoVulnIfNotPresent() error { return installIfNotPresent("govulncheck", "golang.org/x/vuln/cmd/govulncheck@latest") } + +// StartServer starts the local did-dht server. +func StartServer() error { + println("Starting local did-dht server...") + return sh.Run("../scripts/quickstart.sh", "-d", "-n", "did-dht-test-server", "-p", "8305:8305") +} + +// StopServer stops the local did-dht server. +func StopServer() error { + println("Stopping local did-dht server...") + return sh.Run("docker", "stop", "did-dht-test-server") +} + +// LocalTest runs the tests with a local server. +func LocalTest() error { + if err := StartServer(); err != nil { + return err + } + defer StopServer() + return Test() +} From 1db7b219e8732a708a8bc8368c32f9a69e780049 Mon Sep 17 00:00:00 2001 From: Mic Neale Date: Fri, 26 Jul 2024 18:27:02 +1000 Subject: [PATCH 2/2] use local dht container --- impl/concurrencytest/main.go | 52 +++++++++++++++++--------------- impl/internal/did/client_test.go | 4 +-- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/impl/concurrencytest/main.go b/impl/concurrencytest/main.go index 084db2b2..37386093 100644 --- a/impl/concurrencytest/main.go +++ b/impl/concurrencytest/main.go @@ -17,7 +17,7 @@ import ( var ( iterationsPerServer = 1000 - server = "http://localhost:8305" + servers = []string{"http://localhost:8305", "http://localhost:8305"} ) func main() { @@ -26,30 +26,32 @@ func main() { programStart := time.Now() var wg sync.WaitGroup - for i := 0; i < iterationsPerServer; i++ { - log := logrus.WithField("server", server).WithField("i", i) - - s := server - wg.Add(1) - go func() { - putStart := time.Now() - suffix, err := put(s) - if err != nil { - log = log.WithError(err) - } - log.WithField("time", time.Since(putStart)).Info("PUT request completed") - if err != nil { - return - } - - getStart := time.Now() - if err = get(s, suffix); err != nil { - log = log.WithError(err) - } - log.WithField("time", time.Since(getStart)).Info("GET request completed") - - wg.Done() - }() + for _, server := range servers { + for i := 0; i < iterationsPerServer; i++ { + log := logrus.WithField("server", server).WithField("i", i) + + s := server + wg.Add(1) + go func() { + putStart := time.Now() + suffix, err := put(s) + if err != nil { + log = log.WithError(err) + } + log.WithField("time", time.Since(putStart)).Info("PUT request completed") + if err != nil { + return + } + + getStart := time.Now() + if err = get(s, suffix); err != nil { + log = log.WithError(err) + } + log.WithField("time", time.Since(getStart)).Info("GET request completed") + + wg.Done() + }() + } } wg.Wait() diff --git a/impl/internal/did/client_test.go b/impl/internal/did/client_test.go index 5080d976..57c301b8 100644 --- a/impl/internal/did/client_test.go +++ b/impl/internal/did/client_test.go @@ -12,7 +12,7 @@ import ( ) func TestClient(t *testing.T) { - client, err := NewGatewayClient("https://diddht.tbddev.org") + client, err := NewGatewayClient("http://localhost:8305") require.NoError(t, err) require.NotNil(t, client) @@ -49,7 +49,7 @@ func TestClientInvalidGateway(t *testing.T) { } func TestInvalidDIDDocument(t *testing.T) { - client, err := NewGatewayClient("https://diddht.tbddev.test") + client, err := NewGatewayClient("http://localhost:8305") require.NoError(t, err) require.NotEmpty(t, client)