Commit aefd787f authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 35922706
...@@ -20,9 +20,57 @@ ...@@ -20,9 +20,57 @@
package main package main
import ( import (
"io"
"os"
"os/exec"
"testing" "testing"
"lab.nexedi.com/kirr/go123/xerr"
"lab.nexedi.com/kirr/neo/go/zodb"
) )
// TreeGen represents connection to running `treegen trees`.
//
// Create it with StartTreeGen(zurl).
// - Commit(treeTopology) ->
type TreeGen struct {
zurl string
pysrv *exec.Cmd // spawned `treegen trees`
pyin *io.PipeWriter // input to pysrv
pyout *io.PipeReader // output from pysrv
treeRoot zodb.Oid // oid of the tree treegen works on
}
// StartTreeGen spawns `treegen trees` server.
func StartTreeGen(zurl string) (_ *TreeGen, err error) {
defer xerr.Contextf(&err, "treegen %s: start", zurl)
tg := &TreeGen{zurl: zurl}
tg.pysrv = exec.Command("./testprog/treegen.py", "trees")
tg.pysrv.Stdin, tg.pyin = io.Pipe()
tg.pyout, tg.pysrv.Stdout = io.Pipe()
tg.pysrv.Stderr = os.Stderr // no redirection
err = tg.pysrv.Start()
if err != nil {
return nil, err
}
// XXX wait for init message and set .treeRoot
return tg, nil
}
// Close shutdowns the generator.
func (tg *TreeGen) Close() (err error) {
defer xerr.Contextf(&err, "treegen %s: close", tg.zurl)
err1 := tg.pyin.Close()
err2 := tg.pyout.Close()
err3 := tg.pysrv.Wait()
return xerr.Merge(err1, err2, err3)
}
// XXX // XXX
func XXX(t *testing.T, tree1, tree2 string) { func XXX(t *testing.T, tree1, tree2 string) {
// XXX commit tree1 // XXX commit tree1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment