Files
kopia/tests/robustness/multiclient_test/framework/client.go
Julio López d1e5c1d8a0 chore(general): clean nits (#5313)
- make benchmarking params uint
- prevent error in compression benchmarking
- lint on Windows and address linter warnings
- upgrade golang.org/x/exp
- upgrade github.com/cncf/xds/go
- upgrade github.com/dustinkirkland/golang-petname
- direct users to forum
- add warning about _recovery recipes_
2026-04-16 21:41:39 -07:00

49 lines
1.0 KiB
Go

//go:build darwin || (linux && amd64)
package framework
import (
"context"
petname "github.com/dustinkirkland/golang-petname"
"github.com/google/uuid"
)
const nameLen int = 2
type clientKeyT struct{}
var clientKey clientKeyT
// Client is a unique client for use in multiclient robustness tests.
type Client struct {
ID string
}
func newClient() *Client {
return &Client{
ID: petname.Generate(nameLen, "-") + "-" + uuid.NewString(),
}
}
// NewClientContext returns a copy of ctx with a new client.
func NewClientContext(ctx context.Context) context.Context {
return context.WithValue(ctx, clientKey, newClient())
}
// NewClientContexts returns copies of ctx with n new clients.
func NewClientContexts(ctx context.Context, n int) []context.Context {
ctxs := make([]context.Context, n)
for i := range ctxs {
ctxs[i] = NewClientContext(ctx) //nolint:fatcontext
}
return ctxs
}
// UnwrapContext returns a client from the given context.
func UnwrapContext(ctx context.Context) *Client {
c, _ := ctx.Value(clientKey).(*Client)
return c
}