igor-dv commented on code in PR #41744:
URL: https://github.com/apache/beam/pull/41744#discussion_r4730526085


##########
sdks/go/pkg/beam/runners/universal/runnerlib/execute_test.go:
##########
@@ -0,0 +1,144 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package runnerlib
+
+import (
+       "context"
+       "net"
+       "testing"
+       "time"
+
+       "github.com/apache/beam/sdks/v2/go/pkg/beam/core/runtime/graphx"
+       pipepb "github.com/apache/beam/sdks/v2/go/pkg/beam/model/pipeline_v1"
+       "google.golang.org/grpc"
+       "google.golang.org/grpc/connectivity"
+       "google.golang.org/grpc/credentials/insecure"
+)
+
+func TestDialEndpoint_defaultCloses(t *testing.T) {
+       lis, err := net.Listen("tcp", "127.0.0.1:0")
+       if err != nil {
+               t.Fatal(err)
+       }
+       gs := grpc.NewServer()
+       go gs.Serve(lis)
+       t.Cleanup(func() {
+               gs.Stop()
+               lis.Close()
+       })
+
+       cc, closeFn, err := dialEndpoint(context.Background(), 
lis.Addr().String(), time.Second, nil)
+       if err != nil {
+               t.Fatal(err)
+       }
+       closeFn()
+       if cc.GetState() != connectivity.Shutdown {
+               t.Fatalf("default Dial left the connection in state %v", 
cc.GetState())
+       }
+}
+
+func TestDialEndpoint_customDoesNotClose(t *testing.T) {
+       lis, err := net.Listen("tcp", "127.0.0.1:0")
+       if err != nil {
+               t.Fatal(err)
+       }
+       gs := grpc.NewServer()
+       go gs.Serve(lis)
+       t.Cleanup(func() {
+               gs.Stop()
+               lis.Close()
+       })
+
+       want, err := grpc.Dial(lis.Addr().String(), 
grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock())
+       if err != nil {
+               t.Fatal(err)
+       }
+       t.Cleanup(func() { want.Close() })
+
+       var n int
+       cc, closeFn, err := dialEndpoint(context.Background(), 
lis.Addr().String(), time.Second, func(ctx context.Context, endpoint string, 
timeout time.Duration) (*grpc.ClientConn, error) {
+               n++
+               return want, nil
+       })
+       if err != nil {
+               t.Fatal(err)
+       }
+       if n != 1 {
+               t.Fatalf("Dial called %d times, want 1", n)
+       }
+       if cc != want {
+               t.Fatal("dialEndpoint did not return the Dial connection")
+       }
+       closeFn()
+       if want.GetState() == connectivity.Shutdown {
+               t.Fatal("closeFn closed a connection Dial returned")
+       }
+}
+
+func TestExecute_customDialNotClosed(t *testing.T) {
+       lis, err := net.Listen("tcp", "127.0.0.1:0")
+       if err != nil {
+               t.Fatal(err)
+       }
+       gs := grpc.NewServer()
+       go gs.Serve(lis)
+       t.Cleanup(func() {
+               gs.Stop()
+               lis.Close()
+       })
+
+       cc, err := grpc.Dial(lis.Addr().String(), 
grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock())
+       if err != nil {
+               t.Fatal(err)
+       }
+       t.Cleanup(func() { cc.Close() })
+
+       p := &pipepb.Pipeline{
+               Components: &pipepb.Components{
+                       Environments: map[string]*pipepb.Environment{
+                               "go": {
+                                       Dependencies: 
[]*pipepb.ArtifactInformation{{
+                                               RoleUrn: 
graphx.URNArtifactGoWorkerRole,
+                                       }},
+                               },
+                       },
+               },
+       }
+       var n int
+       _, _ = Execute(context.Background(), p, lis.Addr().String(), 
&JobOptions{
+               Loopback: true,
+               Dial: func(ctx context.Context, endpoint string, timeout 
time.Duration) (*grpc.ClientConn, error) {
+                       n++
+                       return cc, nil
+               },
+       }, true)
+       if n == 0 {

Review Comment:
   test added



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to