From 7e59f311a3a7685a9d9aa10eb636cfc2cb0d739e Mon Sep 17 00:00:00 2001 From: Doug Lauder Date: Tue, 21 Jul 2020 12:18:57 -0400 Subject: [PATCH] MM-26757 Run server tests on non-default port (#15075) * run server tests on port randomly selected by the kernel --- cmd/mattermost/commands/server_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cmd/mattermost/commands/server_test.go b/cmd/mattermost/commands/server_test.go index 3f92a43762..98f9882244 100644 --- a/cmd/mattermost/commands/server_test.go +++ b/cmd/mattermost/commands/server_test.go @@ -15,6 +15,10 @@ import ( "github.com/stretchr/testify/require" ) +const ( + UnitTestListeningPort = ":0" +) + type ServerTestHelper struct { disableConfigWatch bool interruptChan chan os.Signal @@ -56,6 +60,9 @@ func TestRunServerSuccess(t *testing.T) { configStore, err := config.NewMemoryStore() require.NoError(t, err) + // Use non-default listening port in case another server instance is already running. + *configStore.Get().ServiceSettings.ListenAddress = UnitTestListeningPort + err = runServer(configStore, th.disableConfigWatch, false, th.interruptChan) require.NoError(t, err) } @@ -104,6 +111,9 @@ func TestRunServerSystemdNotification(t *testing.T) { configStore, err := config.NewMemoryStore() require.NoError(t, err) + // Use non-default listening port in case another server instance is already running. + *configStore.Get().ServiceSettings.ListenAddress = UnitTestListeningPort + // Start and stop the server err = runServer(configStore, th.disableConfigWatch, false, th.interruptChan) require.NoError(t, err) @@ -125,6 +135,9 @@ func TestRunServerNoSystemd(t *testing.T) { configStore, err := config.NewMemoryStore() require.NoError(t, err) + // Use non-default listening port in case another server instance is already running. + *configStore.Get().ServiceSettings.ListenAddress = UnitTestListeningPort + err = runServer(configStore, th.disableConfigWatch, false, th.interruptChan) require.NoError(t, err) }