From 3d60c530a74d8e1bf46a32fb754bf13076d15d4f Mon Sep 17 00:00:00 2001 From: Androlo <andreas@erisindustries.com> Date: Fri, 19 Jun 2015 00:15:26 +0200 Subject: [PATCH] Minor fix to test ports. Long overdue --- erisdb/erisdbss/http.go | 8 +++++--- erisdb/erisdbss/server_manager.go | 6 ++---- server/config.go | 2 +- server/server.go | 8 ++++---- server/websocket.go | 2 +- test/mock/mock_web_api_test.go | 8 ++------ test/server/http_burst_test.go | 2 +- test/server/scumbag.go | 4 ++-- test/server/ws_burst_test.go | 2 +- test/web_api/query_test.go | 17 +++++++++-------- test/web_api/shared.go | 1 - test/web_api/web_api_test.go | 16 ++++++++-------- 12 files changed, 36 insertions(+), 40 deletions(-) diff --git a/erisdb/erisdbss/http.go b/erisdb/erisdbss/http.go index b1878657..13573da2 100644 --- a/erisdb/erisdbss/http.go +++ b/erisdb/erisdbss/http.go @@ -36,12 +36,14 @@ type RequestData struct { MaxDuration uint `json:"max_duration"` } -// The response is the URL to the newly generated server. +// The response is the port of the newly generated server. The assumption +// here is that the host name or ip is the same, and the default server +// settings apply. // TODO return some "live" data after starting the node, so that // the requester can validate that everything is fine. Maybe // some data directly from the state manager. Genesis hash? type ResponseData struct { - URL string `json:"URL"` + Port string `json:"port"` } // Serves requests to fire up erisdb executables. POSTing to the server @@ -104,7 +106,7 @@ func (this *ServerServer) handleFunc(c *gin.Context) { http.Error(c.Writer, "Internal error: "+errA.Error(), 500) return } - log.Debug("Work done.", "URL", resp.URL) + log.Debug("Work done.", "PORT", resp.Port) w := c.Writer enc := json.NewEncoder(w) enc.Encode(resp) diff --git a/erisdb/erisdbss/server_manager.go b/erisdb/erisdbss/server_manager.go index f8b0344f..b3a617b5 100644 --- a/erisdb/erisdbss/server_manager.go +++ b/erisdb/erisdbss/server_manager.go @@ -183,14 +183,12 @@ func (this *ServerManager) add(data *RequestData) (*ResponseData, error) { } st := newServeTask(port, workDir, maxDur, proc) - this.running = append(this.running, st) - - URL := fmt.Sprintf("http://%s:%d", config.Bind.Address, port) + this.running = append(this.running, st) // TODO add validation data. The node should ideally return some post-deploy state data // and send it back with the server URL, so that the validity of the chain can be // established client-side before starting the tests. - return &ResponseData{URL: URL}, nil + return &ResponseData{fmt.Sprintf("%d",port)}, nil } // Add a new erisdb process to the list. diff --git a/server/config.go b/server/config.go index 0fa49d6a..9d979f06 100644 --- a/server/config.go +++ b/server/config.go @@ -59,7 +59,7 @@ func DefaultServerConfig() *ServerConfig { kp := "" return &ServerConfig{ Bind: Bind{ - Address: "0.0.0.0", + Address: "", Port: 1337, }, TLS: TLS{TLS: false, diff --git a/server/server.go b/server/server.go index 95ad7790..d2532cd3 100644 --- a/server/server.go +++ b/server/server.go @@ -54,12 +54,12 @@ func (this *ServeProcess) Start() error { InitLogger(config) - if config.CORS.Enable { + // if config.CORS.Enable { ch := NewCORSMiddleware(config.CORS) router.Use(gin.Recovery(), logHandler, ch) - } else { - router.Use(gin.Recovery(), logHandler) - } + //} else { + // router.Use(gin.Recovery(), logHandler) + //} address := config.Bind.Address port := config.Bind.Port diff --git a/server/websocket.go b/server/websocket.go index 732b45aa..2481fb57 100644 --- a/server/websocket.go +++ b/server/websocket.go @@ -70,7 +70,7 @@ func (this *WebSocketServer) Start(config *ServerConfig, router *gin.Engine) { // TODO Will this be enough for massive "get blockchain" requests? WriteBufferSize: 1024, } - this.upgrader.CheckOrigin = nil + this.upgrader.CheckOrigin = func(r *http.Request) bool {return true} router.GET(config.WebSocket.WebSocketEndpoint, this.handleFunc) this.running = true diff --git a/test/mock/mock_web_api_test.go b/test/mock/mock_web_api_test.go index 7e07c745..456d6283 100644 --- a/test/mock/mock_web_api_test.go +++ b/test/mock/mock_web_api_test.go @@ -18,7 +18,6 @@ import ( "testing" "os" "runtime" - "time" ) func init() { @@ -49,7 +48,7 @@ func (this *MockSuite) SetupSuite() { // The server restServer := edb.NewRestServer(codec, pipe, evtSubs) sConf := server.DefaultServerConfig() - sConf.Bind.Port = 31473 + sConf.Bind.Port = 31402 // Create a server process. proc := server.NewServeProcess(sConf, restServer) err := proc.Start() @@ -59,16 +58,13 @@ func (this *MockSuite) SetupSuite() { this.serveProcess = proc this.codec = edb.NewTCodec() this.testData = testData - this.sUrl = "http://localhost:31473" + this.sUrl = "http://localhost:31402" } func (this *MockSuite) TearDownSuite() { sec := this.serveProcess.StopEventChannel() this.serveProcess.Stop(0) <-sec - // Tests are done rapidly, this is just to give that extra milliseconds - // to shut down the previous server (may be excessive). - time.Sleep(500*time.Millisecond) } // ********************************************* Consensus ********************************************* diff --git a/test/server/http_burst_test.go b/test/server/http_burst_test.go index f74bbb2c..2ac5dbcc 100644 --- a/test/server/http_burst_test.go +++ b/test/server/http_burst_test.go @@ -32,7 +32,7 @@ func TestHttpFlooding(t *testing.T) { func runHttp() error { c := 0 for c < HTTP_MESSAGES { - resp, errG := http.Get("http://localhost:31333/scumbag") + resp, errG := http.Get("http://localhost:31400/scumbag") if errG != nil { return errG } diff --git a/test/server/scumbag.go b/test/server/scumbag.go index bc438092..fb01e75d 100644 --- a/test/server/scumbag.go +++ b/test/server/scumbag.go @@ -57,13 +57,13 @@ func NewScumsocketServer(maxConnections uint) *server.WebSocketServer { func NewServeScumbag() *server.ServeProcess { cfg := server.DefaultServerConfig() - cfg.Bind.Port = uint16(31333) + cfg.Bind.Port = uint16(31400) return server.NewServeProcess(cfg, NewScumbagServer()) } func NewServeScumSocket(wsServer *server.WebSocketServer) *server.ServeProcess { cfg := server.DefaultServerConfig() cfg.WebSocket.WebSocketEndpoint = "/scumsocket" - cfg.Bind.Port = uint16(31337) + cfg.Bind.Port = uint16(31401) return server.NewServeProcess(cfg, wsServer) } diff --git a/test/server/ws_burst_test.go b/test/server/ws_burst_test.go index 67212437..e3922d98 100644 --- a/test/server/ws_burst_test.go +++ b/test/server/ws_burst_test.go @@ -89,7 +89,7 @@ func runWs() error { } func wsClient(doneChan chan bool, errChan chan error) { - client := client.NewWSClient("ws://localhost:31337/scumsocket") + client := client.NewWSClient("ws://localhost:31401/scumsocket") _, err := client.Dial() if err != nil { errChan <- err diff --git a/test/web_api/query_test.go b/test/web_api/query_test.go index d0f5f701..e6714d17 100644 --- a/test/web_api/query_test.go +++ b/test/web_api/query_test.go @@ -15,9 +15,10 @@ import ( "os" "path" "testing" - "time" ) +const QS_URL = "http://localhost:31403/server" + type QuerySuite struct { suite.Suite baseDir string @@ -30,7 +31,9 @@ type QuerySuite struct { func (this *QuerySuite) SetupSuite() { baseDir := path.Join(os.TempDir(), "/.edbservers") ss := ess.NewServerServer(baseDir) - proc := server.NewServeProcess(nil, ss) + cfg := server.DefaultServerConfig() + cfg.Bind.Port = uint16(31403) + proc := server.NewServeProcess(cfg, ss) err := proc.Start() if err != nil { panic(err) @@ -41,14 +44,15 @@ func (this *QuerySuite) SetupSuite() { requestData := &ess.RequestData{testData.ChainData.PrivValidator, testData.ChainData.Genesis, SERVER_DURATION} rBts, _ := this.codec.EncodeBytes(requestData) - resp, _ := http.Post(SS_URL, "application/json", bytes.NewBuffer(rBts)) + resp, _ := http.Post(QS_URL, "application/json", bytes.NewBuffer(rBts)) rd := &ess.ResponseData{} err2 := this.codec.Decode(rd, resp.Body) if err2 != nil { panic(err2) } - fmt.Println("Received URL: " + rd.URL) - this.sUrl = rd.URL + fmt.Println("Received Port: " + rd.Port) + this.sUrl = "http://localhost:" + rd.Port + fmt.Println("URL: " + this.sUrl) this.testData = testData } @@ -56,9 +60,6 @@ func (this *QuerySuite) TearDownSuite() { sec := this.serveProcess.StopEventChannel() this.serveProcess.Stop(0) <-sec - // Tests are done rapidly, this is just to give that extra milliseconds - // to shut down the previous server (may be excessive). - time.Sleep(500*time.Millisecond) } // ********************************************* Tests ********************************************* diff --git a/test/web_api/shared.go b/test/web_api/shared.go index 9c1ad6f3..46962a31 100644 --- a/test/web_api/shared.go +++ b/test/web_api/shared.go @@ -7,7 +7,6 @@ import ( "runtime" ) -const SS_URL = "http://localhost:1337/server" const SERVER_DURATION = 10 func init() { diff --git a/test/web_api/web_api_test.go b/test/web_api/web_api_test.go index c453fd77..bc765df0 100644 --- a/test/web_api/web_api_test.go +++ b/test/web_api/web_api_test.go @@ -18,9 +18,10 @@ import ( "os" "path" "testing" - "time" ) +const WAPIS_URL = "http://localhost:31404/server" + type WebApiSuite struct { suite.Suite baseDir string @@ -34,7 +35,9 @@ func (this *WebApiSuite) SetupSuite() { gin.SetMode(gin.ReleaseMode) baseDir := path.Join(os.TempDir(), "/.edbservers") ss := ess.NewServerServer(baseDir) - proc := server.NewServeProcess(nil, ss) + cfg := server.DefaultServerConfig() + cfg.Bind.Port = uint16(31404) + proc := server.NewServeProcess(cfg, ss) err := proc.Start() if err != nil { panic(err) @@ -45,14 +48,14 @@ func (this *WebApiSuite) SetupSuite() { requestData := &ess.RequestData{testData.ChainData.PrivValidator, testData.ChainData.Genesis, SERVER_DURATION} rBts, _ := this.codec.EncodeBytes(requestData) - resp, _ := http.Post(SS_URL, "application/json", bytes.NewBuffer(rBts)) + resp, _ := http.Post(WAPIS_URL, "application/json", bytes.NewBuffer(rBts)) rd := &ess.ResponseData{} err2 := this.codec.Decode(rd, resp.Body) if err2 != nil { panic(err2) } - fmt.Println("Received URL: " + rd.URL) - this.sUrl = rd.URL + fmt.Println("Received Port: " + rd.Port) + this.sUrl = "http://localhost:" + rd.Port this.testData = testData } @@ -60,9 +63,6 @@ func (this *WebApiSuite) TearDownSuite() { sec := this.serveProcess.StopEventChannel() this.serveProcess.Stop(0) <-sec - // Tests are done rapidly, this is just to give that extra milliseconds - // to shut down the previous server (may be excessive). - time.Sleep(500*time.Millisecond) } // ********************************************* Consensus ********************************************* -- GitLab