Add test to make sure passed keys are not modified in keylock

This commit is contained in:
pkositsyn 2021-02-22 01:35:45 +03:00 committed by Fedor Korotkiy
parent e40aa18778
commit f1997376ee

View file

@ -83,6 +83,20 @@ func TestKeyLock_DeadlockFree(t *testing.T) {
wg.Wait()
}
func TestKeyLock_NoMutates(t *testing.T) {
defer goleak.VerifyNone(t)
l := keylock.New()
keys := []string{"b", "c", "a"}
passedKeys := make([]string, len(keys))
copy(passedKeys, keys)
_, unlock := l.LockKeys(passedKeys, nil)
unlock()
require.Equal(t, keys, passedKeys, "passed keys shouldn't be mutated")
}
func TestKeyLock_SingleKeyStress(t *testing.T) {
const (
N = 1000