Skip to content

Commit

Permalink
test: generate uuid on startup for load tool (#9383) (#9393)
Browse files Browse the repository at this point in the history
the `NewClient` method is called by the load test framework for each connection. This means that if multiple connections are instantiated, each connection will erroneously have its own UUID. This PR changes the UUID generation to happen at the _beginning_ of the script instead of on client creation so that each experimental run shares a UUID.

Caught while preparing the script for production readiness.

- [ ] Tests written/updated, or no tests needed
- [ ] `CHANGELOG_PENDING.md` updated, or no changelog entry needed
- [ ] Updated relevant documentation (`docs/`) and code comments, or no
      documentation updates needed

(cherry picked from commit 59a711eabe90e91f91d61bc7b8fc0fab8b88d89c)

Co-authored-by: William Banfield <[email protected]>
  • Loading branch information
tnasu and williambanfield committed Jul 20, 2023
1 parent bb0db92 commit 82334d9
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions test/loadtime/cmd/load/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ var (
)

// ClientFactory implements the loadtest.ClientFactory interface.
type ClientFactory struct{}
type ClientFactory struct {
ID []byte
}

// TxGenerator is responsible for generating transactions.
// TxGenerator holds the set of information that will be used to generate
Expand All @@ -29,7 +31,8 @@ type TxGenerator struct {
}

func main() {
if err := loadtest.RegisterClientFactory("loadtime-client", &ClientFactory{}); err != nil {
u := [16]byte(uuid.New()) // generate run ID on startup
if err := loadtest.RegisterClientFactory("loadtime-client", &ClientFactory{ID: u[:]}); err != nil {
panic(err)
}
loadtest.Run(&loadtest.CLIConfig{
Expand All @@ -52,9 +55,8 @@ func (f *ClientFactory) ValidateConfig(cfg loadtest.Config) error {
}

func (f *ClientFactory) NewClient(cfg loadtest.Config) (loadtest.Client, error) {
u := [16]byte(uuid.New())
return &TxGenerator{
id: u[:],
id: f.ID,
conns: uint64(cfg.Connections),
rate: uint64(cfg.Rate),
size: uint64(cfg.Size),
Expand Down

0 comments on commit 82334d9

Please sign in to comment.