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

Commit

Permalink
[WIP] failing test refined with a wrapped DAG service
Browse files Browse the repository at this point in the history
  • Loading branch information
schomatis committed Dec 22, 2018
1 parent 88b8e7b commit 9afa20a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 22 deletions.
24 changes: 3 additions & 21 deletions mfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -682,27 +682,9 @@ func actorReadFile(d *Directory) error {
func testActor(rt *Root, iterations int, errs chan error) {
d := rt.GetDirectory()
for i := 0; i < iterations; i++ {
switch rand.Intn(5) {
case 0:
if err := actorMkdir(d); err != nil {
errs <- err
return
}
case 1, 2:
if err := actorMakeFile(d); err != nil {
errs <- err
return
}
case 3:
if err := actorWriteFile(d); err != nil {
errs <- err
return
}
case 4:
if err := actorReadFile(d); err != nil {
errs <- err
return
}
if err := actorMakeFile(d); err != nil {
errs <- err
return
}
}
errs <- nil
Expand Down
42 changes: 41 additions & 1 deletion root.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import (

ipld "github.com/ipfs/go-ipld-format"
logging "github.com/ipfs/go-log"

cid "github.com/ipfs/go-cid"

)

// TODO: Remove if not used.
Expand Down Expand Up @@ -90,6 +93,43 @@ type Root struct {
repub *Republisher
}

// TODO: There *must* be a better way..

type wrappedDAG struct {
ipld.NodeGetter
ds ipld.DAGService
}

func (wd wrappedDAG) RemoveMany(ctx context.Context, cid []cid.Cid) error {
return wd.ds.RemoveMany(ctx, cid)
}

func (wd wrappedDAG) Remove(ctx context.Context, cid cid.Cid) error {
return wd.ds.Remove(ctx, cid)
}

func (wd wrappedDAG) Add(ctx context.Context, nd ipld.Node) error {

// TODO: Accessing the links here doesn't fail.

protoNode, ok := nd.(*dag.ProtoNode)
if ok {
protoLinks := protoNode.Links()
for i := range protoLinks {
if protoLinks[i].Name == "a" { protoLinks[i].Name = "b" }
//fmt.Printf("Link name: %s\n", protoLinks[i].Name) // This avoids the race.
}
}

return wd.ds.Add(ctx, nd)
}

func (wd wrappedDAG) AddMany(ctx context.Context, nd []ipld.Node) error {
return wd.ds.AddMany(ctx, nd)
}



// NewRoot creates a new Root and starts up a republisher routine for it.
func NewRoot(parent context.Context, ds ipld.DAGService, node *dag.ProtoNode, pf PubFunc) (*Root, error) {

Expand Down Expand Up @@ -117,7 +157,7 @@ func NewRoot(parent context.Context, ds ipld.DAGService, node *dag.ProtoNode, pf

switch fsn.Type() {
case ft.TDirectory, ft.THAMTShard:
newDir, err := NewDirectory(parent, node.String(), node, root, ds)
newDir, err := NewDirectory(parent, node.String(), node, root, wrappedDAG{ds, ds})
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 9afa20a

Please sign in to comment.