This repository has been archived by the owner on Dec 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix comment of ReplicaCall * rename rec pointer name * fix discovery range * add more tests & use search lock struct instead --------- Co-authored-by: maxim-konovalov <maksim.konovalov@vk.team>
- Loading branch information
1 parent
9c5be22
commit 9e72b8c
Showing
5 changed files
with
87 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package vshard_router | ||
|
||
import ( | ||
"sync" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestSearchLock_WaitOnSearch(t *testing.T) { | ||
lock := searchLock{ | ||
mu: sync.RWMutex{}, | ||
perBucket: make([]chan struct{}, 10), | ||
} | ||
|
||
noLockStart := time.Now() | ||
lock.WaitOnSearch(5) | ||
require.True(t, time.Since(noLockStart) < time.Millisecond) | ||
|
||
lockStart := time.Now() | ||
chStopSearch := lock.StartSearch(3) | ||
go func() { | ||
time.Sleep(time.Millisecond * 10) | ||
close(chStopSearch) | ||
}() | ||
|
||
noLockStart = time.Now() | ||
lock.WaitOnSearch(5) | ||
require.True(t, time.Since(noLockStart) < time.Millisecond) | ||
|
||
lock.WaitOnSearch(3) | ||
|
||
require.True(t, time.Since(lockStart) < 12*time.Millisecond && time.Since(lockStart) > 9*time.Millisecond) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters