Commit d344db94 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 7b7e0242
......@@ -46,11 +46,13 @@ import (
"github.com/stretchr/testify/require"
)
// TreeGen represents connection to running `treegen trees` server.
// TreeSrv represents connection to running `treegen trees` server.
//
// Create it with StartTreeGen(zurl).
// Create it with StartTreeSrv(zurl).
// - Commit(treeTopology) -> tid
type TreeGen struct {
type TreeSrv struct {
zurl string
pysrv *exec.Cmd // spawned `treegen trees`
pyin io.WriteCloser // input to pysrv
......@@ -61,11 +63,11 @@ type TreeGen struct {
}
// StartTreeGen spawns `treegen trees` server.
func StartTreeGen(zurl string) (_ *TreeGen, err error) {
func StartTreeGen(zurl string) (_ *TreeSrv, err error) {
defer xerr.Contextf(&err, "treegen %s: start", zurl)
// spawn `treegen trees`
tg := &TreeGen{zurl: zurl}
tg := &TreeSrv{zurl: zurl}
tg.pysrv = exec.Command("./testprog/treegen.py", "trees", zurl)
tg.pyin, err = tg.pysrv.StdinPipe()
if err != nil {
......@@ -119,7 +121,7 @@ func StartTreeGen(zurl string) (_ *TreeGen, err error) {
}
// Close shutdowns treegen server.
func (tg *TreeGen) Close() (err error) {
func (tg *TreeSrv) Close() (err error) {
defer xerr.Contextf(&err, "treegen %s: close", tg.zurl)
err1 := tg.pyin.Close()
......@@ -129,7 +131,7 @@ func (tg *TreeGen) Close() (err error) {
}
// Commit creates new commit with underlying tree changed to specified tree topology.
func (tg *TreeGen) Commit(tree string) (_ zodb.Tid, err error) {
func (tg *TreeSrv) 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")
......@@ -507,6 +509,7 @@ func TestΔBTreeAllStructs(t *testing.T) {
for k := range keys2 { kv2[Key(k)] = randv() }
// given (kv1, kv2) test on automatically generated (tree1 -> tree2)
//reqSeed = rng.Int63()
fmt.Printf("%s -> %s\n", kvtxt(kv1), kvtxt(kv2))
//testq <- ...
......@@ -603,6 +606,10 @@ func TestKVDiff(t *testing.T) {
// kvtxt returns string representation of {} kv.
func kvtxt(kv map[Key]string) string {
if len(kv) == 0 {
return "ø"
}
keyv := []Key{}
for k := range kv { keyv = append(keyv, k) }
sort.Slice(keyv, func(i,j int) bool { return keyv[i] < keyv[j] })
......
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