the race conditions in tests

This commit is contained in:
Roman Perekhod
2023-11-29 13:44:36 +01:00
parent 0f9f996aba
commit fd388653a9
3 changed files with 24 additions and 11 deletions

View File

@@ -0,0 +1,6 @@
Bugfix: the race conditions in tests
We fixed the race conditions in tests.
https://github.com/owncloud/ocis/pull/7847
https://github.com/owncloud/ocis/issues/7846

View File

@@ -1,6 +1,7 @@
package search_test
import (
"sync/atomic"
"time"
user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
@@ -13,7 +14,8 @@ import (
var _ = Describe("SpaceDebouncer", func() {
var (
debouncer *search.SpaceDebouncer
callCount map[string]int
callCount atomic.Int32
userId = &user.UserId{
OpaqueId: "user",
@@ -24,9 +26,11 @@ var _ = Describe("SpaceDebouncer", func() {
)
BeforeEach(func() {
callCount = map[string]int{}
callCount = atomic.Int32{}
debouncer = search.NewSpaceDebouncer(50*time.Millisecond, func(id *sprovider.StorageSpaceId, _ *user.UserId) {
callCount[id.OpaqueId] += 1
if id.OpaqueId == "spaceid" {
callCount.Add(1)
}
})
})
@@ -35,7 +39,7 @@ var _ = Describe("SpaceDebouncer", func() {
debouncer.Debounce(spaceid, userId)
debouncer.Debounce(spaceid, userId)
Eventually(func() int {
return callCount["spaceid"]
return int(callCount.Load())
}, "200ms").Should(Equal(1))
})
@@ -49,13 +53,15 @@ var _ = Describe("SpaceDebouncer", func() {
debouncer.Debounce(spaceid, userId)
Eventually(func() int {
return callCount["spaceid"]
return int(callCount.Load())
}, "200ms").Should(Equal(2))
})
It("doesn't trigger twice simultaneously", func() {
debouncer = search.NewSpaceDebouncer(50*time.Millisecond, func(id *sprovider.StorageSpaceId, _ *user.UserId) {
callCount[id.OpaqueId] += 1
if id.OpaqueId == "spaceid" {
callCount.Add(1)
}
time.Sleep(300 * time.Millisecond)
})
debouncer.Debounce(spaceid, userId)
@@ -63,10 +69,10 @@ var _ = Describe("SpaceDebouncer", func() {
debouncer.Debounce(spaceid, userId)
time.Sleep(100 * time.Millisecond) // shouldn't trigger as the other run is still in progress
Expect(callCount["spaceid"]).To(Equal(1))
Expect(int(callCount.Load())).To(Equal(1))
Eventually(func() int {
return callCount["spaceid"]
return int(callCount.Load())
}, "500ms").Should(Equal(2))
})
})

View File

@@ -2,6 +2,7 @@ package search_test
import (
"context"
"sync/atomic"
userv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
"github.com/cs3org/reva/v2/pkg/events"
@@ -19,7 +20,7 @@ var _ = DescribeTable("events",
func(mcks []string, e interface{}, asyncUploads bool) {
var (
s = &searchMocks.Searcher{}
calls int
calls atomic.Int32
)
bus, _ := mEvents.NewStream()
@@ -32,7 +33,7 @@ var _ = DescribeTable("events",
for _, mck := range mcks {
s.On(mck, mock.Anything, mock.Anything).Return(nil).Run(func(args mock.Arguments) {
calls += 1
calls.Add(1)
})
}
@@ -40,7 +41,7 @@ var _ = DescribeTable("events",
Expect(err).To(BeNil())
Eventually(func() int {
return calls
return int(calls.Load())
}, "2s").Should(Equal(len(mcks)))
},
Entry("ItemTrashed", []string{"TrashItem", "IndexSpace"}, events.ItemTrashed{}, false),