Skip to content

Commit

Permalink
Update atomic.Int32 for schedulerapi_mock.go
Browse files Browse the repository at this point in the history
  • Loading branch information
SophieTech88 committed Aug 22, 2024
1 parent 7fb2a13 commit 5dbaf18
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions pkg/common/test/schedulerapi_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ import (
)

type SchedulerAPIMock struct {
registerCount int32
UpdateAllocationCount int32
UpdateApplicationCount int32
UpdateNodeCount int32
registerCount atomic.Int32
UpdateAllocationCount atomic.Int32
UpdateApplicationCount atomic.Int32
UpdateNodeCount atomic.Int32
registerFn func(request *si.RegisterResourceManagerRequest,
callback api.ResourceManagerCallback) (*si.RegisterResourceManagerResponse, error)
UpdateAllocationFn func(request *si.AllocationRequest) error
Expand All @@ -41,10 +41,6 @@ type SchedulerAPIMock struct {

func NewSchedulerAPIMock() *SchedulerAPIMock {
return &SchedulerAPIMock{
registerCount: int32(0),
UpdateAllocationCount: int32(0),
UpdateApplicationCount: int32(0),
UpdateNodeCount: int32(0),
registerFn: func(request *si.RegisterResourceManagerRequest,
callback api.ResourceManagerCallback) (response *si.RegisterResourceManagerResponse, e error) {
return nil, nil
Expand Down Expand Up @@ -93,28 +89,28 @@ func (api *SchedulerAPIMock) RegisterResourceManager(request *si.RegisterResourc
callback api.ResourceManagerCallback) (*si.RegisterResourceManagerResponse, error) {
api.lock.Lock()
defer api.lock.Unlock()
atomic.AddInt32(&api.registerCount, 1)
api.registerCount.Add(1)
return api.registerFn(request, callback)
}

func (api *SchedulerAPIMock) UpdateAllocation(request *si.AllocationRequest) error {
api.lock.Lock()
defer api.lock.Unlock()
atomic.AddInt32(&api.UpdateAllocationCount, 1)
api.UpdateAllocationCount.Add(1)
return api.UpdateAllocationFn(request)
}

func (api *SchedulerAPIMock) UpdateApplication(request *si.ApplicationRequest) error {
api.lock.Lock()
defer api.lock.Unlock()
atomic.AddInt32(&api.UpdateApplicationCount, 1)
api.UpdateApplicationCount.Add(1)
return api.UpdateApplicationFn(request)
}

func (api *SchedulerAPIMock) UpdateNode(request *si.NodeRequest) error {
api.lock.Lock()
defer api.lock.Unlock()
atomic.AddInt32(&api.UpdateNodeCount, 1)
api.UpdateNodeCount.Add(1)
return api.UpdateNodeFn(request)
}

Expand All @@ -125,26 +121,26 @@ func (api *SchedulerAPIMock) UpdateConfiguration(request *si.UpdateConfiguration
}

func (api *SchedulerAPIMock) GetRegisterCount() int32 {
return atomic.LoadInt32(&api.registerCount)
return api.registerCount.Load()

Check warning on line 124 in pkg/common/test/schedulerapi_mock.go

View check run for this annotation

Codecov / codecov/patch

pkg/common/test/schedulerapi_mock.go#L124

Added line #L124 was not covered by tests
}

func (api *SchedulerAPIMock) GetUpdateAllocationCount() int32 {
return atomic.LoadInt32(&api.UpdateAllocationCount)
return api.UpdateAllocationCount.Load()
}

func (api *SchedulerAPIMock) GetUpdateApplicationCount() int32 {
return atomic.LoadInt32(&api.UpdateApplicationCount)
return api.UpdateApplicationCount.Load()

Check warning on line 132 in pkg/common/test/schedulerapi_mock.go

View check run for this annotation

Codecov / codecov/patch

pkg/common/test/schedulerapi_mock.go#L132

Added line #L132 was not covered by tests
}

func (api *SchedulerAPIMock) GetUpdateNodeCount() int32 {
return atomic.LoadInt32(&api.UpdateNodeCount)
return api.UpdateNodeCount.Load()

Check warning on line 136 in pkg/common/test/schedulerapi_mock.go

View check run for this annotation

Codecov / codecov/patch

pkg/common/test/schedulerapi_mock.go#L136

Added line #L136 was not covered by tests
}

func (api *SchedulerAPIMock) ResetAllCounters() {
atomic.StoreInt32(&api.registerCount, 0)
atomic.StoreInt32(&api.UpdateAllocationCount, 0)
atomic.StoreInt32(&api.UpdateApplicationCount, 0)
atomic.StoreInt32(&api.UpdateNodeCount, 0)
api.registerCount.Store(0)
api.UpdateAllocationCount.Store(0)
api.UpdateApplicationCount.Store(0)
api.UpdateNodeCount.Store(0)

Check warning on line 143 in pkg/common/test/schedulerapi_mock.go

View check run for this annotation

Codecov / codecov/patch

pkg/common/test/schedulerapi_mock.go#L140-L143

Added lines #L140 - L143 were not covered by tests
}

func (api *SchedulerAPIMock) Stop() {
Expand Down

0 comments on commit 5dbaf18

Please sign in to comment.