Skip to content

Commit

Permalink
return err on .Start() and expose a function to retrieve url via .URL()
Browse files Browse the repository at this point in the history
  • Loading branch information
geigerj0 committed Jun 14, 2024
1 parent 3fdc401 commit 16f04ba
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,12 @@ var _ = Describe("MetricPoller", func() {
},
},
}, nil)
mockLogCacheEndpoint := mockLogCache.Start(3000 + GinkgoParallelProcess())
err = mockLogCache.Start(3000 + GinkgoParallelProcess())
Expect(err).ToNot(HaveOccurred())

metricClient = NewMetricClientFactory().GetMetricClient(logger, &config.Config{
MetricCollector: config.MetricCollectorConfig{
MetricCollectorURL: mockLogCacheEndpoint,
MetricCollectorURL: mockLogCache.URL(),
TLSClientCerts: models.TLSCerts{
KeyFile: filepath.Join(testCertDir, "log-cache.key"),
CertFile: filepath.Join(testCertDir, "log-cache.crt"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,16 @@ var (
metricType = "a-metric-type"
metricUnit = "a-metric-unit"

regPath = regexp.MustCompile(`^/v1/apps/.*/scale$`)
configFile *os.File
conf config.Config
egPort int
healthport int
httpClient *http.Client
healthHttpClient *http.Client
mockLogCache *testhelpers.MockLogCache
mockLogCacheEndpoint string
mockScalingEngine *ghttp.Server
breachDurationSecs = 10
regPath = regexp.MustCompile(`^/v1/apps/.*/scale$`)
configFile *os.File
conf config.Config
egPort int
healthport int
httpClient *http.Client
healthHttpClient *http.Client
mockLogCache *testhelpers.MockLogCache
mockScalingEngine *ghttp.Server
breachDurationSecs = 10

scalingResult = &models.AppScalingResult{
AppId: testAppId,
Expand Down Expand Up @@ -225,7 +224,8 @@ func initHttpEndPoints() {
},
},
}, nil)
mockLogCacheEndpoint = mockLogCache.Start(10000 + GinkgoParallelProcess())
err = mockLogCache.Start(10000 + GinkgoParallelProcess())
Expect(err).ToNot(HaveOccurred())

mockScalingEngine = ghttp.NewUnstartedServer()
mockScalingEngine.HTTPTestServer.TLS = testhelpers.ServerTlsConfig("scalingengine")
Expand Down Expand Up @@ -293,7 +293,7 @@ func initConfig() {
},
},
MetricCollector: config.MetricCollectorConfig{
MetricCollectorURL: mockLogCacheEndpoint,
MetricCollectorURL: mockLogCache.URL(),
TLSClientCerts: models.TLSCerts{
KeyFile: filepath.Join(testCertDir, "eventgenerator.key"),
CertFile: filepath.Join(testCertDir, "eventgenerator.crt"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var _ = Describe("Integration_Eventgenerator_Scalingengine", func() {
})

JustBeforeEach(func() {
eventGeneratorConfPath = components.PrepareEventGeneratorConfig(dbUrl, components.Ports[EventGenerator], fmt.Sprintf("127.0.0.1:%d", mockLogCachePort), fmt.Sprintf("https://127.0.0.1:%d", components.Ports[ScalingEngine]), aggregatorExecuteInterval, policyPollerInterval, saveInterval, evaluationManagerInterval, defaultHttpClientTimeout, tmpDir)
eventGeneratorConfPath = components.PrepareEventGeneratorConfig(dbUrl, components.Ports[EventGenerator], mockLogCache.URL(), fmt.Sprintf("https://127.0.0.1:%d", components.Ports[ScalingEngine]), aggregatorExecuteInterval, policyPollerInterval, saveInterval, evaluationManagerInterval, defaultHttpClientTimeout, tmpDir)
scalingEngineConfPath = components.PrepareScalingEngineConfig(dbUrl, components.Ports[ScalingEngine], fakeCCNOAAUAA.URL(), defaultHttpClientTimeout, tmpDir)

startEventGenerator()
Expand Down
4 changes: 2 additions & 2 deletions src/autoscaler/integration/integration_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ var (
testUserScope = []string{"cloud_controller.read", "cloud_controller.write", "password.write", "openid", "network.admin", "network.write", "uaa.user"}
processMap = map[string]ifrit.Process{}
mockLogCache = &MockLogCache{}
mockLogCachePort = 20000 + GinkgoParallelProcess()

defaultHttpClientTimeout = 10 * time.Second

Expand Down Expand Up @@ -202,7 +201,8 @@ func startMockLogCache() {
Expect(err).ToNot(HaveOccurred())

mockLogCache = NewMockLogCache(tlsConfig)
mockLogCache.Start(mockLogCachePort)
err = mockLogCache.Start(20000 + GinkgoParallelProcess())
Expect(err).ToNot(HaveOccurred())
}

func stopGolangApiServer() {
Expand Down
9 changes: 6 additions & 3 deletions src/autoscaler/testhelpers/log_cache_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"crypto/x509"
"errors"
"fmt"
"log"
"net"
"os"
"strings"
Expand Down Expand Up @@ -49,11 +48,11 @@ func NewMockLogCache(tlsConfig *tls.Config) *MockLogCache {
}
}

func (m *MockLogCache) Start(port int) string {
func (m *MockLogCache) Start(port int) error {
var err error
m.lis, err = net.Listen("tcp", fmt.Sprintf("127.0.0.1:%d", port))
if err != nil {
log.Fatalf("failed to listen: %v", err)
return err
}

var srv *grpc.Server
Expand All @@ -69,6 +68,10 @@ func (m *MockLogCache) Start(port int) string {
//nolint:errcheck
go srv.Serve(m.lis)

return nil
}

func (m *MockLogCache) URL() string {
return m.lis.Addr().String()
}

Expand Down

0 comments on commit 16f04ba

Please sign in to comment.