github.com/haalcala/mattermost-server-change-repo/v5@v5.33.2/store/searchlayer/layer_test.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See LICENSE.txt for license information.
     3  
     4  package searchlayer_test
     5  
     6  import (
     7  	"os"
     8  	"sync"
     9  	"testing"
    10  
    11  	"github.com/mattermost/mattermost-server/v5/model"
    12  	"github.com/mattermost/mattermost-server/v5/services/searchengine"
    13  	"github.com/mattermost/mattermost-server/v5/store/searchlayer"
    14  	"github.com/mattermost/mattermost-server/v5/store/sqlstore"
    15  	"github.com/mattermost/mattermost-server/v5/store/storetest"
    16  	"github.com/mattermost/mattermost-server/v5/testlib"
    17  )
    18  
    19  // Test to verify race condition on UpdateConfig. The test must run with -race flag in order to verify
    20  // that there is no race. Ref: (#MM-30868)
    21  func TestUpdateConfigRace(t *testing.T) {
    22  	driverName := os.Getenv("MM_SQLSETTINGS_DRIVERNAME")
    23  	if driverName == "" {
    24  		driverName = model.DATABASE_DRIVER_POSTGRES
    25  	}
    26  	settings := storetest.MakeSqlSettings(driverName)
    27  	store := sqlstore.New(*settings, nil)
    28  
    29  	cfg := &model.Config{}
    30  	cfg.SetDefaults()
    31  	cfg.ClusterSettings.MaxIdleConns = model.NewInt(1)
    32  	searchEngine := searchengine.NewBroker(cfg, nil)
    33  	layer := searchlayer.NewSearchLayer(&testlib.TestStore{Store: store}, searchEngine, cfg)
    34  	var wg sync.WaitGroup
    35  
    36  	wg.Add(5)
    37  	for i := 0; i < 5; i++ {
    38  		go func() {
    39  			defer wg.Done()
    40  			layer.UpdateConfig(cfg.Clone())
    41  		}()
    42  	}
    43  
    44  	wg.Wait()
    45  }