Skip to content

Commit

Permalink
Randomize Galley ports for integration testing (istio#11285)
Browse files Browse the repository at this point in the history
* Randomize Galley port for code-coverage runs.

* Remove runaway empty test.
  • Loading branch information
ozevren authored and louiscryan committed Feb 14, 2019
1 parent 06545b6 commit c5f2b44
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
1 change: 0 additions & 1 deletion codecov.skip
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ istio.io/istio/tests/codecov
istio.io/istio/tests/e2e
istio.io/istio/tests/integration2/examples
istio.io/istio/tests/integration2/qualification
istio.io/istio/tests/integration2
istio.io/istio/tests/integration_old
istio.io/istio/tests/local
istio.io/istio/tests/util
Expand Down
9 changes: 9 additions & 0 deletions galley/pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,14 @@ func (s *Server) Run() {
}
}

// Address returns the Address of the MCP service.
func (s *Server) Address() net.Addr {
if s.listener == nil {
return nil
}
return s.listener.Addr()
}

// Close cleans up resources used by the server.
func (s *Server) Close() error {
if s.stopCh != nil {
Expand All @@ -273,6 +281,7 @@ func (s *Server) Close() error {

if s.listener != nil {
_ = s.listener.Close()
s.listener = nil
}

if s.reporter != nil {
Expand Down
12 changes: 12 additions & 0 deletions galley/pkg/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ func TestServer_Basic(t *testing.T) {
t.Fatalf("Unexpected error creating service: %v", err)
}

// ensure that it does not crash
addr := s.Address()
if addr == nil {
t.Fatalf("expected address not found")
}

var wg sync.WaitGroup
wg.Add(1)

Expand All @@ -157,4 +163,10 @@ func TestServer_Basic(t *testing.T) {

wg.Wait()
_ = s.Close()

// ensure that it does not crash
addr = s.Address()
if addr != nil {
t.Fatalf("unexpected address found")
}
}
14 changes: 9 additions & 5 deletions pkg/test/framework/runtime/components/galley/native.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,22 @@ package galley

import (
"fmt"
"io"
"io/ioutil"
"os"
"path"

"io"
"time"

multierror "github.com/hashicorp/go-multierror"

"istio.io/istio/galley/pkg/server"
"istio.io/istio/pkg/test/scopes"

"istio.io/istio/pkg/test/framework/api/component"
"istio.io/istio/pkg/test/framework/api/components"
"istio.io/istio/pkg/test/framework/api/context"
"istio.io/istio/pkg/test/framework/api/descriptors"
"istio.io/istio/pkg/test/framework/api/lifecycle"
"istio.io/istio/pkg/test/framework/runtime/api"
"istio.io/istio/pkg/test/scopes"
)

var (
Expand Down Expand Up @@ -176,7 +174,13 @@ func (c *nativeComponent) restart() error {
a.DisableResourceReadyCheck = true
a.ConfigPath = c.configDir
a.MeshConfigFile = c.meshConfigFile
// To prevent ctrlZ port collision between galley/pilot&mixer
a.IntrospectionOptions.Port = 0
a.ExcludedResourceKinds = make([]string, 0)

// Bind to an arbitrary port.
a.APIAddress = "tcp://0.0.0.0:0"

s, err := server.New(a)
if err != nil {
scopes.Framework.Errorf("Error starting Galley: %v", err)
Expand All @@ -188,7 +192,7 @@ func (c *nativeComponent) restart() error {
go s.Run()

c.client = &client{
address: a.APIAddress,
address: fmt.Sprintf("tcp://%s", s.Address().String()),
ctx: c.ctx,
}

Expand Down

0 comments on commit c5f2b44

Please sign in to comment.