eth/downloader: enhanced test cases for downloader queue (#22114)
This commit is contained in:
parent
9ba306d47e
commit
618454214b
@ -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")
|
||||
@ -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)
|
||||
@ -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
|
||||
@ -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)
|
||||
@ -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)
|
||||
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user