Skip to content
This repository has been archived by the owner on Nov 24, 2022. It is now read-only.

Commit

Permalink
add test to cover removing manually downloaded files
Browse files Browse the repository at this point in the history
Signed-off-by: Merlin Ran <merlinran@gmail.com>
  • Loading branch information
merlinran committed Sep 14, 2021
1 parent 56b9117 commit cb8560b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion service/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ func (s *Store) GC(discardOrphanDealsAfter time.Duration) (bidsRemoved, filesRem
if _, exists := removeFiles[path]; exists {
shouldRemove = true
} else if _, exists := keepFiles[path]; !exists {
if time.Since(info.ModTime()) > discardOrphanDealsAfter {
if discardOrphanDealsAfter > 0 && time.Since(info.ModTime()) > discardOrphanDealsAfter {
shouldRemove = true
}
}
Expand Down
15 changes: 13 additions & 2 deletions service/store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,12 @@ func TestStore_GC(t *testing.T) {
require.NoError(t, err)
_ = f.Close()

manualFile := s.dealDataFilePathFor("", failBid.PayloadCid.String())
// simulate manually downloaded file
f, err = os.Create(manualFile)
require.NoError(t, err)
_ = f.Close()

hangingBid, _ = s.GetBid(hangingBid.ID)
assert.Equal(t, BidStatusAwaitingProposal, hangingBid.Status)

Expand All @@ -235,14 +241,19 @@ func TestStore_GC(t *testing.T) {
require.True(t, os.IsNotExist(err), "file for finalized deal should have been removed")
_, err = os.Stat(failFile)
require.NoError(t, err, "file for errored deal should always be kept")
_, err = os.Stat(manualFile)
require.NoError(t, err, "manually downloaded file should have been kept")

_, err = s.GetBid(hangingBid.ID)
require.NoError(t, err, "not cleaning orphan deals")

// GC with discarding orphan deals
s.GC(time.Second)
time.Sleep(100 * time.Millisecond)
s.GC(100 * time.Millisecond)
_, err = os.Stat(failFile)
require.NoError(t, err, "file for errored deal should always be kept")
//
_, err = os.Stat(manualFile)
require.Error(t, err, "manually downloaded file should be discarded")
_, err = s.GetBid(hangingBid.ID)
require.Equal(t, ErrBidNotFound, err, "orphan deals should have been cleaned up")
}
Expand Down

0 comments on commit cb8560b

Please sign in to comment.