Skip to content

Commit

Permalink
tests/robustness: address golangci var-naming issues
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Valdes <[email protected]>
  • Loading branch information
ivanvc committed Mar 22, 2024
1 parent 4898908 commit be1ee4d
Show file tree
Hide file tree
Showing 15 changed files with 102 additions and 102 deletions.
10 changes: 5 additions & 5 deletions tests/robustness/failpoint/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ var (
type memberReplace struct{}

func (f memberReplace) Inject(ctx context.Context, t *testing.T, lg *zap.Logger, clus *e2e.EtcdProcessCluster) error {
memberId := rand.Int() % len(clus.Procs)
member := clus.Procs[memberId]
memberID := uint64(rand.Int() % len(clus.Procs))
member := clus.Procs[memberID]
var endpoints []string
for i := 1; i < len(clus.Procs); i++ {
endpoints = append(endpoints, clus.Procs[(memberId+i)%len(clus.Procs)].EndpointsGRPC()...)
endpoints = append(endpoints, clus.Procs[(int(memberID)+i)%len(clus.Procs)].EndpointsGRPC()...)
}
cc, err := clientv3.New(clientv3.Config{
Endpoints: endpoints,
Expand Down Expand Up @@ -93,15 +93,15 @@ func (f memberReplace) Inject(ctx context.Context, t *testing.T, lg *zap.Logger,
}

lg.Info("Adding member back", zap.String("member", member.Config().Name))
removedMemberPeerUrl := member.Config().PeerURL.String()
removedMemberPeerURL := member.Config().PeerURL.String()
for {
select {
case <-ctx.Done():
return ctx.Err()
default:
}
reqCtx, cancel := context.WithTimeout(ctx, time.Second)
_, err = cc.MemberAdd(reqCtx, []string{removedMemberPeerUrl})
_, err = cc.MemberAdd(reqCtx, []string{removedMemberPeerURL})
cancel()
if err == nil {
break
Expand Down
32 changes: 16 additions & 16 deletions tests/robustness/identity/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,32 @@ package identity
import "sync/atomic"

type Provider interface {
// NewStreamId returns an integer starting from zero to make it render nicely by porcupine visualization.
NewStreamId() int
// NewRequestId returns unique identification used to make write requests unique.
NewRequestId() int
// NewClientId returns unique identification for client and their reports.
NewClientId() int
// NewStreamID returns an integer starting from zero to make it render nicely by porcupine visualization.
NewStreamID() int
// NewRequestID returns unique identification used to make write requests unique.
NewRequestID() int
// NewClientID returns unique identification for client and their reports.
NewClientID() int
}

func NewIdProvider() Provider {
func NewIDProvider() Provider {
return &atomicProvider{}
}

type atomicProvider struct {
streamId atomic.Int64
requestId atomic.Int64
clientId atomic.Int64
streamID atomic.Int64
requestID atomic.Int64
clientID atomic.Int64
}

func (id *atomicProvider) NewStreamId() int {
return int(id.streamId.Add(1) - 1)
func (id *atomicProvider) NewStreamID() int {
return int(id.streamID.Add(1) - 1)
}

func (id *atomicProvider) NewRequestId() int {
return int(id.requestId.Add(1))
func (id *atomicProvider) NewRequestID() int {
return int(id.requestID.Add(1))
}

func (id *atomicProvider) NewClientId() int {
return int(id.clientId.Add(1))
func (id *atomicProvider) NewClientID() int {
return int(id.clientID.Add(1))
}
26 changes: 13 additions & 13 deletions tests/robustness/identity/lease_ids.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,36 @@ import (
"sync"
)

type LeaseIdStorage interface {
LeaseId(int) int64
AddLeaseId(int, int64)
RemoveLeaseId(int)
type LeaseIDStorage interface {
LeaseID(int) int64
AddLeaseID(int, int64)
RemoveLeaseID(int)
}

func NewLeaseIdStorage() LeaseIdStorage {
return &atomicClientId2LeaseIdMapper{m: map[int]int64{}}
func NewLeaseIDStorage() LeaseIDStorage {
return &atomicClientID2LeaseIDMapper{m: map[int]int64{}}
}

type atomicClientId2LeaseIdMapper struct {
type atomicClientID2LeaseIDMapper struct {
sync.RWMutex
// m is used to store clientId to leaseId mapping.
m map[int]int64
}

func (lm *atomicClientId2LeaseIdMapper) LeaseId(clientId int) int64 {
func (lm *atomicClientID2LeaseIDMapper) LeaseID(clientID int) int64 {
lm.RLock()
defer lm.RUnlock()
return lm.m[clientId]
return lm.m[clientID]
}

func (lm *atomicClientId2LeaseIdMapper) AddLeaseId(clientId int, leaseId int64) {
func (lm *atomicClientID2LeaseIDMapper) AddLeaseID(clientID int, leaseID int64) {
lm.Lock()
defer lm.Unlock()
lm.m[clientId] = leaseId
lm.m[clientID] = leaseID
}

func (lm *atomicClientId2LeaseIdMapper) RemoveLeaseId(clientId int) {
func (lm *atomicClientID2LeaseIDMapper) RemoveLeaseID(clientID int) {
lm.Lock()
defer lm.Unlock()
delete(lm.m, clientId)
delete(lm.m, clientID)
}
2 changes: 1 addition & 1 deletion tests/robustness/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (s testScenario) run(ctx context.Context, t *testing.T, lg *zap.Logger, clu
// using baseTime time-measuring operation to get monotonic clock reading
// see https://github.com/golang/go/blob/master/src/time/time.go#L17
baseTime := time.Now()
ids := identity.NewIdProvider()
ids := identity.NewIDProvider()
g.Go(func() error {
defer close(finishTraffic)
err := failpoint.Inject(ctx, t, lg, clus, s.failpoint)
Expand Down
4 changes: 2 additions & 2 deletions tests/robustness/model/deterministic.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ func (s EtcdState) getRange(options RangeOptions) RangeResponse {
}

func detachFromOldLease(s EtcdState, key string) EtcdState {
if oldLeaseId, ok := s.KeyLeases[key]; ok {
delete(s.Leases[oldLeaseId].Keys, key)
if oldLeaseID, ok := s.KeyLeases[key]; ok {
delete(s.Leases[oldLeaseID].Keys, key)
delete(s.KeyLeases, key)
}
return s
Expand Down
26 changes: 13 additions & 13 deletions tests/robustness/model/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ import (
// Operations time should be calculated as time.Since common base time to ensure that Go monotonic time is used.
// More in https://github.com/golang/go/blob/96add980ad27faed627f26ef1ab09e8fe45d6bd1/src/time/time.go#L10.
type AppendableHistory struct {
// streamId for the next operation. Used for porcupine.Operation.ClientId as porcupine assumes no concurrent requests.
streamId int
// streamID for the next operation. Used for porcupine.Operation.ClientId as porcupine assumes no concurrent requests.
streamID int
// If needed a new streamId is requested from idProvider.
idProvider identity.Provider

Expand All @@ -45,7 +45,7 @@ type AppendableHistory struct {

func NewAppendableHistory(ids identity.Provider) *AppendableHistory {
return &AppendableHistory{
streamId: ids.NewStreamId(),
streamID: ids.NewStreamID(),
idProvider: ids,
History: History{
successful: []porcupine.Operation{},
Expand All @@ -60,7 +60,7 @@ func (h *AppendableHistory) AppendRange(startKey, endKey string, revision, limit
respRevision = resp.Header.Revision
}
h.appendSuccessful(porcupine.Operation{
ClientId: h.streamId,
ClientId: h.streamID,
Input: staleRangeRequest(startKey, endKey, limit, revision),
Call: start.Nanoseconds(),
Output: rangeResponse(resp.Kvs, resp.Count, respRevision),
Expand All @@ -79,7 +79,7 @@ func (h *AppendableHistory) AppendPut(key, value string, start, end time.Duratio
revision = resp.Header.Revision
}
h.appendSuccessful(porcupine.Operation{
ClientId: h.streamId,
ClientId: h.streamID,
Input: request,
Call: start.Nanoseconds(),
Output: putResponse(revision),
Expand All @@ -98,7 +98,7 @@ func (h *AppendableHistory) AppendPutWithLease(key, value string, leaseID int64,
revision = resp.Header.Revision
}
h.appendSuccessful(porcupine.Operation{
ClientId: h.streamId,
ClientId: h.streamID,
Input: request,
Call: start.Nanoseconds(),
Output: putResponse(revision),
Expand All @@ -121,7 +121,7 @@ func (h *AppendableHistory) AppendLeaseGrant(start, end time.Duration, resp *cli
revision = resp.ResponseHeader.Revision
}
h.appendSuccessful(porcupine.Operation{
ClientId: h.streamId,
ClientId: h.streamID,
Input: request,
Call: start.Nanoseconds(),
Output: leaseGrantResponse(revision),
Expand All @@ -140,7 +140,7 @@ func (h *AppendableHistory) AppendLeaseRevoke(id int64, start, end time.Duration
revision = resp.Header.Revision
}
h.appendSuccessful(porcupine.Operation{
ClientId: h.streamId,
ClientId: h.streamID,
Input: request,
Call: start.Nanoseconds(),
Output: leaseRevokeResponse(revision),
Expand All @@ -161,7 +161,7 @@ func (h *AppendableHistory) AppendDelete(key string, start, end time.Duration, r
deleted = resp.Deleted
}
h.appendSuccessful(porcupine.Operation{
ClientId: h.streamId,
ClientId: h.streamID,
Input: request,
Call: start.Nanoseconds(),
Output: deleteResponse(deleted, revision),
Expand Down Expand Up @@ -196,7 +196,7 @@ func (h *AppendableHistory) AppendTxn(cmp []clientv3.Cmp, clientOnSuccessOps, cl
results = append(results, toEtcdOperationResult(resp))
}
h.appendSuccessful(porcupine.Operation{
ClientId: h.streamId,
ClientId: h.streamID,
Input: request,
Call: start.Nanoseconds(),
Output: txnResponse(results, resp.Succeeded, revision),
Expand Down Expand Up @@ -306,7 +306,7 @@ func (h *AppendableHistory) AppendDefragment(start, end time.Duration, resp *cli
revision = resp.Header.Revision
}
h.appendSuccessful(porcupine.Operation{
ClientId: h.streamId,
ClientId: h.streamID,
Input: request,
Call: start.Nanoseconds(),
Output: defragmentResponse(revision),
Expand All @@ -331,15 +331,15 @@ func (h *AppendableHistory) appendFailed(request EtcdRequest, call int64, err er
}
}
h.failed = append(h.failed, porcupine.Operation{
ClientId: h.streamId,
ClientId: h.streamID,
Input: request,
Call: call,
Output: failedResponse(err),
Return: 0, // For failed writes we don't know when request has really finished.
})
// Operations of single client needs to be sequential.
// As we don't know return time of failed operations, all new writes need to be done with new stream id.
h.streamId = h.idProvider.NewStreamId()
h.streamID = h.idProvider.NewStreamID()
}

func getRequest(key string) EtcdRequest {
Expand Down
14 changes: 7 additions & 7 deletions tests/robustness/report/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
)

type ClientReport struct {
ClientId int
ClientID int
KeyValue []porcupine.Operation
Watch []model.WatchOperation
}
Expand All @@ -48,10 +48,10 @@ func (r ClientReport) WatchEventCount() int {

func persistClientReports(t *testing.T, lg *zap.Logger, path string, reports []ClientReport) {
sort.Slice(reports, func(i, j int) bool {
return reports[i].ClientId < reports[j].ClientId
return reports[i].ClientID < reports[j].ClientID
})
for _, r := range reports {
clientDir := filepath.Join(path, fmt.Sprintf("client-%d", r.ClientId))
clientDir := filepath.Join(path, fmt.Sprintf("client-%d", r.ClientID))
err := os.MkdirAll(clientDir, 0700)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -82,12 +82,12 @@ func LoadClientReports(path string) ([]ClientReport, error) {
if err != nil {
return nil, err
}
r.ClientId = id
r.ClientID = id
reports = append(reports, r)
}
}
sort.Slice(reports, func(i, j int) bool {
return reports[i].ClientId < reports[j].ClientId
return reports[i].ClientID < reports[j].ClientID
})
return reports, nil
}
Expand Down Expand Up @@ -145,7 +145,7 @@ func loadKeyValueOperations(path string) (operations []porcupine.Operation, err
decoder := json.NewDecoder(file)
for decoder.More() {
var operation struct {
ClientId int
ClientID int
Input model.EtcdRequest
Call int64
Output model.MaybeEtcdResponse
Expand All @@ -156,7 +156,7 @@ func loadKeyValueOperations(path string) (operations []porcupine.Operation, err
return nil, fmt.Errorf("failed to decode watch operation, err: %w", err)
}
operations = append(operations, porcupine.Operation{
ClientId: operation.ClientId,
ClientId: operation.ClientID,
Input: operation.Input,
Call: operation.Call,
Output: operation.Output,
Expand Down
6 changes: 3 additions & 3 deletions tests/robustness/report/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
)

func TestPersistLoadClientReports(t *testing.T) {
h := model.NewAppendableHistory(identity.NewIdProvider())
h := model.NewAppendableHistory(identity.NewIDProvider())
baseTime := time.Now()

start := time.Since(baseTime)
Expand Down Expand Up @@ -122,12 +122,12 @@ func TestPersistLoadClientReports(t *testing.T) {
}
reports := []ClientReport{
{
ClientId: 1,
ClientID: 1,
KeyValue: h.Operations(),
Watch: []model.WatchOperation{watch},
},
{
ClientId: 2,
ClientID: 2,
KeyValue: nil,
Watch: []model.WatchOperation{watch},
},
Expand Down
16 changes: 8 additions & 8 deletions tests/robustness/traffic/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func NewClient(endpoints []string, ids identity.Provider, baseTime time.Time) (*
return nil, err
}
return &RecordingClient{
id: ids.NewClientId(),
id: ids.NewClientID(),
client: *cc,
kvOperations: model.NewAppendableHistory(ids),
baseTime: baseTime,
Expand All @@ -75,7 +75,7 @@ func (c *RecordingClient) Close() error {

func (c *RecordingClient) Report() report.ClientReport {
return report.ClientReport{
ClientId: c.id,
ClientID: c.id,
KeyValue: c.kvOperations.History.Operations(),
Watch: c.watchOperations,
}
Expand Down Expand Up @@ -162,24 +162,24 @@ func (c *RecordingClient) LeaseGrant(ctx context.Context, ttl int64) (*clientv3.
return resp, err
}

func (c *RecordingClient) LeaseRevoke(ctx context.Context, leaseId int64) (*clientv3.LeaseRevokeResponse, error) {
func (c *RecordingClient) LeaseRevoke(ctx context.Context, leaseID int64) (*clientv3.LeaseRevokeResponse, error) {
c.kvMux.Lock()
defer c.kvMux.Unlock()
callTime := time.Since(c.baseTime)
resp, err := c.client.Lease.Revoke(ctx, clientv3.LeaseID(leaseId))
resp, err := c.client.Lease.Revoke(ctx, clientv3.LeaseID(leaseID))
returnTime := time.Since(c.baseTime)
c.kvOperations.AppendLeaseRevoke(leaseId, callTime, returnTime, resp, err)
c.kvOperations.AppendLeaseRevoke(leaseID, callTime, returnTime, resp, err)
return resp, err
}

func (c *RecordingClient) PutWithLease(ctx context.Context, key string, value string, leaseId int64) (*clientv3.PutResponse, error) {
opts := clientv3.WithLease(clientv3.LeaseID(leaseId))
func (c *RecordingClient) PutWithLease(ctx context.Context, key string, value string, leaseID int64) (*clientv3.PutResponse, error) {
opts := clientv3.WithLease(clientv3.LeaseID(leaseID))
c.kvMux.Lock()
defer c.kvMux.Unlock()
callTime := time.Since(c.baseTime)
resp, err := c.client.Put(ctx, key, value, opts)
returnTime := time.Since(c.baseTime)
c.kvOperations.AppendPutWithLease(key, value, leaseId, callTime, returnTime, resp, err)
c.kvOperations.AppendPutWithLease(key, value, leaseID, callTime, returnTime, resp, err)
return resp, err
}

Expand Down
Loading

0 comments on commit be1ee4d

Please sign in to comment.