Commit 02db2a48 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent aefd787f
...@@ -181,8 +181,10 @@ def Trees(zstor, r): ...@@ -181,8 +181,10 @@ def Trees(zstor, r):
xbtree.Restructure(ztree, tree) xbtree.Restructure(ztree, tree)
tid = commit("treegen/trees: %s" % treetxt) tid = commit("treegen/trees: %s" % treetxt)
# XXX print more details # XXX print more details?
print("txn %s -> tree(%s) %s" % (ashex(tid), ashex(ztree._p_oid), treetxt)) # XXX print just tid (as `zodb commit` does) ?
#print("txn %s -> tree(%s) %s" % (ashex(tid), ashex(ztree._p_oid), treetxt))
print("%s" % ashex(tid))
# AllStructs generates subset of all possible tree changes in # AllStructs generates subset of all possible tree changes in
......
...@@ -20,9 +20,12 @@ ...@@ -20,9 +20,12 @@
package main package main
import ( import (
"bufio"
"fmt"
"io" "io"
"os" "os"
"os/exec" "os/exec"
"strings"
"testing" "testing"
"lab.nexedi.com/kirr/go123/xerr" "lab.nexedi.com/kirr/go123/xerr"
...@@ -37,7 +40,8 @@ type TreeGen struct { ...@@ -37,7 +40,8 @@ type TreeGen struct {
zurl string zurl string
pysrv *exec.Cmd // spawned `treegen trees` pysrv *exec.Cmd // spawned `treegen trees`
pyin *io.PipeWriter // input to pysrv pyin *io.PipeWriter // input to pysrv
pyout *io.PipeReader // output from pysrv pyoutRaw *io.PipeReader // output from pysrv
pyout *bufio.Reader // buffered ^^^
treeRoot zodb.Oid // oid of the tree treegen works on treeRoot zodb.Oid // oid of the tree treegen works on
} }
...@@ -48,7 +52,8 @@ func StartTreeGen(zurl string) (_ *TreeGen, err error) { ...@@ -48,7 +52,8 @@ func StartTreeGen(zurl string) (_ *TreeGen, err error) {
tg := &TreeGen{zurl: zurl} tg := &TreeGen{zurl: zurl}
tg.pysrv = exec.Command("./testprog/treegen.py", "trees") tg.pysrv = exec.Command("./testprog/treegen.py", "trees")
tg.pysrv.Stdin, tg.pyin = io.Pipe() tg.pysrv.Stdin, tg.pyin = io.Pipe()
tg.pyout, tg.pysrv.Stdout = io.Pipe() tg.pyoutRaw, tg.pysrv.Stdout = io.Pipe()
tg.pyout = bufio.NewReader(tg.pyout)
tg.pysrv.Stderr = os.Stderr // no redirection tg.pysrv.Stderr = os.Stderr // no redirection
err = tg.pysrv.Start() err = tg.pysrv.Start()
...@@ -66,11 +71,33 @@ func (tg *TreeGen) Close() (err error) { ...@@ -66,11 +71,33 @@ func (tg *TreeGen) Close() (err error) {
defer xerr.Contextf(&err, "treegen %s: close", tg.zurl) defer xerr.Contextf(&err, "treegen %s: close", tg.zurl)
err1 := tg.pyin.Close() err1 := tg.pyin.Close()
err2 := tg.pyout.Close() err2 := tg.pyoutRaw.Close()
err3 := tg.pysrv.Wait() err3 := tg.pysrv.Wait()
return xerr.Merge(err1, err2, err3) return xerr.Merge(err1, err2, err3)
} }
// Commit creates new commit with underlying tree changed to tree topology.
func (tg *TreeGen) Commit(tree string) (_ zodb.Tid, err error) {
defer xerr.Contextf(&err, "treegen %s: commit %s", tg.zurl, tree)
_, err = io.WriteString(tg.pyin, tree + "\n")
if err != nil {
return zodb.InvalidTid, err
}
reply, err := tg.pyout.ReadString('\n')
if err != nil {
return zodb.InvalidTid, err
}
reply = strings.TrimSuffix(reply, "\n")
tid, err := zodb.ParseTid(reply)
if err != nil {
return zodb.InvalidTid, fmt.Errorf("invalid reply: %s", err)
}
return tid, nil
}
// 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