Skip to content

Commit

Permalink
local test daemon for grpc server test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
srprash committed Aug 11, 2022
1 parent 0f2ea34 commit 5b2a364
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions xray/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,19 +254,6 @@ func TestGrpcUnaryClientInterceptor(t *testing.T) {
}

func TestUnaryServerInterceptor(t *testing.T) {
ctx, td := NewTestDaemon()
defer td.Close()

lis := newGrpcServer(
t,
grpc.UnaryInterceptor(
UnaryServerInterceptor(
WithRecorder(GetRecorder(ctx)),
WithSegmentNamer(NewFixedSegmentNamer("test")))),
)
client, closeFunc := newGrpcClient(context.Background(), t, lis)
defer closeFunc()

testCases := []testCase{
{
name: "success response",
Expand Down Expand Up @@ -300,6 +287,24 @@ func TestUnaryServerInterceptor(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {

// Ideally we shouldn't be creating a local test daemon for each test case.
// However, how the shared channel in the test daemon doesn't guarantee
// segment isolation across test cases. Therefore, for now a local test daemon
// is a workaround.
ctx, td := NewTestDaemon()
defer td.Close()

lis := newGrpcServer(
t,
grpc.UnaryInterceptor(
UnaryServerInterceptor(
WithRecorder(GetRecorder(ctx)),
WithSegmentNamer(NewFixedSegmentNamer("test")))),
)
client, closeFunc := newGrpcClient(context.Background(), t, lis)
defer closeFunc()

var respHeaders metadata.MD
if tc.isTestForSuccessResponse() {
_, err := client.Ping(
Expand Down

0 comments on commit 5b2a364

Please sign in to comment.