Replace sync/atomic usage with uber/atomic (#471)

This commit is contained in:
Raja Subramanian
2022-02-28 09:57:17 +05:30
committed by GitHub
parent 933b41e42a
commit 2706dc130f
9 changed files with 67 additions and 68 deletions
+4 -4
View File
@@ -3,12 +3,12 @@ package service_test
import (
"context"
"sync"
"sync/atomic"
"testing"
"time"
"github.com/livekit/protocol/livekit"
"github.com/stretchr/testify/require"
"go.uber.org/atomic"
"github.com/livekit/livekit-server/pkg/service"
)
@@ -77,7 +77,7 @@ func TestRoomLock(t *testing.T) {
token, err := rs.LockRoom(ctx, roomName, lockInterval)
require.NoError(t, err)
require.NotEmpty(t, token)
unlocked := uint32(0)
unlocked := atomic.NewUint32(0)
wg := sync.WaitGroup{}
wg.Add(1)
@@ -87,12 +87,12 @@ func TestRoomLock(t *testing.T) {
token2, err := rs.LockRoom(ctx, roomName, lockInterval)
require.NoError(t, err)
defer rs.UnlockRoom(ctx, roomName, token2)
require.Equal(t, uint32(1), atomic.LoadUint32(&unlocked))
require.Equal(t, uint32(1), unlocked.Load())
}()
// release after 2 ms
time.Sleep(2 * time.Millisecond)
atomic.StoreUint32(&unlocked, 1)
unlocked.Store(1)
_ = rs.UnlockRoom(ctx, roomName, token)
wg.Wait()