Skip to content

Commit

Permalink
Add profiling for failed transport test
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkren committed Jun 17, 2019
1 parent 379a82c commit 0d37f4f
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions pkg/dmsg/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
"math"
"math/rand"
"net"
"os"
"runtime"
"runtime/pprof"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -541,14 +544,38 @@ func TestServer_Serve(t *testing.T) {
})

t.Run("test failed accept not hanging already established transport", func(t *testing.T) {
f, err := os.Create("./cpu.prof")
if err != nil {
log.Fatalf("Error creating cpu profile: %v\n", err)
}

if err := pprof.StartCPUProfile(f); err != nil {
log.Fatalf("Error starting cpu profiling: %v\n", err)
}

defer pprof.StopCPUProfile()

blockF, err := os.Create("./block.prof")
if err != nil {
log.Fatalf("Error creating block profile: %v\n", err)
}

runtime.SetBlockProfileRate(1)
p := pprof.Lookup("block")
defer func() {
if err := p.WriteTo(blockF, 0); err != nil {
log.Fatalf("Error saving block profile: %v\n", err)
}
}()

// generate keys for both clients
aPK, aSK := cipher.GenerateKeyPair()
bPK, bSK := cipher.GenerateKeyPair()

// create remote
a := NewClient(aPK, aSK, dc)
a.SetLogger(logging.MustGetLogger("A"))
err := a.InitiateServerConnections(context.Background(), 1)
err = a.InitiateServerConnections(context.Background(), 1)
require.NoError(t, err)

// create initiator
Expand Down Expand Up @@ -586,12 +613,13 @@ func TestServer_Serve(t *testing.T) {
tpReadWriteWG.Done()
return
default:
var msg []byte
//var msg []byte
msg := make([]byte, 13)
if _, aErr = aTransport.Read(msg); aErr != nil {
tpReadWriteWG.Done()
return
}
log.Printf("GOT MESSAGE %s", string(msg))
//log.Printf("GOT MESSAGE %s", string(msg))
}
}
}()
Expand All @@ -606,10 +634,13 @@ func TestServer_Serve(t *testing.T) {
return
default:
msg := []byte("Hello there!")
log.Println("BEFORE TRANSPORT WRITE")
if _, bErr = bTransport.Write(msg); bErr != nil {
log.Println("ERROR IN TRANSPORT WRITE")
tpReadWriteWG.Done()
return
}
log.Println("AFTER TRANSPORT WRITE")
}
}
}()
Expand Down

0 comments on commit 0d37f4f

Please sign in to comment.