Skip to content

Instantly share code, notes, and snippets.

@vyskocilm
Created Oct 28, 2019
Embed
What would you like to do?
Stress zproc test
package main
import (
"fmt"
"io/ioutil"
"log"
"os/exec"
)
// stress zproc for https://github.com/zeromq/czmq/issues/2007
const (
NPROC = 2
SUM = 1000000
)
type ErrTuple struct {
c *exec.Cmd
err error
}
func run(idx int, c *exec.Cmd, successCh chan *exec.Cmd, errorCh chan ErrTuple) {
log.Printf("[%d]: zproc test started", idx)
stderr, err := c.StderrPipe()
if err != nil {
log.Fatal(err)
}
err = c.Run()
if err != nil {
slurp, _ := ioutil.ReadAll(stderr)
fmt.Printf("%s\n", slurp)
log.Printf("[%d]: zproc test error (err=%s), stderr=\n%s", idx, err, slurp)
errorCh <- ErrTuple{c, err}
return
}
log.Printf("[%d]: zproc test succeded", idx)
successCh <- c
}
func main() {
successCh := make(chan *exec.Cmd)
errorCh := make(chan ErrTuple)
idx := 0
for i := 0; i != NPROC; i++ {
c := exec.Command("./src/czmq_selftest", "-t", "zproc")
idx = i
go run(idx, c, successCh, errorCh)
}
for i := 0; i != SUM; i++ {
select {
case c := <-successCh:
if i < (SUM - NPROC) {
c = exec.Command("./src/czmq_selftest", "-t", "zproc")
idx++
go run(idx, c, successCh, errorCh)
}
case t := <-errorCh:
log.Fatal(t.err)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment