Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dabasov committed Aug 5, 2023
1 parent d2099c4 commit 3f0f4b0
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 38 deletions.
59 changes: 26 additions & 33 deletions code/go/0chain.net/blobbercore/reference/hashnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,50 +10,43 @@ import (

// LoadRootHashnode load root node with its descendant nodes
func LoadRootHashnode(ctx context.Context, allocationID string) (*Hashnode, error) {
nodes := make(map[string]*Hashnode)

err := datastore.GetStore().WithNewTransaction(func(ctx context.Context) error {
tx := datastore.GetStore().GetTransaction(ctx)

db := tx.Raw(`
SELECT allocation_id, type, name, path, validation_root, fixed_merkle_root, actual_file_hash, chunk_size,size,actual_file_size, parent_path
FROM reference_objects
WHERE allocation_id = ?
ORDER BY level desc, path`, allocationID)
tx := datastore.GetStore().GetTransaction(ctx)

rows, err := db.Rows()
if err != nil {
return errors.ThrowLog(err.Error(), common.ErrBadDataStore)
}
db := tx.Raw(`
SELECT allocation_id, type, name, path, validation_root, fixed_merkle_root, actual_file_hash, chunk_size,size,actual_file_size, parent_path
FROM reference_objects
WHERE allocation_id = ?
ORDER BY level desc, path`, allocationID)

defer rows.Close()
rows, err := db.Rows()
if err != nil {
return nil, errors.ThrowLog(err.Error(), common.ErrBadDataStore)
}

for rows.Next() {
defer rows.Close()

node := &Hashnode{}
err = db.ScanRows(rows, node)
if err != nil {
return errors.ThrowLog(err.Error(), common.ErrBadDataStore)
}
nodes := make(map[string]*Hashnode)
for rows.Next() {

_, ok := nodes[node.Path]
if ok {
return common.ErrDuplicatedNode
}
node := &Hashnode{}
err = db.ScanRows(rows, node)
if err != nil {
return nil, errors.ThrowLog(err.Error(), common.ErrBadDataStore)
}

nodes[node.Path] = node
_, ok := nodes[node.Path]
if ok {
return nil, common.ErrDuplicatedNode
}

parent, ok := nodes[node.ParentPath]
if ok {
parent.AddChild(node)
}
nodes[node.Path] = node

parent, ok := nodes[node.ParentPath]
if ok {
parent.AddChild(node)
}
return nil
})

if err != nil {
return nil, err
}

// create empty dir if root is missing
Expand Down
20 changes: 16 additions & 4 deletions code/go/0chain.net/blobbercore/reference/hashnode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,14 @@ FROM reference_objects`).
if it.mock != nil {
it.mock()
}

r, err := LoadRootHashnode(context.TODO(), it.allocationID)
var (
r *Hashnode
err error
)
err = datastore.GetStore().WithNewTransaction(func(ctx context.Context) error {
r, err = LoadRootHashnode(ctx, it.allocationID)
return err
})

it.assert(test, it.allocationID, r, err)

Expand Down Expand Up @@ -357,8 +363,14 @@ FROM reference_objects`).
it.mock()
}

r, err := LoadRootHashnode(context.TODO(), it.allocationID)

var (
r *Hashnode
err error
)
err = datastore.GetStore().WithNewTransaction(func(ctx context.Context) error {
r, err = LoadRootHashnode(ctx, it.allocationID)
return err
})
it.assert(test, it.allocationID, r, err)

},
Expand Down
9 changes: 8 additions & 1 deletion code/go/0chain.net/blobbercore/writemarker/mutext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,14 @@ func TestMutext_LockShouldWork(t *testing.T) {
if it.mock != nil {
it.mock()
}
r, err := m.Lock(context.TODO(), it.allocationID, it.connectionID)
var (
r *LockResult
err error
)
err = datastore.GetStore().WithNewTransaction(func(ctx context.Context) error {
r, err = m.Lock(ctx, it.allocationID, it.connectionID)
return nil
})

it.assert(test, r, err)

Expand Down

0 comments on commit 3f0f4b0

Please sign in to comment.