From 34285d8cca93fc0f473636e78680fade03f26bda Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 16 Oct 2017 08:09:43 -0700 Subject: parallel tests (#7629) --- api/apitestlib.go | 12 +++++++++--- api/command_test.go | 5 +++-- api/file_test.go | 5 +---- api/post_test.go | 29 ++++++++++++++++++++--------- api/websocket_test.go | 5 +++-- 5 files changed, 36 insertions(+), 20 deletions(-) (limited to 'api') diff --git a/api/apitestlib.go b/api/apitestlib.go index 48637ee59..5b5bfff19 100644 --- a/api/apitestlib.go +++ b/api/apitestlib.go @@ -4,6 +4,7 @@ package api import ( + "fmt" "net" "time" @@ -69,6 +70,10 @@ func setupTestHelper(enterprise bool) *TestHelper { var options []app.Option if testStore != nil { options = append(options, app.StoreOverride(testStore)) + options = append(options, app.ConfigOverride(func(cfg *model.Config) { + cfg.ServiceSettings.ListenAddress = new(string) + *cfg.ServiceSettings.ListenAddress = ":0" + })) } th := &TestHelper{ @@ -153,8 +158,9 @@ func (me *TestHelper) InitSystemAdmin() *TestHelper { func (me *TestHelper) waitForConnectivity() { for i := 0; i < 1000; i++ { - _, err := net.Dial("tcp", "localhost"+*utils.Cfg.ServiceSettings.ListenAddress) + conn, err := net.Dial("tcp", fmt.Sprintf("localhost:%v", me.App.Srv.ListenAddr.Port)) if err == nil { + conn.Close() return } time.Sleep(time.Millisecond * 20) @@ -163,11 +169,11 @@ func (me *TestHelper) waitForConnectivity() { } func (me *TestHelper) CreateClient() *model.Client { - return model.NewClient("http://localhost" + *utils.Cfg.ServiceSettings.ListenAddress) + return model.NewClient(fmt.Sprintf("http://localhost:%v", me.App.Srv.ListenAddr.Port)) } func (me *TestHelper) CreateWebSocketClient() (*model.WebSocketClient, *model.AppError) { - return model.NewWebSocketClient("ws://localhost"+*utils.Cfg.ServiceSettings.ListenAddress, me.BasicClient.AuthToken) + return model.NewWebSocketClient(fmt.Sprintf("ws://localhost:%v", me.App.Srv.ListenAddr.Port), me.BasicClient.AuthToken) } func (me *TestHelper) CreateTeam(client *model.Client) *model.Team { diff --git a/api/command_test.go b/api/command_test.go index 9d146b189..948193852 100644 --- a/api/command_test.go +++ b/api/command_test.go @@ -4,6 +4,7 @@ package api import ( + "fmt" "strings" "testing" "time" @@ -257,7 +258,7 @@ func TestTestCommand(t *testing.T) { *utils.Cfg.ServiceSettings.AllowedUntrustedInternalConnections = "localhost" cmd1 := &model.Command{ - URL: "http://localhost" + *utils.Cfg.ServiceSettings.ListenAddress + model.API_URL_SUFFIX_V3 + "/teams/command_test", + URL: fmt.Sprintf("http://localhost:%v", th.App.Srv.ListenAddr.Port) + model.API_URL_SUFFIX_V3 + "/teams/command_test", Method: model.COMMAND_METHOD_POST, Trigger: "testcommand", } @@ -290,7 +291,7 @@ func TestTestCommand(t *testing.T) { } cmd2 := &model.Command{ - URL: "http://localhost" + *utils.Cfg.ServiceSettings.ListenAddress + model.API_URL_SUFFIX_V3 + "/teams/command_test", + URL: fmt.Sprintf("http://localhost:%v", th.App.Srv.ListenAddr.Port) + model.API_URL_SUFFIX_V3 + "/teams/command_test", Method: model.COMMAND_METHOD_GET, Trigger: "test2", } diff --git a/api/file_test.go b/api/file_test.go index 405e3e7d1..2935f0804 100644 --- a/api/file_test.go +++ b/api/file_test.go @@ -516,10 +516,7 @@ func TestGetPublicFileOld(t *testing.T) { store.Must(th.App.Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id)) // reconstruct old style of link - siteURL := *utils.Cfg.ServiceSettings.SiteURL - if siteURL == "" { - siteURL = "http://localhost" + *utils.Cfg.ServiceSettings.ListenAddress - } + siteURL := fmt.Sprintf("http://localhost:%v", th.App.Srv.ListenAddr.Port) link := generatePublicLinkOld(siteURL, th.BasicTeam.Id, channel.Id, th.BasicUser.Id, fileId+"/test.png") // Wait a bit for files to ready diff --git a/api/post_test.go b/api/post_test.go index f57c2e05c..e7c230963 100644 --- a/api/post_test.go +++ b/api/post_test.go @@ -1153,20 +1153,31 @@ func TestEmailMention(t *testing.T) { if !strings.ContainsAny(resultsMailbox[len(resultsMailbox)-1].To[0], th.BasicUser2.Email) { t.Fatal("Wrong To recipient") } else { - for i := 0; i < 5; i++ { - if resultsEmail, err := utils.GetMessageFromMailbox(th.BasicUser2.Email, resultsMailbox[len(resultsMailbox)-1].ID); err == nil { - if strings.Contains(resultsEmail.Body.Text, post1.Message) { - break - } else if i == 4 { - t.Log(resultsEmail.Body.Text) - t.Fatal("Received wrong Message") + for i := 0; i < 30; i++ { + for j := len(resultsMailbox) - 1; j >= 0; j-- { + isUser := false + for _, to := range resultsMailbox[j].To { + if to == "<"+th.BasicUser2.Email+">" { + isUser = true + } + } + if !isUser { + continue + } + if resultsEmail, err := utils.GetMessageFromMailbox(th.BasicUser2.Email, resultsMailbox[j].ID); err == nil { + if strings.Contains(resultsEmail.Body.Text, post1.Message) { + return + } else if i == 4 { + t.Log(resultsEmail.Body.Text) + t.Fatal("Received wrong Message") + } } - time.Sleep(100 * time.Millisecond) } + time.Sleep(100 * time.Millisecond) } + t.Fatal("Didn't receive message") } } - } func TestFuzzyPosts(t *testing.T) { diff --git a/api/websocket_test.go b/api/websocket_test.go index 161ea4960..42604124b 100644 --- a/api/websocket_test.go +++ b/api/websocket_test.go @@ -4,6 +4,7 @@ package api import ( + "fmt" //"encoding/json" //"net/http" "net/http" @@ -323,7 +324,7 @@ func TestWebsocketOriginSecurity(t *testing.T) { th := Setup().InitBasic() defer th.TearDown() - url := "ws://localhost" + *utils.Cfg.ServiceSettings.ListenAddress + url := fmt.Sprintf("ws://localhost:%v", th.App.Srv.ListenAddr.Port) // Should fail because origin doesn't match _, _, err := websocket.DefaultDialer.Dial(url+model.API_URL_SUFFIX_V3+"/users/websocket", http.Header{ @@ -335,7 +336,7 @@ func TestWebsocketOriginSecurity(t *testing.T) { // We are not a browser so we can spoof this just fine _, _, err = websocket.DefaultDialer.Dial(url+model.API_URL_SUFFIX_V3+"/users/websocket", http.Header{ - "Origin": []string{"http://localhost" + *utils.Cfg.ServiceSettings.ListenAddress}, + "Origin": []string{fmt.Sprintf("http://localhost:%v", th.App.Srv.ListenAddr.Port)}, }) if err != nil { t.Fatal(err) -- cgit v1.2.3-1-g7c22