Created
October 28, 2019 16:57
-
-
Save vyskocilm/9784e0ed060fdec02775713940c4c766 to your computer and use it in GitHub Desktop.
Stress zproc test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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