mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-17 04:11:37 +00:00
triedb/pathdb: fix broken test
This commit is contained in:
parent
902c680a83
commit
27abe09b32
1 changed files with 12 additions and 12 deletions
|
|
@ -271,32 +271,32 @@ func TestPrunePauseResume(t *testing.T) {
|
||||||
|
|
||||||
tail := firstBlockMax + 1
|
tail := firstBlockMax + 1
|
||||||
|
|
||||||
// Construct the pruner without starting run(). Calling process()
|
// Construct the pruner without starting run(). We call process()
|
||||||
// directly while run() is active would race: both run()'s main select
|
// directly to exercise the mid-iteration pause path deterministically.
|
||||||
// and prunePrefix's select listen on pauseReq. If run() receives it
|
|
||||||
// (idle ack), process() runs unpaused and can overwrite data with a
|
|
||||||
// stale iterator snapshot.
|
|
||||||
pruner := &indexPruner{
|
pruner := &indexPruner{
|
||||||
disk: db,
|
disk: db,
|
||||||
typ: typeStateHistory,
|
typ: typeStateHistory,
|
||||||
log: log.New("type", "account"),
|
log: log.New("type", "account"),
|
||||||
closed: make(chan struct{}),
|
closed: make(chan struct{}),
|
||||||
pauseReq: make(chan chan struct{}),
|
pauseReq: make(chan chan struct{}, 1), // buffered so we can pre-deposit
|
||||||
resumeCh: make(chan struct{}),
|
resumeCh: make(chan struct{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pre-deposit a pause request before process() starts. Because
|
||||||
|
// pauseReq is buffered, this succeeds immediately. When prunePrefix's
|
||||||
|
// select checks the channel on an early iteration, it will find the
|
||||||
|
// pending request and pause — no scheduling race is possible.
|
||||||
|
ack := make(chan struct{})
|
||||||
|
pruner.pauseReq <- ack
|
||||||
|
|
||||||
// Run process() in the background.
|
// Run process() in the background.
|
||||||
errCh := make(chan error, 1)
|
errCh := make(chan error, 1)
|
||||||
go func() {
|
go func() {
|
||||||
errCh <- pruner.process(tail)
|
errCh <- pruner.process(tail)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Pause — blocks until the pruner has flushed pending writes and
|
// Block until the pruner has flushed pending writes and acknowledged.
|
||||||
// acknowledged. Because pauseReq is unbuffered, the send in pause()
|
<-ack
|
||||||
// blocks until prunePrefix's select receives it; the pruner checks
|
|
||||||
// the channel on every iteration, so this always succeeds before
|
|
||||||
// the iterator is exhausted.
|
|
||||||
pruner.pause()
|
|
||||||
|
|
||||||
// While paused, append a new element to the target account's index,
|
// While paused, append a new element to the target account's index,
|
||||||
// simulating what indexSingle would do during the pause window.
|
// simulating what indexSingle would do during the pause window.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue