From 8e0d46e0c6e20a61636d2170390c0d30622f72cf Mon Sep 17 00:00:00 2001 From: Ibrahim Serdar Acikgoz Date: Wed, 17 Aug 2022 23:07:04 +0300 Subject: [PATCH] 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 --- app/enterprise.go | 1 + app/platform/cluster.go | 6 ++++++ app/platform/config_test.go | 27 +++++++++++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/app/enterprise.go b/app/enterprise.go index db826a873f..956d220d1e 100644 --- a/app/enterprise.go +++ b/app/enterprise.go @@ -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)) diff --git a/app/platform/cluster.go b/app/platform/cluster.go index 75fe329cea..4964c7d6f0 100644 --- a/app/platform/cluster.go +++ b/app/platform/cluster.go @@ -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 +} diff --git a/app/platform/config_test.go b/app/platform/config_test.go index 62ecbce482..3dd9ebf19e 100644 --- a/app/platform/config_test.go +++ b/app/platform/config_test.go @@ -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) + }) +}