diff --git a/Makefile b/Makefile index 8963db207..7c6d03832 100644 --- a/Makefile +++ b/Makefile @@ -141,7 +141,7 @@ e2e: .PHONY: unit-test unit-test: - go test -count=1 $(shell go list ./... | grep -v /test/e2e) -v + go test -race -count=1 $(shell go list ./... | grep -v /test/e2e) -v .PHONY: validate-version validate-version: validate-version-NMI validate-version-MIC validate-version-IDENTITY_VALIDATOR validate-version-DEMO diff --git a/pkg/mic/mic.go b/pkg/mic/mic.go index 8cf1fa279..e25af65ba 100644 --- a/pkg/mic/mic.go +++ b/pkg/mic/mic.go @@ -58,7 +58,9 @@ type Client struct { SyncLoopStarted bool syncRetryInterval time.Duration - syncing int32 // protect against conucrrent sync's + syncing int32 // protect against conucrrent sync's + statsMutex sync.Mutex + leaderElector *leaderelection.LeaderElector *LeaderElectionConfig } @@ -842,5 +844,7 @@ func (c *Client) updateUserMSI(newAssignedIDs []aadpodid.AzureAssignedIdentity, c.EventRecorder.Event(removedBinding, corev1.EventTypeNormal, "binding removed", fmt.Sprintf("Binding %s removed from node %s for pod %s", removedBinding.Name, delID.Spec.NodeName, delID.Spec.Pod)) } + c.statsMutex.Lock() stats.Put(stats.TotalCreateOrUpdate, time.Since(beginAdding)) + c.statsMutex.Unlock() } diff --git a/pkg/mic/mic_test.go b/pkg/mic/mic_test.go index c61412be6..3d07e23d4 100644 --- a/pkg/mic/mic_test.go +++ b/pkg/mic/mic_test.go @@ -40,11 +40,15 @@ type TestVMClient struct { } func (c *TestVMClient) SetError(err error) { + c.mu.Lock() c.err = &err + c.mu.Unlock() } func (c *TestVMClient) UnSetError() { + c.mu.Lock() c.err = nil + c.mu.Unlock() } func (c *TestVMClient) Get(rgName string, nodeName string) (ret compute.VirtualMachine, err error) {