Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
address PR comments; remove commented/dead code
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Zach Ramsay <zach.ramsay@gmail.com>
  • Loading branch information
zramsay committed Jun 1, 2017
1 parent ee18aaa commit 427d991
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 139 deletions.
104 changes: 0 additions & 104 deletions hamt/hamt_stress_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package hamt

import (
"bufio"
"context"
"fmt"
"math/rand"
"os"
"strconv"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -189,104 +186,3 @@ func genOpSet(seed int64, keep, temp []string) []testOp {
}
}
}

// executes the given op set with a repl to allow easier debugging
func debugExecuteOpSet(ds dag.DAGService, width int, ops []testOp) (*HamtShard, error) {
s, err := NewHamtShard(ds, width)
if err != nil {
return nil, err
}

e := ft.EmptyDirNode()
ds.Add(e)
ctx := context.TODO()

run := 0

opnames := map[int]string{
opAdd: "add",
opDel: "del",
}

mainloop:
for i := 0; i < len(ops); i++ {
o := ops[i]

fmt.Printf("Op %d: %s %s\n", i, opnames[o.Op], o.Val)
for run == 0 {
cmd := readCommand()
parts := strings.Split(cmd, " ")
switch parts[0] {
case "":
run = 1
case "find":
_, err := s.Find(ctx, parts[1])
if err == nil {
fmt.Println("success")
} else {
fmt.Println(err)
}
case "run":
if len(parts) > 1 {
n, err := strconv.Atoi(parts[1])
if err != nil {
panic(err)
}

run = n
} else {
run = -1
}
case "lookop":
for k := 0; k < len(ops); k++ {
if ops[k].Val == parts[1] {
fmt.Printf(" Op %d: %s %s\n", k, opnames[ops[k].Op], parts[1])
}
}
case "restart":
var err error
s, err = NewHamtShard(ds, width)
if err != nil {
panic(err)
}
i = -1
continue mainloop
case "print":
nd, err := s.Node()
if err != nil {
panic(err)
}
printDag(ds, nd.(*dag.ProtoNode), 0)
}
}
run--

switch o.Op {
case opAdd:
err := s.Set(ctx, o.Val, e)
if err != nil {
return nil, fmt.Errorf("inserting %s: %s", o.Val, err)
}
case opDel:
fmt.Println("deleting: ", o.Val)
err := s.Remove(ctx, o.Val)
if err != nil {
return nil, fmt.Errorf("deleting %s: %s", o.Val, err)
}
case opFind:
_, err := s.Find(ctx, o.Val)
if err != nil {
return nil, fmt.Errorf("finding %s: %s", o.Val, err)
}
}
}

return s, nil
}

func readCommand() string {
fmt.Print("> ")
scan := bufio.NewScanner(os.Stdin)
scan.Scan()
return scan.Text()
}
20 changes: 2 additions & 18 deletions hamt/hamt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"math/rand"
"os"
"sort"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -138,7 +137,7 @@ func TestBasicSet(t *testing.T) {

func TestDirBuilding(t *testing.T) {
ds := mdtest.Mock()
s, _ := NewHamtShard(ds, 256)
_, _ = NewHamtShard(ds, 256)

_, s, err := makeDir(ds, 200)
if err != nil {
Expand All @@ -161,7 +160,7 @@ func TestDirBuilding(t *testing.T) {

func TestShardReload(t *testing.T) {
ds := mdtest.Mock()
s, _ := NewHamtShard(ds, 256)
_, _ = NewHamtShard(ds, 256)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

Expand Down Expand Up @@ -494,21 +493,6 @@ func TestSetHamtChild(t *testing.T) {
}
}

func printDag(ds dag.DAGService, nd *dag.ProtoNode, depth int) {
padding := strings.Repeat(" ", depth)
fmt.Println("{")
for _, l := range nd.Links() {
fmt.Printf("%s%s: %s", padding, l.Name, l.Cid.String())
ch, err := ds.Get(context.Background(), l.Cid)
if err != nil {
panic(err)
}

printDag(ds, ch.(*dag.ProtoNode), depth+1)
}
fmt.Println(padding + "}")
}

func printDiff(ds dag.DAGService, a, b *dag.ProtoNode) {
diff, err := dagutils.Diff(context.TODO(), ds, a, b)
if err != nil {
Expand Down
19 changes: 2 additions & 17 deletions mod/dagmodifier_test.go
Original file line number Diff line number Diff line change
@@ -1,36 +1,21 @@
package mod

import (
"context"
"fmt"
"io"
"io/ioutil"
"testing"

"github.com/ipfs/go-ipfs/blocks/blockstore"
bs "github.com/ipfs/go-ipfs/blockservice"
"github.com/ipfs/go-ipfs/exchange/offline"
h "github.com/ipfs/go-ipfs/importer/helpers"
trickle "github.com/ipfs/go-ipfs/importer/trickle"
mdag "github.com/ipfs/go-ipfs/merkledag"
ft "github.com/ipfs/go-ipfs/unixfs"
uio "github.com/ipfs/go-ipfs/unixfs/io"
testu "github.com/ipfs/go-ipfs/unixfs/test"

context "context"
ds "gx/ipfs/QmRWDav6mzWseLWeYfVd5fvUKiVe9xNH29YfMF438fG364/go-datastore"
"gx/ipfs/QmRWDav6mzWseLWeYfVd5fvUKiVe9xNH29YfMF438fG364/go-datastore/sync"
u "gx/ipfs/QmWbjfz3u6HkAdPh34dgPchGbQjob6LXLhAeCGii2TX69n/go-ipfs-util"
)

func getMockDagServAndBstore(t testing.TB) (mdag.DAGService, blockstore.Blockstore) {
dstore := ds.NewMapDatastore()
tsds := sync.MutexWrap(dstore)
bstore := blockstore.NewBlockstore(tsds)
bserv := bs.New(bstore, offline.Exchange(bstore))
dserv := mdag.NewDAGService(bserv)
return dserv, bstore
}

func testModWrite(t *testing.T, beg, size uint64, orig []byte, dm *DagModifier) []byte {
newdata := make([]byte, size)
r := u.NewTimeSeededRand()
Expand Down Expand Up @@ -112,7 +97,7 @@ func TestDagModifierBasic(t *testing.T) {
beg = uint64(len(b))
length = 3000
t.Log("Testing pure append")
b = testModWrite(t, beg, length, b, dagmod)
_ = testModWrite(t, beg, length, b, dagmod)

// Verify reported length
node, err := dagmod.GetNode()
Expand Down

0 comments on commit 427d991

Please sign in to comment.