You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2022/03/04 15:33:27 UTC

[GitHub] [beam] jrmccluskey commented on a change in pull request #17014: [BEAM-13909] improve coverage of Provision package

jrmccluskey commented on a change in pull request #17014:
URL: https://github.com/apache/beam/pull/17014#discussion_r819671180



##########
File path: sdks/go/pkg/beam/provision/provision_test.go
##########
@@ -52,3 +58,37 @@ func TestConversions(t *testing.T) {
 		}
 	}
 }
+
+type ProvisionServiceServicer struct {
+	fnpb.UnimplementedProvisionServiceServer
+}
+
+func (p ProvisionServiceServicer) GetProvisionInfo(ctx context.Context, req *fnpb.GetProvisionInfoRequest) (*fnpb.GetProvisionInfoResponse, error) {
+	return &fnpb.GetProvisionInfoResponse{Info: &fnpb.ProvisionInfo{RetrievalToken: "token"}}, nil
+}
+
+func setup(addr string, prs *ProvisionServiceServicer) {
+	l, err := net.Listen("tcp", addr)
+	if err != nil {
+		log.Fatalf("failed to listen on addr: %v", err)
+	}
+	server := grpc.NewServer()
+	defer server.Stop()
+	fnpb.RegisterProvisionServiceServer(server, prs)
+	if err := server.Serve(l); err != nil {
+		log.Fatalf("cannot serve the server: %v", err)
+	}
+}
+
+func TestProvisionInfo(t *testing.T) {
+	prs := &ProvisionServiceServicer{}
+	go setup(":9000", prs)

Review comment:
       Hard coding the address is not ideal since the outcome of the test is now dependent on localhost:9000 being available. You can instead [poll for an open port using net.Listen() like in the expansion service start-up code](https://github.com/apache/beam/blob/2aa4da02bc49be72b45e8327c5233c0e4938e59d/sdks/go/pkg/beam/core/runtime/xlangx/expansionx/process.go#L37)




-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org