MM-29486: Fix racy test TestPatchChannelModeration (#16256)
* MM-29486: Fix racy test TestPatchChannelModeration - We avoid appending to the slice in `(r *Role) IsValidWithoutId` by just iterating the 2 slices separately. - We pass deep copies of channels to prevent racy modification. https://mattermost.atlassian.net/browse/MM-29486 ```release-note NONE ``` * fix lint * simplify perm check * improve more Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
42c785218d
Коммит
cae59d327c
@@ -1828,15 +1828,15 @@ func TestPatchChannelModerationsForChannel(t *testing.T) {
|
|||||||
wg.Add(20)
|
wg.Add(20)
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
go func() {
|
go func() {
|
||||||
th.App.PatchChannelModerationsForChannel(channel, addCreatePosts)
|
th.App.PatchChannelModerationsForChannel(channel.DeepCopy(), addCreatePosts)
|
||||||
th.App.PatchChannelModerationsForChannel(channel, removeCreatePosts)
|
th.App.PatchChannelModerationsForChannel(channel.DeepCopy(), removeCreatePosts)
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
go func() {
|
go func() {
|
||||||
th.App.PatchChannelModerationsForChannel(channel, addCreatePosts)
|
th.App.PatchChannelModerationsForChannel(channel.DeepCopy(), addCreatePosts)
|
||||||
th.App.PatchChannelModerationsForChannel(channel, removeCreatePosts)
|
th.App.PatchChannelModerationsForChannel(channel.DeepCopy(), removeCreatePosts)
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -482,15 +482,16 @@ func (r *Role) IsValidWithoutId() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, permission := range r.Permissions {
|
check := func(perms []*Permission, permission string) bool {
|
||||||
permissionValidated := false
|
for _, p := range perms {
|
||||||
for _, p := range append(AllPermissions, DeprecatedPermissions...) {
|
|
||||||
if permission == p.Id {
|
if permission == p.Id {
|
||||||
permissionValidated = true
|
return true
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, permission := range r.Permissions {
|
||||||
|
permissionValidated := check(AllPermissions, permission) || check(DeprecatedPermissions, permission)
|
||||||
if !permissionValidated {
|
if !permissionValidated {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user