Use the same dir in TestAcquireID

This commit is contained in:
Łukasz Magiera 2019-11-08 19:55:23 +01:00
parent c729cabef1
commit 61505b6802
2 changed files with 27 additions and 13 deletions

View File

@ -15,9 +15,20 @@ func TempSectorbuilder(sectorSize uint64, ds dtypes.MetadataDS) (*SectorBuilder,
return nil, nil, err return nil, nil, err
} }
sb, err := TempSectorbuilderDir(dir, sectorSize, ds)
return sb, func() {
sb.Destroy()
if err := os.RemoveAll(dir); err != nil {
log.Warn("failed to clean up temp sectorbuilder: ", err)
}
}, err
}
func TempSectorbuilderDir(dir string, sectorSize uint64, ds dtypes.MetadataDS) (*SectorBuilder, error) {
addr, err := address.NewFromString("t3vfxagwiegrywptkbmyohqqbfzd7xzbryjydmxso4hfhgsnv6apddyihltsbiikjf3lm7x2myiaxhuc77capq") addr, err := address.NewFromString("t3vfxagwiegrywptkbmyohqqbfzd7xzbryjydmxso4hfhgsnv6apddyihltsbiikjf3lm7x2myiaxhuc77capq")
if err != nil { if err != nil {
return nil, nil, err return nil, err
} }
metadata := filepath.Join(dir, "meta") metadata := filepath.Join(dir, "meta")
@ -37,14 +48,8 @@ func TempSectorbuilder(sectorSize uint64, ds dtypes.MetadataDS) (*SectorBuilder,
Miner: addr, Miner: addr,
}, ds, nil) }, ds, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, err
} }
return sb, func() { return sb, nil
sb.Destroy()
if err := os.RemoveAll(dir); err != nil {
log.Warn("failed to clean up temp sectorbuilder: ", err)
}
}, nil
} }

View File

@ -2,6 +2,7 @@ package sectorbuilder_test
import ( import (
"io" "io"
"io/ioutil"
"math/rand" "math/rand"
"os" "os"
"testing" "testing"
@ -98,7 +99,12 @@ func TestSealAndVerify(t *testing.T) {
func TestAcquireID(t *testing.T) { func TestAcquireID(t *testing.T) {
ds := datastore.NewMapDatastore() ds := datastore.NewMapDatastore()
sb, cleanup, err := sectorbuilder.TempSectorbuilder(sectorSize, ds) dir, err := ioutil.TempDir("", "sbtest")
if err != nil {
t.Fatal(err)
}
sb, err := sectorbuilder.TempSectorbuilderDir(dir, sectorSize, ds)
if err != nil { if err != nil {
t.Fatalf("%+v", err) t.Fatalf("%+v", err)
} }
@ -113,9 +119,9 @@ func TestAcquireID(t *testing.T) {
assertAcquire(2) assertAcquire(2)
assertAcquire(3) assertAcquire(3)
cleanup() sb.Destroy()
sb, cleanup, err = sectorbuilder.TempSectorbuilder(sectorSize, ds) sb, err = sectorbuilder.TempSectorbuilderDir(dir, sectorSize, ds)
if err != nil { if err != nil {
t.Fatalf("%+v", err) t.Fatalf("%+v", err)
} }
@ -124,5 +130,8 @@ func TestAcquireID(t *testing.T) {
assertAcquire(5) assertAcquire(5)
assertAcquire(6) assertAcquire(6)
cleanup() sb.Destroy()
if err := os.RemoveAll(dir); err != nil {
t.Error(err)
}
} }