Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

integration: check concurrent auth ops don't cause old rev errors #8442

Merged
merged 2 commits into from
Aug 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions integration/v3_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package integration

import (
"fmt"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -292,3 +294,41 @@ func TestV3AuthNonAuthorizedRPCs(t *testing.T) {
t.Fatalf("could put key (%v), it should cause an error of permission denied", respput)
}
}

func TestV3AuthOldRevConcurrent(t *testing.T) {
defer testutil.AfterTest(t)
clus := NewClusterV3(t, &ClusterConfig{Size: 1})
defer clus.Terminate(t)

authSetupRoot(t, toGRPC(clus.Client(0)).Auth)

c, cerr := clientv3.New(clientv3.Config{
Endpoints: clus.Client(0).Endpoints(),
DialTimeout: 5 * time.Second,
Username: "root",
Password: "123",
})
testutil.AssertNil(t, cerr)
defer c.Close()

var wg sync.WaitGroup
f := func(i int) {
defer wg.Done()
role, user := fmt.Sprintf("test-role-%d", i), fmt.Sprintf("test-user-%d", i)
_, err := c.RoleAdd(context.TODO(), role)
testutil.AssertNil(t, err)
_, err = c.RoleGrantPermission(context.TODO(), role, "", clientv3.GetPrefixRangeEnd(""), clientv3.PermissionType(clientv3.PermReadWrite))
testutil.AssertNil(t, err)
_, err = c.UserAdd(context.TODO(), user, "123")
testutil.AssertNil(t, err)
_, err = c.Put(context.TODO(), "a", "b")
testutil.AssertNil(t, err)
}
// needs concurrency to trigger
numRoles := 2
wg.Add(numRoles)
for i := 0; i < numRoles; i++ {
go f(i)
}
wg.Wait()
}
6 changes: 5 additions & 1 deletion pkg/testutil/assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,9 @@ func AssertFalse(t *testing.T, v bool, msg ...string) {
}

func isNil(v interface{}) bool {
return v == nil || reflect.ValueOf(v).IsNil()
if v == nil {
return true
}
rv := reflect.ValueOf(v)
return rv.Kind() != reflect.Struct && rv.IsNil()
}