MM-30988 - Fix racy test ServerSystemdNotification (#16431)

* MM-30988 - Fix racy test ServerSystemdNotification

The translateFunc is a global variable which was unguarded.
So we convert that into an atomic variable to prevent against races.

https://mattermost.atlassian.net/browse/MM-30988

```release-note
NONE
```

* fix tests

* move call upwards

* use race

* after translations init

* guard with a sync.Once

* missed import

* revert race

* update timeout
Этот коммит содержится в:
Agniva De Sarker
2020-12-02 14:22:41 +05:30
коммит произвёл GitHub
родитель e22669c403
Коммит fc60a1e8dd
3 изменённых файлов: 8 добавлений и 5 удалений

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

@@ -269,6 +269,7 @@ func NewServer(options ...Option) (*Server, error) {
if err := utils.TranslationsPreInit(); err != nil {
return nil, errors.Wrapf(err, "unable to load Mattermost translation files")
}
model.AppErrorInit(utils.T)
searchEngine := searchengine.NewBroker(s.Config(), s.Jobs)
bleveEngine := bleveengine.NewBleveEngine(s.Config(), s.Jobs)
@@ -450,8 +451,6 @@ func NewServer(options ...Option) (*Server, error) {
mlog.Error("Problem with file storage settings", mlog.Err(appErr))
}
model.AppErrorInit(utils.T)
s.timezones = timezones.New()
// Start email batching because it's not like the other jobs
s.AddConfigListener(func(_, _ *model.Config) {

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

@@ -18,6 +18,7 @@ import (
"regexp"
"strconv"
"strings"
"sync"
"time"
"unicode"
@@ -72,10 +73,13 @@ func (sa StringArray) Equals(input StringArray) bool {
return true
}
var translateFunc goi18n.TranslateFunc = nil
var translateFunc goi18n.TranslateFunc
var translateFuncOnce sync.Once
func AppErrorInit(t goi18n.TranslateFunc) {
translateFunc = t
translateFuncOnce.Do(func() {
translateFunc = t
})
}
type AppError struct {

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

@@ -16,7 +16,7 @@ echo "Packages to test: $PACKAGES"
find . -name 'cprofile*.out' -exec sh -c 'rm "{}"' \;
find . -type d -name data -not -path './vendor/*' -not -path './data' | xargs rm -rf
$GO test $GOFLAGS -run=$TESTS $TESTFLAGS -v -timeout=2000s -covermode=count -coverpkg=$PACKAGES_COMMA -exec $DIR/test-xprog.sh $PACKAGES 2>&1 > >( tee output )
$GO test $GOFLAGS -run=$TESTS $TESTFLAGS -v -timeout=20m -covermode=count -coverpkg=$PACKAGES_COMMA -exec $DIR/test-xprog.sh $PACKAGES 2>&1 > >( tee output )
EXIT_STATUS=$?
cat output | $GOBIN/go-junit-report > report.xml