Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix TestDealPublisher #7173

Merged
merged 2 commits into from
Aug 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions markets/storageadapter/dealpublisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,15 @@ func (p *DealPublisher) waitForMoreDeals() {
// Set a timeout to wait for more deals to arrive
log.Infof("waiting publish deals queue period of %s before publishing", p.publishPeriod)
ctx, cancel := context.WithCancel(p.ctx)

// Create the timer _before_ taking the current time so publishPeriod+timeout is always >=
// the actual timer timeout.
timer := build.Clock.Timer(p.publishPeriod)

p.publishPeriodStart = build.Clock.Now()
p.cancelWaitForMoreDeals = cancel

go func() {
timer := build.Clock.Timer(p.publishPeriod)
select {
case <-ctx.Done():
timer.Stop()
Expand All @@ -257,7 +261,7 @@ func (p *DealPublisher) publishAllDeals() {

// Filter out any deals that have been cancelled
p.filterCancelledDeals()
deals := p.pending[:]
deals := p.pending
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also a drive-by fix. There's no need to do this unless p.pending is an array.

p.pending = nil

// Send the publish message
Expand Down Expand Up @@ -384,12 +388,12 @@ func pieceCids(deals []market2.ClientDealProposal) string {

// filter out deals that have been cancelled
func (p *DealPublisher) filterCancelledDeals() {
i := 0
filtered := p.pending[:0]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was just a drive-by fix to make the logic here easier to reason about.

for _, pd := range p.pending {
if pd.ctx.Err() == nil {
p.pending[i] = pd
i++
if pd.ctx.Err() != nil {
continue
}
filtered = append(filtered, pd)
}
p.pending = p.pending[:i]
p.pending = filtered
}