Skip to content

Commit c5f2b44

Browse files
ozevrenlouiscryan
authored and
louiscryan
committed
Randomize Galley ports for integration testing (istio#11285)
* Randomize Galley port for code-coverage runs. * Remove runaway empty test.
1 parent 06545b6 commit c5f2b44

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

codecov.skip

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ istio.io/istio/tests/codecov
1515
istio.io/istio/tests/e2e
1616
istio.io/istio/tests/integration2/examples
1717
istio.io/istio/tests/integration2/qualification
18-
istio.io/istio/tests/integration2
1918
istio.io/istio/tests/integration_old
2019
istio.io/istio/tests/local
2120
istio.io/istio/tests/util

galley/pkg/server/server.go

+9
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,14 @@ func (s *Server) Run() {
252252
}
253253
}
254254

255+
// Address returns the Address of the MCP service.
256+
func (s *Server) Address() net.Addr {
257+
if s.listener == nil {
258+
return nil
259+
}
260+
return s.listener.Addr()
261+
}
262+
255263
// Close cleans up resources used by the server.
256264
func (s *Server) Close() error {
257265
if s.stopCh != nil {
@@ -273,6 +281,7 @@ func (s *Server) Close() error {
273281

274282
if s.listener != nil {
275283
_ = s.listener.Close()
284+
s.listener = nil
276285
}
277286

278287
if s.reporter != nil {

galley/pkg/server/server_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ func TestServer_Basic(t *testing.T) {
147147
t.Fatalf("Unexpected error creating service: %v", err)
148148
}
149149

150+
// ensure that it does not crash
151+
addr := s.Address()
152+
if addr == nil {
153+
t.Fatalf("expected address not found")
154+
}
155+
150156
var wg sync.WaitGroup
151157
wg.Add(1)
152158

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

158164
wg.Wait()
159165
_ = s.Close()
166+
167+
// ensure that it does not crash
168+
addr = s.Address()
169+
if addr != nil {
170+
t.Fatalf("unexpected address found")
171+
}
160172
}

pkg/test/framework/runtime/components/galley/native.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,22 @@ package galley
1616

1717
import (
1818
"fmt"
19+
"io"
1920
"io/ioutil"
2021
"os"
2122
"path"
22-
23-
"io"
2423
"time"
2524

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

2827
"istio.io/istio/galley/pkg/server"
29-
"istio.io/istio/pkg/test/scopes"
30-
3128
"istio.io/istio/pkg/test/framework/api/component"
3229
"istio.io/istio/pkg/test/framework/api/components"
3330
"istio.io/istio/pkg/test/framework/api/context"
3431
"istio.io/istio/pkg/test/framework/api/descriptors"
3532
"istio.io/istio/pkg/test/framework/api/lifecycle"
3633
"istio.io/istio/pkg/test/framework/runtime/api"
34+
"istio.io/istio/pkg/test/scopes"
3735
)
3836

3937
var (
@@ -176,7 +174,13 @@ func (c *nativeComponent) restart() error {
176174
a.DisableResourceReadyCheck = true
177175
a.ConfigPath = c.configDir
178176
a.MeshConfigFile = c.meshConfigFile
177+
// To prevent ctrlZ port collision between galley/pilot&mixer
178+
a.IntrospectionOptions.Port = 0
179179
a.ExcludedResourceKinds = make([]string, 0)
180+
181+
// Bind to an arbitrary port.
182+
a.APIAddress = "tcp://0.0.0.0:0"
183+
180184
s, err := server.New(a)
181185
if err != nil {
182186
scopes.Framework.Errorf("Error starting Galley: %v", err)
@@ -188,7 +192,7 @@ func (c *nativeComponent) restart() error {
188192
go s.Run()
189193

190194
c.client = &client{
191-
address: a.APIAddress,
195+
address: fmt.Sprintf("tcp://%s", s.Address().String()),
192196
ctx: c.ctx,
193197
}
194198

0 commit comments

Comments
 (0)