diff --git a/internal/rwmutex/rwmutex_z_unit_test.go b/internal/rwmutex/rwmutex_z_unit_test.go index 2cb6d7048..5979c6ff0 100644 --- a/internal/rwmutex/rwmutex_z_unit_test.go +++ b/internal/rwmutex/rwmutex_z_unit_test.go @@ -15,7 +15,7 @@ import ( "github.com/gogf/gf/v2/test/gtest" ) -func TestRwmutexIsSafe(t *testing.T) { +func TestRWMutexIsSafe(t *testing.T) { gtest.C(t, func(t *gtest.T) { lock := rwmutex.New() t.Assert(lock.IsSafe(), false) @@ -37,7 +37,7 @@ func TestRwmutexIsSafe(t *testing.T) { }) } -func TestSafeRwmutex(t *testing.T) { +func TestSafeRWMutex(t *testing.T) { gtest.C(t, func(t *gtest.T) { safeLock := rwmutex.New(true) array := garray.New(true) @@ -68,33 +68,34 @@ func TestSafeRwmutex(t *testing.T) { }) } -func TestSafeReaderRwmutex(t *testing.T) { +func TestSafeReaderRWMutex(t *testing.T) { gtest.C(t, func(t *gtest.T) { - safeLock := rwmutex.New(true) - array := garray.New(true) - + var ( + localSafeLock = rwmutex.New(true) + array = garray.New(true) + ) go func() { - safeLock.RLock() + localSafeLock.RLock() array.Append(1) time.Sleep(100 * time.Millisecond) array.Append(1) - safeLock.RUnlock() + localSafeLock.RUnlock() }() go func() { time.Sleep(10 * time.Millisecond) - safeLock.RLock() + localSafeLock.RLock() array.Append(1) time.Sleep(200 * time.Millisecond) array.Append(1) time.Sleep(100 * time.Millisecond) array.Append(1) - safeLock.RUnlock() + localSafeLock.RUnlock() }() go func() { time.Sleep(50 * time.Millisecond) - safeLock.Lock() + localSafeLock.Lock() array.Append(1) - safeLock.Unlock() + localSafeLock.Unlock() }() time.Sleep(50 * time.Millisecond) t.Assert(array.Len(), 2) @@ -107,33 +108,34 @@ func TestSafeReaderRwmutex(t *testing.T) { }) } -func TestUnsafeRwmutex(t *testing.T) { +func TestUnsafeRWMutex(t *testing.T) { gtest.C(t, func(t *gtest.T) { - unsafeLock := rwmutex.New() - array := garray.New(true) - + var ( + localUnsafeLock = rwmutex.New() + array = garray.New(true) + ) go func() { - unsafeLock.Lock() + localUnsafeLock.Lock() array.Append(1) - time.Sleep(100 * time.Millisecond) + time.Sleep(2000 * time.Millisecond) array.Append(1) - unsafeLock.Unlock() + localUnsafeLock.Unlock() }() go func() { - time.Sleep(10 * time.Millisecond) - unsafeLock.Lock() + time.Sleep(500 * time.Millisecond) + localUnsafeLock.Lock() array.Append(1) - time.Sleep(200 * time.Millisecond) + time.Sleep(500 * time.Millisecond) array.Append(1) - unsafeLock.Unlock() + localUnsafeLock.Unlock() }() - time.Sleep(50 * time.Millisecond) + time.Sleep(800 * time.Millisecond) t.Assert(array.Len(), 2) - time.Sleep(100 * time.Millisecond) + time.Sleep(800 * time.Millisecond) t.Assert(array.Len(), 3) - time.Sleep(50 * time.Millisecond) + time.Sleep(200 * time.Millisecond) t.Assert(array.Len(), 3) - time.Sleep(100 * time.Millisecond) + time.Sleep(500 * time.Millisecond) t.Assert(array.Len(), 4) }) }