Skip to content

Commit

Permalink
Parallelize tests (PR #178)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattayes authored May 26, 2022
1 parent e6365ec commit 3cd38c9
Show file tree
Hide file tree
Showing 30 changed files with 1,148 additions and 583 deletions.
42 changes: 15 additions & 27 deletions bench/clientserver_roundtrip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,45 @@ package bench

import (
"context"
"log"
"os"
"testing"
"time"

"github.com/lytics/grid/v3"
)

// go test -run=^BenchmarkClientServerRoundTrip -bench=. -benchmem
// go test -run=^BenchmarkClientServerRoundTrip -bench=. -benchmem -memprofile /tmp/memprofile.out -cpuprofile /tmp/cpuprofile.out

func BenchmarkClientServerRoundTripSmallMsg(b *testing.B) {
logger := log.New(os.Stderr, "rountrip-bench :: ", log.LstdFlags|log.Lshortfile)

wg.Wait()

_, client := runPingPongGrid(b)
b.ResetTimer()
benchRunner(b, logger, requestSmallMsg)
b.StopTimer()
benchRunner(b, client, requestSmallMsg)
}

func BenchmarkClientServerRoundTripBigStrMsg(b *testing.B) {
logger := log.New(os.Stderr, "rountrip-bench :: ", log.LstdFlags|log.Lshortfile)

wg.Wait()

_, client := runPingPongGrid(b)
b.ResetTimer()
benchRunner(b, logger, requestBigStrMsg)
b.StopTimer()
benchRunner(b, client, requestBigStrMsg)
}

func BenchmarkClientServerRoundTripBigMapBigStrMsg(b *testing.B) {
logger := log.New(os.Stderr, "rountrip-bench :: ", log.LstdFlags|log.Lshortfile)

wg.Wait()

_, client := runPingPongGrid(b)
b.ResetTimer()
benchRunner(b, logger, requestBigMapBigStrMsg)
b.StopTimer()
benchRunner(b, client, requestBigMapBigStrMsg)
}

func benchRunner(b *testing.B, logger *log.Logger, evtMsg *Event) {
ctx := context.Background()
func benchRunner(b *testing.B, client *grid.Client, evtMsg *Event) {
for n := 0; n < b.N; n++ {
timeoutC, cancel := context.WithTimeout(ctx, 10*time.Second)
response, err := client.RequestC(timeoutC, mailboxName, evtMsg)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
response, err := client.RequestC(ctx, mailboxName, evtMsg)
cancel()
successOrDie(logger, err)
if err != nil {
b.Fatal(err)
}
switch response.(type) {
case *EventResponse:
default:
logger.Printf("ERROR: wrong type %#v :: %T", response, response)
break
b.Fatalf("ERROR: wrong type %#v :: %T", response, response)
}
}
}
Loading

0 comments on commit 3cd38c9

Please sign in to comment.