Fix race in stress test tool
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
12e7c76771
commit
1cb0e81b5a
@ -101,10 +101,6 @@ func test(c config) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
logrus.Info("generating spec from image")
|
logrus.Info("generating spec from image")
|
||||||
spec, err := containerd.GenerateSpec(ctx, client, &containers.Container{ID: ""}, containerd.WithImageConfig(image), containerd.WithProcessArgs("true"))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
tctx, cancel := context.WithTimeout(ctx, c.Duration)
|
tctx, cancel := context.WithTimeout(ctx, c.Duration)
|
||||||
go func() {
|
go func() {
|
||||||
s := make(chan os.Signal, 1)
|
s := make(chan os.Signal, 1)
|
||||||
@ -120,10 +116,14 @@ func test(c config) error {
|
|||||||
logrus.Info("starting stress test run...")
|
logrus.Info("starting stress test run...")
|
||||||
for i := 0; i < c.Concurrency; i++ {
|
for i := 0; i < c.Concurrency; i++ {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
|
spec, err := containerd.GenerateSpec(ctx, client, &containers.Container{ID: ""}, containerd.WithImageConfig(image), containerd.WithProcessArgs("true"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
w := &worker{
|
w := &worker{
|
||||||
id: i,
|
id: i,
|
||||||
wg: &wg,
|
wg: &wg,
|
||||||
spec: *spec,
|
spec: spec,
|
||||||
image: image,
|
image: image,
|
||||||
client: client,
|
client: client,
|
||||||
}
|
}
|
||||||
@ -161,7 +161,7 @@ type worker struct {
|
|||||||
|
|
||||||
client *containerd.Client
|
client *containerd.Client
|
||||||
image containerd.Image
|
image containerd.Image
|
||||||
spec specs.Spec
|
spec *specs.Spec
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *worker) run(ctx, tctx context.Context) {
|
func (w *worker) run(ctx, tctx context.Context) {
|
||||||
@ -197,9 +197,10 @@ func (w *worker) run(ctx, tctx context.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *worker) runContainer(ctx context.Context, id string) error {
|
func (w *worker) runContainer(ctx context.Context, id string) error {
|
||||||
w.spec.Linux.CgroupsPath = filepath.Join("/", fmt.Sprint(w.id), id)
|
// fix up cgroups path for a default config
|
||||||
|
w.spec.Linux.CgroupsPath = filepath.Join("/", "stress", id)
|
||||||
c, err := w.client.NewContainer(ctx, id,
|
c, err := w.client.NewContainer(ctx, id,
|
||||||
containerd.WithSpec(&w.spec),
|
containerd.WithSpec(w.spec),
|
||||||
containerd.WithNewSnapshot(id, w.image),
|
containerd.WithNewSnapshot(id, w.image),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user