Address data race in pkg/locale
This commit is contained in:
@@ -421,6 +421,9 @@ func (svc *service) TResourceFor(tag language.Tag, ns, key string, rr ...string)
|
||||
func (svc *service) ResourceTranslations(tag language.Tag, resource string) ResourceTranslationIndex {
|
||||
out := make(ResourceTranslationIndex)
|
||||
|
||||
svc.l.Lock()
|
||||
defer svc.l.Unlock()
|
||||
|
||||
if svc != nil && svc.set != nil {
|
||||
if l, has := svc.set[tag]; has {
|
||||
return l.resourceTranslations(resource)
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package locale
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/cortezaproject/corteza-server/pkg/options"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.uber.org/zap"
|
||||
"golang.org/x/text/language"
|
||||
)
|
||||
|
||||
// tested with
|
||||
// go test -count 10 -race -run TestServiceReloadAndTranslate ./pkg/locale/...
|
||||
func TestServiceReloadAndTranslate(t *testing.T) {
|
||||
var (
|
||||
req = require.New(t)
|
||||
svc, err = Service(zap.NewNop(), options.LocaleOpt{
|
||||
Languages: "en",
|
||||
})
|
||||
|
||||
tag = language.English
|
||||
)
|
||||
|
||||
req.NoError(err)
|
||||
req.NotNil(svc)
|
||||
go svc.ResourceTranslations(tag, "resource")
|
||||
go svc.ReloadStatic()
|
||||
}
|
||||
Reference in New Issue
Block a user