Skip to content

eth/downloader: enhanced test cases for downloader queue #22114

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

Merged
merged 1 commit into from
Jan 5, 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
44 changes: 35 additions & 9 deletions eth/downloader/queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ func dummyPeer(id string) *peerConnection {
}

func TestBasics(t *testing.T) {
numOfBlocks := len(emptyChain.blocks)
numOfReceipts := len(emptyChain.blocks) / 2

q := newQueue(10, 10)
if !q.Idle() {
t.Errorf("new queue should be idle")
Expand Down Expand Up @@ -135,6 +138,12 @@ func TestBasics(t *testing.T) {
t.Fatalf("expected header %d, got %d", exp, got)
}
}
if exp, got := q.blockTaskQueue.Size(), numOfBlocks-10; exp != got {
t.Errorf("expected block task queue to be %d, got %d", exp, got)
}
if exp, got := q.receiptTaskQueue.Size(), numOfReceipts; exp != got {
t.Errorf("expected receipt task queue to be %d, got %d", exp, got)
}
{
peer := dummyPeer("peer-2")
fetchReq, _, throttle := q.ReserveBodies(peer, 50)
Expand All @@ -148,8 +157,12 @@ func TestBasics(t *testing.T) {
t.Fatalf("should have no fetches, got %d", len(fetchReq.Headers))
}
}
//fmt.Printf("blockTaskQueue len: %d\n", q.blockTaskQueue.Size())
//fmt.Printf("receiptTaskQueue len: %d\n", q.receiptTaskQueue.Size())
if exp, got := q.blockTaskQueue.Size(), numOfBlocks-10; exp != got {
t.Errorf("expected block task queue to be %d, got %d", exp, got)
}
if exp, got := q.receiptTaskQueue.Size(), numOfReceipts; exp != got {
t.Errorf("expected receipt task queue to be %d, got %d", exp, got)
}
{
// The receipt delivering peer should not be affected
// by the throttling of body deliveries
Expand All @@ -168,12 +181,20 @@ func TestBasics(t *testing.T) {
}

}
//fmt.Printf("blockTaskQueue len: %d\n", q.blockTaskQueue.Size())
//fmt.Printf("receiptTaskQueue len: %d\n", q.receiptTaskQueue.Size())
//fmt.Printf("processable: %d\n", q.resultCache.countCompleted())
if exp, got := q.blockTaskQueue.Size(), numOfBlocks-10; exp != got {
t.Errorf("expected block task queue to be %d, got %d", exp, got)
}
if exp, got := q.receiptTaskQueue.Size(), numOfReceipts-5; exp != got {
t.Errorf("expected receipt task queue to be %d, got %d", exp, got)
}
if got, exp := q.resultCache.countCompleted(), 0; got != exp {
t.Errorf("wrong processable count, got %d, exp %d", got, exp)
}
}

func TestEmptyBlocks(t *testing.T) {
numOfBlocks := len(emptyChain.blocks)

q := newQueue(10, 10)

q.Prepare(1, FastSync)
Expand Down Expand Up @@ -208,13 +229,12 @@ func TestEmptyBlocks(t *testing.T) {
}

}
if q.blockTaskQueue.Size() != len(emptyChain.blocks)-10 {
t.Errorf("expected block task queue to be 0, got %d", q.blockTaskQueue.Size())
if q.blockTaskQueue.Size() != numOfBlocks-10 {
t.Errorf("expected block task queue to be %d, got %d", numOfBlocks-10, q.blockTaskQueue.Size())
}
if q.receiptTaskQueue.Size() != 0 {
t.Errorf("expected receipt task queue to be 0, got %d", q.receiptTaskQueue.Size())
t.Errorf("expected receipt task queue to be %d, got %d", 0, q.receiptTaskQueue.Size())
}
//fmt.Printf("receiptTaskQueue len: %d\n", q.receiptTaskQueue.Size())
{
peer := dummyPeer("peer-3")
fetchReq, _, _ := q.ReserveReceipts(peer, 50)
Expand All @@ -224,6 +244,12 @@ func TestEmptyBlocks(t *testing.T) {
t.Fatal("there should be no body fetch tasks remaining")
}
}
if q.blockTaskQueue.Size() != numOfBlocks-10 {
t.Errorf("expected block task queue to be %d, got %d", numOfBlocks-10, q.blockTaskQueue.Size())
}
if q.receiptTaskQueue.Size() != 0 {
t.Errorf("expected receipt task queue to be %d, got %d", 0, q.receiptTaskQueue.Size())
}
if got, exp := q.resultCache.countCompleted(), 10; got != exp {
t.Errorf("wrong processable count, got %d, exp %d", got, exp)
}
Expand Down