Vladimir Domnich
962da644af
It improves payload generation in our scenarios. Current implementation of scenarios generates single random payload at the start and then sends this same payload on every request. More realistic test is to generate unique payload for each request. However, this is an expensive operation that can easily cause a bottleneck on K6 side when we run multiple writing VUs. So instead we generate a random buffer with some extra bytes and then take slices of this buffer thus producing a random payload for each request. Signed-off-by: Vladimir Domnich <v.domnich@yadro.com>
42 lines
1 KiB
Go
42 lines
1 KiB
Go
package datagen
|
|
|
|
import (
|
|
"go.k6.io/k6/js/modules"
|
|
)
|
|
|
|
// RootModule is the global module object type. It is instantiated once per test
|
|
// run and will be used to create k6/x/neofs/registry module instances for each VU.
|
|
type RootModule struct{}
|
|
|
|
// Datagen represents an instance of the module for every VU.
|
|
type Datagen struct {
|
|
vu modules.VU
|
|
}
|
|
|
|
// Ensure the interfaces are implemented correctly.
|
|
var (
|
|
_ modules.Instance = &Datagen{}
|
|
_ modules.Module = &RootModule{}
|
|
)
|
|
|
|
func init() {
|
|
modules.Register("k6/x/neofs/datagen", new(RootModule))
|
|
}
|
|
|
|
// NewModuleInstance implements the modules.Module interface and returns
|
|
// a new instance for each VU.
|
|
func (r *RootModule) NewModuleInstance(vu modules.VU) modules.Instance {
|
|
mi := &Datagen{vu: vu}
|
|
return mi
|
|
}
|
|
|
|
// Exports implements the modules.Instance interface and returns the exports
|
|
// of the JS module.
|
|
func (d *Datagen) Exports() modules.Exports {
|
|
return modules.Exports{Default: d}
|
|
}
|
|
|
|
func (d *Datagen) Generator(size int) *Generator {
|
|
g := NewGenerator(d.vu, size)
|
|
return &g
|
|
}
|