Skip to content

Commit

Permalink
fix(pruner): Make pruner test slightly more deterministic
Browse files Browse the repository at this point in the history
  • Loading branch information
renaynay committed Feb 5, 2024
1 parent b5bfb6f commit a53cdc1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
2 changes: 0 additions & 2 deletions pruner/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package pruner

import (
"context"
"fmt"
"time"

"github.com/celestiaorg/celestia-node/header"
Expand Down Expand Up @@ -32,7 +31,6 @@ func (s *Service) findPruneableHeaders(ctx context.Context) ([]*header.ExtendedH
if err != nil {
return nil, err
}
fmt.Println("len(heaaders)", len(headers), "to: ", headers[len(headers)-1].Height())

// if our estimated range didn't cover enough headers, we need to fetch more
// TODO: This is really inefficient in the case that lastPruned is the default value, or if the
Expand Down
1 change: 0 additions & 1 deletion pruner/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ func (s *Service) prune(
log.Errorw("failed to find prune-able blocks", "error", err)
return lastPrunedHeader
}
fmt.Println("len(headers): ", len(headers), " to: ", headers[len(headers)-1].Height())

failed := make(map[uint64]error)

Expand Down
15 changes: 6 additions & 9 deletions pruner/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestService(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)

blockTime := time.Nanosecond * 50
blockTime := time.Millisecond

// all headers generated in suite are timestamped to time.Now(), so
// they will all be considered "pruneable" within the availability window (
Expand All @@ -43,26 +43,23 @@ func TestService(t *testing.T) {

serv := NewService(
mp,
AvailabilityWindow(time.Millisecond),
AvailabilityWindow(time.Millisecond*2),
store,
sync.MutexWrap(datastore.NewMapDatastore()),
blockTime,
WithGCCycle(time.Millisecond),
)

serv.ctx, serv.cancel = ctx, cancel

err := serv.loadCheckpoint(ctx)
require.NoError(t, err)
/*

lastPruned := serv.lastPruned()
lastPruned = serv.prune(ctx, lastPruned)
time.Sleep(time.Millisecond * 2)

assert.Equal(t, uint64(5), lastPruned)
assert.Equal(t, uint64(5), serv.checkpoint.LastPrunedHeight)
lastPruned := serv.prune(ctx, serv.lastPruned())

*/
assert.Greater(t, lastPruned.Height(), uint64(2))
assert.Greater(t, serv.checkpoint.LastPrunedHeight, uint64(2))
}

func TestService_RetryingFailed(t *testing.T) {
Expand Down

0 comments on commit a53cdc1

Please sign in to comment.