mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
tests: Fix putWithLease traffic timeout/limit and double overall timeout to reduce number of failed requests
Signed-off-by: Marek Siarkowicz <siarkowicz@google.com>
This commit is contained in:
parent
2b45023364
commit
bff3d4a592
@ -27,6 +27,7 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
DefaultLeaseTTL int64 = 7200
|
DefaultLeaseTTL int64 = 7200
|
||||||
|
RequestTimeout = 40 * time.Millisecond
|
||||||
DefaultTraffic Traffic = readWriteSingleKey{keyCount: 4, leaseTTL: DefaultLeaseTTL, writes: []opChance{{operation: Put, chance: 50}, {operation: Delete, chance: 10}, {operation: PutWithLease, chance: 10}, {operation: LeaseRevoke, chance: 10}, {operation: Txn, chance: 20}}}
|
DefaultTraffic Traffic = readWriteSingleKey{keyCount: 4, leaseTTL: DefaultLeaseTTL, writes: []opChance{{operation: Put, chance: 50}, {operation: Delete, chance: 10}, {operation: PutWithLease, chance: 10}, {operation: LeaseRevoke, chance: 10}, {operation: Txn, chance: 20}}}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -65,7 +66,7 @@ func (t readWriteSingleKey) Run(ctx context.Context, c *recordingClient, limiter
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t readWriteSingleKey) Read(ctx context.Context, c *recordingClient, limiter *rate.Limiter, key string) ([]*mvccpb.KeyValue, error) {
|
func (t readWriteSingleKey) Read(ctx context.Context, c *recordingClient, limiter *rate.Limiter, key string) ([]*mvccpb.KeyValue, error) {
|
||||||
getCtx, cancel := context.WithTimeout(ctx, 20*time.Millisecond)
|
getCtx, cancel := context.WithTimeout(ctx, RequestTimeout)
|
||||||
resp, err := c.Get(getCtx, key)
|
resp, err := c.Get(getCtx, key)
|
||||||
cancel()
|
cancel()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -75,33 +76,38 @@ func (t readWriteSingleKey) Read(ctx context.Context, c *recordingClient, limite
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t readWriteSingleKey) Write(ctx context.Context, c *recordingClient, limiter *rate.Limiter, key string, newValue string, lm clientId2LeaseIdMapper, cid int, lastValues []*mvccpb.KeyValue) error {
|
func (t readWriteSingleKey) Write(ctx context.Context, c *recordingClient, limiter *rate.Limiter, key string, newValue string, lm clientId2LeaseIdMapper, cid int, lastValues []*mvccpb.KeyValue) error {
|
||||||
putCtx, cancel := context.WithTimeout(ctx, 20*time.Millisecond)
|
writeCtx, cancel := context.WithTimeout(ctx, RequestTimeout)
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
switch t.pickWriteOperation() {
|
switch t.pickWriteOperation() {
|
||||||
case Put:
|
case Put:
|
||||||
err = c.Put(putCtx, key, newValue)
|
err = c.Put(writeCtx, key, newValue)
|
||||||
case Delete:
|
case Delete:
|
||||||
err = c.Delete(putCtx, key)
|
err = c.Delete(writeCtx, key)
|
||||||
case Txn:
|
case Txn:
|
||||||
var expectValue string
|
var expectValue string
|
||||||
if len(lastValues) != 0 {
|
if len(lastValues) != 0 {
|
||||||
expectValue = string(lastValues[0].Value)
|
expectValue = string(lastValues[0].Value)
|
||||||
}
|
}
|
||||||
err = c.Txn(putCtx, key, expectValue, newValue)
|
err = c.Txn(writeCtx, key, expectValue, newValue)
|
||||||
case PutWithLease:
|
case PutWithLease:
|
||||||
leaseId := lm.LeaseId(cid)
|
leaseId := lm.LeaseId(cid)
|
||||||
if leaseId == 0 {
|
if leaseId == 0 {
|
||||||
leaseId, err = c.LeaseGrant(ctx, t.leaseTTL)
|
leaseId, err = c.LeaseGrant(writeCtx, t.leaseTTL)
|
||||||
lm.AddLeaseId(cid, leaseId)
|
if err == nil {
|
||||||
|
lm.AddLeaseId(cid, leaseId)
|
||||||
|
limiter.Wait(ctx)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if leaseId != 0 {
|
if leaseId != 0 {
|
||||||
|
putCtx, putCancel := context.WithTimeout(ctx, RequestTimeout)
|
||||||
err = c.PutWithLease(putCtx, key, newValue, leaseId)
|
err = c.PutWithLease(putCtx, key, newValue, leaseId)
|
||||||
|
putCancel()
|
||||||
}
|
}
|
||||||
case LeaseRevoke:
|
case LeaseRevoke:
|
||||||
leaseId := lm.LeaseId(cid)
|
leaseId := lm.LeaseId(cid)
|
||||||
if leaseId != 0 {
|
if leaseId != 0 {
|
||||||
err = c.LeaseRevoke(putCtx, leaseId)
|
err = c.LeaseRevoke(writeCtx, leaseId)
|
||||||
//if LeaseRevoke has failed, do not remove the mapping.
|
//if LeaseRevoke has failed, do not remove the mapping.
|
||||||
if err == nil {
|
if err == nil {
|
||||||
lm.RemoveLeaseId(cid)
|
lm.RemoveLeaseId(cid)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user