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) }