Merge pull request #21146 from hashicorp/jbardin/grpc-test-server

Stop grpc server when running ACC tests
This commit is contained in:
James Bardin 2019-04-29 14:33:44 -04:00 committed by GitHub
commit 30199600eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 7 deletions

View File

@ -37,7 +37,7 @@ func GRPCTestProvider(rp terraform.ResourceProvider) providers.Interface {
client, _ := pp.GRPCClient(context.Background(), nil, conn) client, _ := pp.GRPCClient(context.Background(), nil, conn)
grpcClient := client.(*tfplugin.GRPCProvider) grpcClient := client.(*tfplugin.GRPCProvider)
grpcClient.TestListener = listener grpcClient.TestServer = grpcServer
return grpcClient return grpcClient
} }

View File

@ -3,7 +3,6 @@ package plugin
import ( import (
"context" "context"
"errors" "errors"
"io"
"log" "log"
"sync" "sync"
@ -45,9 +44,9 @@ type GRPCProvider struct {
// This allows the GRPCProvider a way to shutdown the plugin process. // This allows the GRPCProvider a way to shutdown the plugin process.
PluginClient *plugin.Client PluginClient *plugin.Client
// TestListener contains a net.Conn to close when the GRPCProvider is being // TestServer contains a grpc.Server to close when the GRPCProvider is being
// used in an end to end test of a provider. // used in an end to end test of a provider.
TestListener io.Closer TestServer *grpc.Server
// Proto client use to make the grpc service calls. // Proto client use to make the grpc service calls.
client proto.ProviderClient client proto.ProviderClient
@ -544,9 +543,9 @@ func (p *GRPCProvider) ReadDataSource(r providers.ReadDataSourceRequest) (resp p
func (p *GRPCProvider) Close() error { func (p *GRPCProvider) Close() error {
log.Printf("[TRACE] GRPCProvider: Close") log.Printf("[TRACE] GRPCProvider: Close")
// close the remote listener if we're running within a test // Make sure to stop the server if we're not running within go-plugin.
if p.TestListener != nil { if p.TestServer != nil {
p.TestListener.Close() p.TestServer.Stop()
} }
// Check this since it's not automatically inserted during plugin creation. // Check this since it's not automatically inserted during plugin creation.