Skip to content

Commit

Permalink
refactor test to confirm priority
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardmack committed Sep 8, 2022
1 parent f019de2 commit 3a80f62
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions lib/transaction/priority_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,20 +278,38 @@ func TestPopChannel(t *testing.T) {
slotTimer := time.NewTimer(time.Second)

popChan := pq.PopChannel(slotTimer)
tests := []*ValidTransaction{
{
Extrinsic: []byte("a"),
Validity: &Validity{Priority: 1},
},
{
Extrinsic: []byte("b"),
Validity: &Validity{Priority: 4},
},
{
Extrinsic: []byte("c"),
Validity: &Validity{Priority: 2},
},
{
Extrinsic: []byte("d"),
Validity: &Validity{Priority: 17},
},
{
Extrinsic: []byte("e"),
Validity: &Validity{Priority: 2},
},
}

go func() {
counter := 0
for {
time.Sleep(time.Millisecond * 100)
pq.Push(&ValidTransaction{Validity: &Validity{Priority: uint64(counter)}})
counter++
}
}()
expected := []int{3, 1, 2, 4, 0}

for _, test := range tests {
pq.Push(test)
}

counter := 0
for txn := range popChan {
assert.Equal(t, uint64(counter), txn.Validity.Priority)
assert.Equal(t, tests[expected[counter]], txn)
counter++
}
assert.Equal(t, 9, counter)
}

0 comments on commit 3a80f62

Please sign in to comment.