mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
integration: check concurrent auth ops don't cause old rev errors
This commit is contained in:
parent
1fc300ecbd
commit
267a2fc8c9
@ -15,6 +15,8 @@
|
||||
package integration
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@ -118,3 +120,41 @@ func authSetupRoot(t *testing.T, auth pb.AuthClient) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user