Skip to content

Commit

Permalink
trying out running against localhost for test
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelneale committed Jul 25, 2024
1 parent 3abdf43 commit b4acb43
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 34 deletions.
56 changes: 27 additions & 29 deletions impl/concurrencytest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

var (
iterationsPerServer = 1000
servers = []string{"diddht-a", "diddht-b"}
server = "http://localhost:8305"
)

func main() {
Expand All @@ -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()
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down
8 changes: 3 additions & 5 deletions impl/integrationtest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
21 changes: 21 additions & 0 deletions impl/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

0 comments on commit b4acb43

Please sign in to comment.