Skip to content

Commit

Permalink
made functional tests stable
Browse files Browse the repository at this point in the history
  • Loading branch information
ezsilmar committed Apr 17, 2019
1 parent d9b49ec commit 37b92ab
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion internal/helloworld/greeter_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package helloworld
import (
"fmt"
"io"
"math/rand"
"sync"
"time"

context "golang.org/x/net/context"
"google.golang.org/grpc/stats"
Expand Down Expand Up @@ -35,12 +37,19 @@ type Greeter struct {
callCounts map[CallType]int
}

func RandomSleep() {
msCount := rand.Intn(4) + 1
time.Sleep(time.Millisecond * time.Duration(msCount))
}

// SayHello implements helloworld.GreeterServer
func (s *Greeter) SayHello(ctx context.Context, in *HelloRequest) (*HelloReply, error) {
s.mutex.Lock()
s.callCounts[Unary]++
s.mutex.Unlock()

RandomSleep()

return &HelloReply{Message: "Hello " + in.Name}, nil
}

Expand All @@ -50,6 +59,8 @@ func (s *Greeter) SayHellos(req *HelloRequest, stream Greeter_SayHellosServer) e
s.callCounts[ServerStream]++
s.mutex.Unlock()

RandomSleep()

for _, msg := range s.streamData {
if err := stream.Send(msg); err != nil {
return err
Expand All @@ -65,6 +76,8 @@ func (s *Greeter) SayHelloCS(stream Greeter_SayHelloCSServer) error {
s.callCounts[ClientStream]++
s.mutex.Unlock()

RandomSleep()

msgCount := 0

for {
Expand All @@ -86,6 +99,8 @@ func (s *Greeter) SayHelloBidi(stream Greeter_SayHelloBidiServer) error {
s.callCounts[Bidi]++
s.mutex.Unlock()

RandomSleep()

for {
in, err := stream.Recv()
if err == io.EOF {
Expand Down Expand Up @@ -197,4 +212,4 @@ func (c *HWStatsHandler) HandleRPC(ctx context.Context, rs stats.RPCStats) {
// TagRPC implements per-RPC context management.
func (c *HWStatsHandler) TagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context {
return ctx
}
}

0 comments on commit 37b92ab

Please sign in to comment.