re-assign cluster interface after initializing enterprise interfaces (#20839)

* re-assign cluster interface after initializing enterprise interfaces

* add a unit test to check if cluster is triggered

* remove env overrides

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Ibrahim Serdar Acikgoz
2022-08-17 23:07:04 +03:00
коммит произвёл GitHub
родитель 3498592a45
Коммит 8e0d46e0c6
3 изменённых файлов: 34 добавлений и 0 удалений

Просмотреть файл

@@ -114,6 +114,7 @@ func RegisterLicenseInterface(f func(*Server) einterfaces.LicenseInterface) {
func (s *Server) initEnterprise() {
if clusterInterface != nil && s.Cluster == nil {
s.Cluster = clusterInterface(s)
s.platform.SetCluster(s.Cluster)
}
if elasticsearchInterface != nil {
s.SearchEngine.RegisterElasticsearchEngine(elasticsearchInterface(s))

Просмотреть файл

@@ -3,6 +3,8 @@
package platform
import "github.com/mattermost/mattermost-server/v6/einterfaces"
func (ps *PlatformService) IsLeader() bool {
if ps.License() != nil && *ps.Config().ClusterSettings.Enable && ps.cluster != nil {
return ps.cluster.IsLeader()
@@ -10,3 +12,7 @@ func (ps *PlatformService) IsLeader() bool {
return true
}
func (ps *PlatformService) SetCluster(impl einterfaces.ClusterInterface) {
ps.cluster = impl
}

Просмотреть файл

@@ -7,7 +7,9 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/mattermost/mattermost-server/v6/einterfaces/mocks"
"github.com/mattermost/mattermost-server/v6/model"
)
@@ -45,3 +47,28 @@ func TestConfigListener(t *testing.T) {
assert.True(t, listenerCalled, "listener should've been called")
assert.True(t, listener2Called, "listener 2 should've been called")
}
func TestConfigSave(t *testing.T) {
th := Setup(t)
defer th.TearDown()
cm := &mocks.ClusterInterface{}
th.Service.SetCluster(cm)
t.Run("trigger a config changed event for the cluster", func(t *testing.T) {
oldCfg := th.Service.Config()
newCfg := oldCfg.Clone()
newCfg.ServiceSettings.SiteURL = model.NewString("http://newhost.me")
sanitizedOldCfg := th.Service.configStore.RemoveEnvironmentOverrides(oldCfg)
sanitizedNewCfg := th.Service.configStore.RemoveEnvironmentOverrides(newCfg)
cm.On("ConfigChanged", sanitizedOldCfg, sanitizedNewCfg, true).Return(nil)
_, _, appErr := th.Service.SaveConfig(newCfg, true)
require.Nil(t, appErr)
updatedCfg := th.Service.Config()
assert.Equal(t, "http://newhost.me", *updatedCfg.ServiceSettings.SiteURL)
})
}