Add concurrent execs in stress tests

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby 2019-07-19 19:12:44 +00:00
parent ffa86b25f9
commit 1945e26ac3
2 changed files with 16 additions and 12 deletions

View File

@ -18,6 +18,7 @@ package main
import ( import (
"context" "context"
"fmt"
"strings" "strings"
"syscall" "syscall"
"time" "time"
@ -38,8 +39,9 @@ func (w *execWorker) exec(ctx, tctx context.Context) {
w.wg.Done() w.wg.Done()
logrus.Infof("worker %d finished", w.id) logrus.Infof("worker %d finished", w.id)
}() }()
c, err := w.client.NewContainer(ctx, "exec-container", id := fmt.Sprintf("exec-container-%d", w.id)
containerd.WithNewSnapshot("exec-container", w.image), c, err := w.client.NewContainer(ctx, id,
containerd.WithNewSnapshot(id, w.image),
containerd.WithNewSpec(oci.WithImageConfig(w.image), oci.WithUsername("games"), oci.WithProcessArgs("sleep", "30d")), containerd.WithNewSpec(oci.WithImageConfig(w.image), oci.WithUsername("games"), oci.WithProcessArgs("sleep", "30d")),
) )
if err != nil { if err != nil {

View File

@ -257,17 +257,19 @@ func test(c config) error {
} }
var exec *execWorker var exec *execWorker
if c.Exec { if c.Exec {
wg.Add(1) for i := c.Concurrency; i < c.Concurrency+c.Concurrency; i++ {
exec = &execWorker{ wg.Add(1)
worker: worker{ exec = &execWorker{
id: c.Concurrency, worker: worker{
wg: &wg, id: i,
image: image, wg: &wg,
client: client, image: image,
commit: v.Revision, client: client,
}, commit: v.Revision,
},
}
go exec.exec(ctx, tctx)
} }
go exec.exec(ctx, tctx)
} }
// start the timer and run the worker // start the timer and run the worker