Skip to content

Commit

Permalink
Network test fix: assert on number of completed rollback TXs (#947)
Browse files Browse the repository at this point in the history
* Assert on number of rollbacks instead of number of active rollback TXs


Co-authored-by: Rein Krul <[email protected]>
  • Loading branch information
reinkrul and reinkrul authored Apr 6, 2022
1 parent 1602a7f commit 710253d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 3 additions & 0 deletions network/dag/bbolt_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type bboltTree struct {
bucketName string
tree tree.Tree
activeRollbackRoutines *uint32
numRollbacks *uint32
}

// newBBoltTreeStore returns an instance of a BBolt based tree store. Buckets managed by this store are filled to treeBucketFillPercent
Expand All @@ -60,6 +61,7 @@ func newBBoltTreeStore(db *bbolt.DB, bucketName string, tree tree.Tree) *bboltTr
bucketName: bucketName,
tree: tree,
activeRollbackRoutines: new(uint32),
numRollbacks: new(uint32),
}
}

Expand Down Expand Up @@ -98,6 +100,7 @@ func (store *bboltTree) dagObserver(ctx context.Context, transaction Transaction
if err == context.DeadlineExceeded {
log.Logger().Warnf("deadline exceeded - rollback transaction %s from %s", transaction.Ref(), store.bucketName)
store.tree.Delete(transaction.Ref(), transaction.Clock())
atomic.AddUint32(store.numRollbacks, 1)
}
}()
tx.OnCommit(func() {
Expand Down
3 changes: 2 additions & 1 deletion network/dag/bbolt_tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,12 @@ func TestBboltTree_dagObserver(t *testing.T) {
observerRollbackTimeOut = defaultObserverRollbackTimeOut
}()

assert.Equal(t, uint32(0), atomic.LoadUint32(store.numRollbacks))
store.dagObserver(ctx, tx, nil)
assert.Equal(t, tx.Ref(), store.getRoot().(*tree.Xor).Hash())

test.WaitFor(t, func() (bool, error) {
return atomic.LoadUint32(store.activeRollbackRoutines) == 0, nil
return atomic.LoadUint32(store.numRollbacks) == 1, nil
}, 5*time.Second, "timeout while waiting for go routine to exit")
assert.Equal(t, hash.EmptyHash(), store.getRoot().(*tree.Xor).Hash())

Expand Down
6 changes: 4 additions & 2 deletions network/transport/grpc/outbound_connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ func Test_connector_start(t *testing.T) {

<-connected // wait for connected

resetCounts, _ := bo.counts()
assert.Equal(t, 1, resetCounts)
test.WaitFor(t, func() (bool, error) {
resetCounts, _ := bo.counts()
return resetCounts == 1, nil
}, 5 * time.Second, "waiting for backoff.Reset() to be called")
})
t.Run("not connecting when already connected", func(t *testing.T) {
calls := make(chan struct{}, 10)
Expand Down

0 comments on commit 710253d

Please sign in to comment.