extend test to do a double move and check symlink following
This commit is contained in:
parent
cbaffab9dd
commit
d6ace68540
@ -291,7 +291,7 @@ func (b *Blockstore) movingGC() error {
|
|||||||
dir := filepath.Dir(linkPath)
|
dir := filepath.Dir(linkPath)
|
||||||
path = filepath.Join(dir, name)
|
path = filepath.Join(dir, name)
|
||||||
}
|
}
|
||||||
path = fmt.Sprintf("%s.%d", path, time.Now().Unix())
|
path = fmt.Sprintf("%s.%d", path, time.Now().UnixNano())
|
||||||
|
|
||||||
log.Infof("moving blockstore from %s to %s", b.opts.Dir, path)
|
log.Infof("moving blockstore from %s to %s", b.opts.Dir, path)
|
||||||
|
|
||||||
|
@ -163,72 +163,88 @@ func testMove(t *testing.T, optsF func(string) Options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// now check that we have all the blocks in have and none in the deleted lists
|
// now check that we have all the blocks in have and none in the deleted lists
|
||||||
for _, blk := range have {
|
checkBlocks := func() {
|
||||||
has, err := db.Has(blk.Cid())
|
for _, blk := range have {
|
||||||
if err != nil {
|
has, err := db.Has(blk.Cid())
|
||||||
t.Fatal(err)
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !has {
|
||||||
|
t.Fatal("missing block")
|
||||||
|
}
|
||||||
|
|
||||||
|
blk2, err := db.Get(blk.Cid())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !bytes.Equal(blk.RawData(), blk2.RawData()) {
|
||||||
|
t.Fatal("data mismatch")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !has {
|
for _, c := range deleted {
|
||||||
t.Fatal("missing block")
|
has, err := db.Has(c)
|
||||||
}
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
blk2, err := db.Get(blk.Cid())
|
if has {
|
||||||
if err != nil {
|
t.Fatal("resurrected block")
|
||||||
t.Fatal(err)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if !bytes.Equal(blk.RawData(), blk2.RawData()) {
|
|
||||||
t.Fatal("data mismatch")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range deleted {
|
checkBlocks()
|
||||||
has, err := db.Has(c)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if has {
|
|
||||||
t.Fatal("resurrected block")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// check the basePath -- it should contain a directory with name db.{timestamp}, soft-linked
|
// check the basePath -- it should contain a directory with name db.{timestamp}, soft-linked
|
||||||
// to db and nothing else
|
// to db and nothing else
|
||||||
entries, err := os.ReadDir(basePath)
|
checkPath := func() {
|
||||||
if err != nil {
|
entries, err := os.ReadDir(basePath)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(entries) != 2 {
|
||||||
|
t.Fatalf("too many entries; expected %d but got %d", 2, len(entries))
|
||||||
|
}
|
||||||
|
|
||||||
|
var haveDB, haveDBLink bool
|
||||||
|
for _, e := range entries {
|
||||||
|
if e.Name() == "db" {
|
||||||
|
if (e.Type() & os.ModeSymlink) == 0 {
|
||||||
|
t.Fatal("found db, but it's not a symlink")
|
||||||
|
}
|
||||||
|
haveDBLink = true
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if strings.HasPrefix(e.Name(), "db.") {
|
||||||
|
if !e.Type().IsDir() {
|
||||||
|
t.Fatal("found db prefix, but it's not a directory")
|
||||||
|
}
|
||||||
|
haveDB = true
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !haveDB {
|
||||||
|
t.Fatal("db directory is missing")
|
||||||
|
}
|
||||||
|
if !haveDBLink {
|
||||||
|
t.Fatal("db link is missing")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
checkPath()
|
||||||
|
|
||||||
|
// now do another FullGC to test the double move and following of symlinks
|
||||||
|
if err := db.CollectGarbage(blockstore.WithFullGC(true)); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(entries) != 2 {
|
checkBlocks()
|
||||||
t.Fatalf("too many entries; expected %d but got %d", 2, len(entries))
|
checkPath()
|
||||||
}
|
|
||||||
|
|
||||||
var haveDB, haveDBLink bool
|
|
||||||
for _, e := range entries {
|
|
||||||
if e.Name() == "db" {
|
|
||||||
if (e.Type() & os.ModeSymlink) == 0 {
|
|
||||||
t.Fatal("found db, but it's not a symlink")
|
|
||||||
}
|
|
||||||
haveDBLink = true
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if strings.HasPrefix(e.Name(), "db.") {
|
|
||||||
if !e.Type().IsDir() {
|
|
||||||
t.Fatal("found db prefix, but it's not a directory")
|
|
||||||
}
|
|
||||||
haveDB = true
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !haveDB {
|
|
||||||
t.Fatal("db directory is missing")
|
|
||||||
}
|
|
||||||
if !haveDBLink {
|
|
||||||
t.Fatal("db link is missing")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMoveNoPrefix(t *testing.T) {
|
func TestMoveNoPrefix(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user