Skip to content

Commit ef5e77e

Browse files
author
Anthony Romano
authored
Merge pull request #8442 from heyitsanthony/oldrev-test
integration: check concurrent auth ops don't cause old rev errors
2 parents d76b29c + dfed636 commit ef5e77e

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

integration/v3_auth_test.go

+40
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
package integration
1616

1717
import (
18+
"fmt"
19+
"sync"
1820
"testing"
1921
"time"
2022

@@ -292,3 +294,41 @@ func TestV3AuthNonAuthorizedRPCs(t *testing.T) {
292294
t.Fatalf("could put key (%v), it should cause an error of permission denied", respput)
293295
}
294296
}
297+
298+
func TestV3AuthOldRevConcurrent(t *testing.T) {
299+
defer testutil.AfterTest(t)
300+
clus := NewClusterV3(t, &ClusterConfig{Size: 1})
301+
defer clus.Terminate(t)
302+
303+
authSetupRoot(t, toGRPC(clus.Client(0)).Auth)
304+
305+
c, cerr := clientv3.New(clientv3.Config{
306+
Endpoints: clus.Client(0).Endpoints(),
307+
DialTimeout: 5 * time.Second,
308+
Username: "root",
309+
Password: "123",
310+
})
311+
testutil.AssertNil(t, cerr)
312+
defer c.Close()
313+
314+
var wg sync.WaitGroup
315+
f := func(i int) {
316+
defer wg.Done()
317+
role, user := fmt.Sprintf("test-role-%d", i), fmt.Sprintf("test-user-%d", i)
318+
_, err := c.RoleAdd(context.TODO(), role)
319+
testutil.AssertNil(t, err)
320+
_, err = c.RoleGrantPermission(context.TODO(), role, "", clientv3.GetPrefixRangeEnd(""), clientv3.PermissionType(clientv3.PermReadWrite))
321+
testutil.AssertNil(t, err)
322+
_, err = c.UserAdd(context.TODO(), user, "123")
323+
testutil.AssertNil(t, err)
324+
_, err = c.Put(context.TODO(), "a", "b")
325+
testutil.AssertNil(t, err)
326+
}
327+
// needs concurrency to trigger
328+
numRoles := 2
329+
wg.Add(numRoles)
330+
for i := 0; i < numRoles; i++ {
331+
go f(i)
332+
}
333+
wg.Wait()
334+
}

pkg/testutil/assert.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,9 @@ func AssertFalse(t *testing.T, v bool, msg ...string) {
5454
}
5555

5656
func isNil(v interface{}) bool {
57-
return v == nil || reflect.ValueOf(v).IsNil()
57+
if v == nil {
58+
return true
59+
}
60+
rv := reflect.ValueOf(v)
61+
return rv.Kind() != reflect.Struct && rv.IsNil()
5862
}

0 commit comments

Comments
 (0)