This is an automated email from the ASF dual-hosted git repository.

pbacsko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/yunikorn-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 40486373 [YUNIKORN-2157] Data race in TestStoreWithLimitedSize (#716)
40486373 is described below

commit 40486373298918c931e55a7ecbf2fc50ae45431b
Author: Peter Bacsko <[email protected]>
AuthorDate: Fri Nov 17 19:05:54 2023 +0100

    [YUNIKORN-2157] Data race in TestStoreWithLimitedSize (#716)
    
    Closes: #716
    
    Signed-off-by: Peter Bacsko <[email protected]>
---
 pkg/events/event_store.go      | 8 ++++++--
 pkg/events/event_store_test.go | 6 +-----
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/pkg/events/event_store.go b/pkg/events/event_store.go
index cd2cc603..638cea8a 100644
--- a/pkg/events/event_store.go
+++ b/pkg/events/event_store.go
@@ -25,7 +25,7 @@ import (
        "github.com/apache/yunikorn-scheduler-interface/lib/go/si"
 )
 
-var defaultEventStoreSize = 1000
+const defaultEventStoreSize = 1000
 
 // The EventStore operates under the following assumptions:
 //   - there is a cap for the number of events stored
@@ -40,8 +40,12 @@ type EventStore struct {
 }
 
 func newEventStore() *EventStore {
+       return newEventStoreWithSize(defaultEventStoreSize)
+}
+
+func newEventStoreWithSize(size int) *EventStore {
        return &EventStore{
-               events: make([]*si.EventRecord, defaultEventStoreSize),
+               events: make([]*si.EventRecord, size),
        }
 }
 
diff --git a/pkg/events/event_store_test.go b/pkg/events/event_store_test.go
index 6ad42e8a..7bb2c17c 100644
--- a/pkg/events/event_store_test.go
+++ b/pkg/events/event_store_test.go
@@ -54,12 +54,8 @@ func TestStoreAndRetrieve(t *testing.T) {
 // if we push more events to the EventStore than its
 // allowed maximum, those that couldn't fit will be omitted
 func TestStoreWithLimitedSize(t *testing.T) {
-       defaultEventStoreSize = 3
-       defer func() {
-               defaultEventStoreSize = 1000
-       }()
+       store := newEventStoreWithSize(3)
 
-       store := newEventStore()
        for i := 0; i < 5; i++ {
                event := &si.EventRecord{
                        Type:        si.EventRecord_REQUEST,


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to