* Fixing race in update channel

* Switching to struct copy
Этот коммит содержится в:
Corey Hulen
2017-08-22 10:20:54 -07:00
коммит произвёл GitHub
родитель 1ce079d2d0
Коммит b0e367b192
3 изменённых файлов: 15 добавлений и 1 удалений

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

@@ -53,6 +53,11 @@ type ChannelPatch struct {
Purpose *string `json:"purpose"`
}
func (o *Channel) DeepCopy() *Channel {
copy := *o
return &copy
}
func (o *Channel) ToJson() string {
b, err := json.Marshal(o)
if err != nil {

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

@@ -27,6 +27,15 @@ func TestChannelJson(t *testing.T) {
}
}
func TestChannelCopy(t *testing.T) {
o := Channel{Id: NewId(), Name: NewId()}
ro := o.DeepCopy()
if o.Id != ro.Id {
t.Fatal("Ids do not match")
}
}
func TestChannelPatch(t *testing.T) {
p := &ChannelPatch{Name: new(string), DisplayName: new(string), Header: new(string), Purpose: new(string)}
*p.Name = NewId()

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

@@ -405,7 +405,7 @@ func (s SqlChannelStore) get(id string, master bool, allowFromCache bool) StoreC
if metrics != nil {
metrics.IncrementMemCacheHitCounter("Channel")
}
result.Data = cacheItem.(*model.Channel)
result.Data = (cacheItem.(*model.Channel)).DeepCopy()
storeChannel <- result
close(storeChannel)
return