Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Commit

Permalink
fix: make blockstore cancel test less timing dependent
Browse files Browse the repository at this point in the history
1. More blocks so we have more time.
2. Lock less.
3. Put without the delay (so we can put more blocks without slowing
things down).
  • Loading branch information
Stebalien committed Jun 24, 2021
1 parent 5f2fd63 commit a45ff1b
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions internal/decision/blockstoremanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,20 +224,22 @@ func TestBlockstoreManagerCtxDone(t *testing.T) {
delayTime := 20 * time.Millisecond
bsdelay := delay.Fixed(delayTime)

dstore := ds_sync.MutexWrap(delayed.New(ds.NewMapDatastore(), bsdelay))
bstore := blockstore.NewBlockstore(ds_sync.MutexWrap(dstore))
underlyingDstore := ds_sync.MutexWrap(ds.NewMapDatastore())
dstore := delayed.New(underlyingDstore, bsdelay)
underlyingBstore := blockstore.NewBlockstore(underlyingDstore)
bstore := blockstore.NewBlockstore(dstore)

bsm := newBlockstoreManager(bstore, 3)
proc := process.WithTeardown(func() error { return nil })
bsm.start(proc)

blks := testutil.GenerateBlocksOfSize(10, 1024)
blks := testutil.GenerateBlocksOfSize(100, 128)
var ks []cid.Cid
for _, b := range blks {
ks = append(ks, b.Cid())
}

err := bstore.PutMany(blks)
err := underlyingBstore.PutMany(blks)
if err != nil {
t.Fatal(err)
}
Expand All @@ -251,8 +253,8 @@ func TestBlockstoreManagerCtxDone(t *testing.T) {
t.Error("expected an error")
}

// would expect to wait delayTime*10 if we didn't cancel.
if time.Since(before) > delayTime*2 {
// would expect to wait delayTime*100/3 if we didn't cancel.
if time.Since(before) > delayTime*10 {
t.Error("expected a fast timeout")
}
}

0 comments on commit a45ff1b

Please sign in to comment.