Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module github.com/ipfs/go-peertaskqueue
go 1.24.6

require (
github.com/filecoin-project/go-clock v0.1.0
github.com/ipfs/go-ipfs-pq v0.0.3
github.com/libp2p/go-libp2p v0.46.0
)
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ github.com/decred/dcrd/crypto/blake256 v1.1.0 h1:zPMNGQCm0g4QTY27fOCorQW7EryeQ/U
github.com/decred/dcrd/crypto/blake256 v1.1.0/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 h1:NMZiJj8QnKe1LgsbDayM4UoHwbvwDRwnI3hwNaAHRnc=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0/go.mod h1:ZXNYxsqcloTdSy/rNShjYzMhyjf0LaoftYK0p+A3h40=
github.com/filecoin-project/go-clock v0.1.0 h1:SFbYIM75M8NnFm1yMHhN9Ahy3W5bEZV9gd6MPfXbKVU=
github.com/filecoin-project/go-clock v0.1.0/go.mod h1:4uB/O4PvOjlx1VCMdZ9MyDZXRm//gkj1ELEbxfI1AZs=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/ipfs/go-cid v0.5.0 h1:goEKKhaGm0ul11IHA7I6p1GmKz8kEYniqFopaB5Otwg=
Expand Down
2 changes: 2 additions & 0 deletions peertaskqueue_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build go1.25

package peertaskqueue

import (
Expand Down
6 changes: 2 additions & 4 deletions peertracker/peertracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ import (
"math"
"math/bits"
"sync"
"time"

"github.com/filecoin-project/go-clock"
pq "github.com/ipfs/go-ipfs-pq"
"github.com/ipfs/go-peertaskqueue/peertask"
"github.com/libp2p/go-libp2p/core/peer"
)

var clockInstance = clock.New()

// TaskMerger is an interface that is used to merge new tasks into the active
// and pending queues
type TaskMerger interface {
Expand Down Expand Up @@ -214,7 +212,7 @@ func (p *PeerTracker) PushTasks(tasks ...peertask.Task) {
// When truncation happen we will keep older tasks in the queue to avoid some infinite
// tasks rotations if we are continously receiving work faster than we process it.
func (p *PeerTracker) PushTasksTruncated(n uint, tasks ...peertask.Task) {
now := clockInstance.Now()
now := time.Now()

p.activelk.Lock()
defer p.activelk.Unlock()
Expand Down
106 changes: 52 additions & 54 deletions peertracker/peertracker_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
//go:build go1.25

package peertracker

import (
"reflect"
"sort"
"testing"
"testing/synctest"
"time"

"github.com/filecoin-project/go-clock"
"github.com/ipfs/go-peertaskqueue/peertask"
"github.com/ipfs/go-peertaskqueue/testutil"
)
Expand Down Expand Up @@ -670,58 +672,54 @@ func TestRemoveActive(t *testing.T) {
}

func TestPushPopEqualTaskPriorities(t *testing.T) {
partner := testutil.GeneratePeers(1)[0]
clock := clock.NewMock()
oldClock := clockInstance
clockInstance = clock
t.Cleanup(func() {
clockInstance = oldClock
synctest.Test(t, func(t *testing.T) {
partner := testutil.GeneratePeers(1)[0]
tracker := New(partner, &DefaultTaskMerger{}, 1)

tasks := []peertask.Task{
{
Topic: "1",
Priority: 10,
Work: 1,
},
{
Topic: "2",
Priority: 10,
Work: 1,
},
{
Topic: "3",
Priority: 10,
Work: 1,
},
}
tracker.PushTasks(tasks[0])
time.Sleep(10 * time.Millisecond)
tracker.PushTasks(tasks[1])
time.Sleep(10 * time.Millisecond)
tracker.PushTasks(tasks[2])
popped, _ := tracker.PopTasks(1)
if len(popped) != 1 {
t.Fatal("Expected 1 task")
}
if popped[0].Topic != "1" {
t.Fatal("Expected first task")
}
tracker.TaskDone(popped[0])
popped, _ = tracker.PopTasks(1)
if len(popped) != 1 {
t.Fatal("Expected 1 task")
}
if popped[0].Topic != "2" {
t.Fatal("Expected second task")
}
tracker.TaskDone(popped[0])
popped, _ = tracker.PopTasks(1)
if len(popped) != 1 {
t.Fatal("Expected 1 task")
}
if popped[0].Topic != "3" {
t.Fatal("Expected third task")
}
})
tracker := New(partner, &DefaultTaskMerger{}, 1)

tasks := []peertask.Task{
{
Topic: "1",
Priority: 10,
Work: 1,
},
{
Topic: "2",
Priority: 10,
Work: 1,
},
{
Topic: "3",
Priority: 10,
Work: 1,
},
}
tracker.PushTasks(tasks[0])
clock.Add(10 * time.Millisecond)
tracker.PushTasks(tasks[1])
clock.Add(10 * time.Millisecond)
tracker.PushTasks(tasks[2])
popped, _ := tracker.PopTasks(1)
if len(popped) != 1 {
t.Fatal("Expected 1 task")
}
if popped[0].Topic != "1" {
t.Fatal("Expected first task")
}
tracker.TaskDone(popped[0])
popped, _ = tracker.PopTasks(1)
if len(popped) != 1 {
t.Fatal("Expected 1 task")
}
if popped[0].Topic != "2" {
t.Fatal("Expected second task")
}
tracker.TaskDone(popped[0])
popped, _ = tracker.PopTasks(1)
if len(popped) != 1 {
t.Fatal("Expected 1 task")
}
if popped[0].Topic != "3" {
t.Fatal("Expected third task")
}
}