Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Changes rest and client tests to use ":0" for port and not specify a …
Browse files Browse the repository at this point in the history
…specific port.

Should fix #517
  • Loading branch information
lynxbat authored and jcooklin committed Nov 24, 2015
1 parent 2c79589 commit 7a471fa
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 40 deletions.
6 changes: 2 additions & 4 deletions mgmt/rest/client/client_config_func_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ limitations under the License.
package client

import (
"fmt"
"testing"

. "github.com/smartystreets/goconvey/convey"
Expand All @@ -30,10 +29,9 @@ import (
)

func TestPulseClientConfig(t *testing.T) {
port := getPort()
startAPI(port)
uri := startAPI()
CompressUpload = false
c := New(fmt.Sprintf("http://localhost:%d", port), "v1", true)
c := New(uri, "v1", true)
Convey("When no config is set", t, func() {
Convey("Get global config", func() {
res := c.GetPluginConfig("", "", "")
Expand Down
27 changes: 10 additions & 17 deletions mgmt/rest/client/client_func_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,6 @@ var (
NextPort = 45000
)

func getPort() int {
defer incrPort()
return NextPort
}

func incrPort() {
NextPort += 10
}

func getWMFromSample(sample string) *wmap.WorkflowMap {
jsonP, err := ioutil.ReadFile("../wmap_sample/" + sample)
if err != nil {
Expand All @@ -75,7 +66,7 @@ func getWMFromSample(sample string) *wmap.WorkflowMap {

// REST API instances that are started are killed when the tests end.
// When we eventually have a REST API Stop command this can be killed.
func startAPI(port int) string {
func startAPI() string {
// Start a REST API to talk to
rest.StreamingBufferWindow = 0.01
log.SetLevel(LOG_LEVEL)
Expand All @@ -88,15 +79,19 @@ func startAPI(port int) string {
r.BindConfigManager(c.Config)
r.BindMetricManager(c)
r.BindTaskManager(s)
r.Start(":" + fmt.Sprint(port))
err := r.Start("127.0.0.1:0")
if err != nil {
// Panic on an error
panic(err)
}
time.Sleep(100 * time.Millisecond)
return fmt.Sprintf("http://localhost:%d", port)
return fmt.Sprintf("http://localhost:%d", r.Port())
}

func TestPulseClient(t *testing.T) {
CompressUpload = false
port := getPort()
uri := startAPI(port)

uri := startAPI()
c := New(uri, "v1", true)
wf := getWMFromSample("1.json")
sch := &Schedule{Type: "simple", Interval: "1s"}
Expand Down Expand Up @@ -481,9 +476,7 @@ func TestPulseClient(t *testing.T) {
})
})

port = -1
uri = startAPI(port)
c = New(uri, "v1", true)
c = New("http://localhost:127.0.0.1:-1", "v1", true)

Convey("API with invalid port", t, func() {
p1 := c.LoadPlugin(MOCK_PLUGIN_PATH1)
Expand Down
32 changes: 13 additions & 19 deletions mgmt/rest/rest_func_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ var (
MOCK_PLUGIN_PATH2 = PULSE_PATH + "/plugin/pulse-collector-mock2"
FILE_PLUGIN_PATH = PULSE_PATH + "/plugin/pulse-publisher-file"

NextPort = 40000
CompressedUpload = true
TotalUploadSize = 0
UploadCount = 0
Expand All @@ -69,15 +68,6 @@ type restAPIInstance struct {
server *Server
}

func getPort() int {
defer incrPort()
return NextPort
}

func incrPort() {
NextPort += 10
}

func command() string {
return "curl"
}
Expand Down Expand Up @@ -436,7 +426,7 @@ func deletePluginConfigItem(port int, typ string, name, ver string, fields []str

// REST API instances that are started are killed when the tests end.
// When we eventually have a REST API Stop command this can be killed.
func startAPI(port int, opts ...interface{}) *restAPIInstance {
func startAPI(opts ...interface{}) *restAPIInstance {
// Start a REST API to talk to
log.SetLevel(LOG_LEVEL)
r, _ := New(false, "", "")
Expand All @@ -455,10 +445,14 @@ func startAPI(port int, opts ...interface{}) *restAPIInstance {
r.BindMetricManager(c)
r.BindTaskManager(s)
r.BindConfigManager(c.Config)
r.Start(":" + fmt.Sprint(port))
err := r.Start("127.0.0.1:0")
if err != nil {
// Panic on an error
panic(err)
}
time.Sleep(time.Millisecond * 100)
return &restAPIInstance{
port: port,
port: r.Port(),
server: r,
}
}
Expand All @@ -470,8 +464,8 @@ func TestPluginRestCalls(t *testing.T) {
Convey("a single plugin loads", func() {
// This test alone tests gzip. Saves on test time.
CompressedUpload = true
port := getPort()
startAPI(port)
r := startAPI()
port := r.port
col := core.CollectorPluginType
pub := core.PublisherPluginType
Convey("A global plugin config is added for all plugins", func() {
Expand Down Expand Up @@ -543,12 +537,12 @@ func TestPluginRestCalls(t *testing.T) {

})
Convey("Plugin config is set at startup", func() {
port := getPort()
cfg := control.NewConfig()
b, err := ioutil.ReadFile("../../examples/configs/pulse-config-sample.json")
So(err, ShouldBeNil)
json.Unmarshal(b, cfg)
startAPI(port, control.OptSetConfig(cfg))
r := startAPI(control.OptSetConfig(cfg))
port := r.port
col := core.CollectorPluginType

Convey("Gets the collector config by name and version", func() {
Expand Down Expand Up @@ -587,8 +581,8 @@ func TestPluginRestCalls(t *testing.T) {

Convey("Enable task - put - /v1/tasks/:id/enable", func() {
Convey("Enable a running task", func(c C) {
port := getPort()
startAPI(port)
r := startAPI()
port := r.port

uploadPlugin(MOCK_PLUGIN_PATH2, port)
uploadPlugin(FILE_PLUGIN_PATH, port)
Expand Down

0 comments on commit 7a471fa

Please sign in to comment.