Skip to content

Commit

Permalink
les/vflux: run tests in parallel (ethereum#28524)
Browse files Browse the repository at this point in the history
  • Loading branch information
estensen authored and Dergarcon committed Jan 31, 2024
1 parent a2878b6 commit 9d2cc00
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 7 deletions.
2 changes: 2 additions & 0 deletions les/vflux/client/fillset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ func (i *testIter) waiting(timeout time.Duration) bool {
}

func TestFillSet(t *testing.T) {
t.Parallel()

ns := nodestate.NewNodeStateMachine(nil, nil, &mclock.Simulated{}, testSetup)
iter := &testIter{
waitCh: make(chan struct{}),
Expand Down
4 changes: 4 additions & 0 deletions les/vflux/client/queueiterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ func testNode(i int) *enode.Node {
}

func TestQueueIteratorFIFO(t *testing.T) {
t.Parallel()

testQueueIterator(t, true)
}

func TestQueueIteratorLIFO(t *testing.T) {
t.Parallel()

testQueueIterator(t, false)
}

Expand Down
10 changes: 10 additions & 0 deletions les/vflux/client/requestbasket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ func checkF64(t *testing.T, name string, value, exp, tol float64) {
}

func TestServerBasket(t *testing.T) {
t.Parallel()

var s serverBasket
s.init(2)
// add some requests with different request value factors
Expand Down Expand Up @@ -70,6 +72,8 @@ func TestServerBasket(t *testing.T) {
}

func TestConvertMapping(t *testing.T) {
t.Parallel()

b := requestBasket{items: []basketItem{{3, 3}, {1, 1}, {2, 2}}}
oldMap := []string{"req3", "req1", "req2"}
newMap := []string{"req1", "req2", "req3", "req4"}
Expand All @@ -82,6 +86,8 @@ func TestConvertMapping(t *testing.T) {
}

func TestReqValueFactor(t *testing.T) {
t.Parallel()

var ref referenceBasket
ref.basket = requestBasket{items: make([]basketItem, 4)}
for i := range ref.basket.items {
Expand All @@ -95,6 +101,8 @@ func TestReqValueFactor(t *testing.T) {
}

func TestNormalize(t *testing.T) {
t.Parallel()

for cycle := 0; cycle < 100; cycle += 1 {
// Initialize data for testing
valueRange, lower := 1000000, 1000000
Expand All @@ -119,6 +127,8 @@ func TestNormalize(t *testing.T) {
}

func TestReqValueAdjustment(t *testing.T) {
t.Parallel()

var s1, s2 serverBasket
s1.init(3)
s2.init(3)
Expand Down
46 changes: 39 additions & 7 deletions les/vflux/client/serverpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,21 @@ func (s *ServerPoolTest) checkNodes(t *testing.T, nodes []int) {
}
}

func TestServerPool(t *testing.T) { testServerPool(t, false, false) }
func TestServerPoolWithPreNeg(t *testing.T) { testServerPool(t, true, false) }
func TestServerPoolWithPreNegFail(t *testing.T) { testServerPool(t, true, true) }
func TestServerPool(t *testing.T) {
t.Parallel()

testServerPool(t, false, false)
}
func TestServerPoolWithPreNeg(t *testing.T) {
t.Parallel()

testServerPool(t, true, false)
}
func TestServerPoolWithPreNegFail(t *testing.T) {
t.Parallel()

testServerPool(t, true, true)
}
func testServerPool(t *testing.T, preNeg, fail bool) {
s := newServerPoolTest(preNeg, fail)
nodes := s.setNodes(100, 200, 200, true, false)
Expand All @@ -339,8 +351,16 @@ func testServerPool(t *testing.T, preNeg, fail bool) {
s.checkNodes(t, nodes)
}

func TestServerPoolChangedNodes(t *testing.T) { testServerPoolChangedNodes(t, false) }
func TestServerPoolChangedNodesWithPreNeg(t *testing.T) { testServerPoolChangedNodes(t, true) }
func TestServerPoolChangedNodes(t *testing.T) {
t.Parallel()

testServerPoolChangedNodes(t, false)
}
func TestServerPoolChangedNodesWithPreNeg(t *testing.T) {
t.Parallel()

testServerPoolChangedNodes(t, true)
}
func testServerPoolChangedNodes(t *testing.T, preNeg bool) {
s := newServerPoolTest(preNeg, false)
nodes := s.setNodes(100, 200, 200, true, false)
Expand All @@ -358,8 +378,14 @@ func testServerPoolChangedNodes(t *testing.T, preNeg bool) {
s.stop()
}

func TestServerPoolRestartNoDiscovery(t *testing.T) { testServerPoolRestartNoDiscovery(t, false) }
func TestServerPoolRestartNoDiscovery(t *testing.T) {
t.Parallel()

testServerPoolRestartNoDiscovery(t, false)
}
func TestServerPoolRestartNoDiscoveryWithPreNeg(t *testing.T) {
t.Parallel()

testServerPoolRestartNoDiscovery(t, true)
}
func testServerPoolRestartNoDiscovery(t *testing.T, preNeg bool) {
Expand All @@ -377,8 +403,14 @@ func testServerPoolRestartNoDiscovery(t *testing.T, preNeg bool) {
s.checkNodes(t, nodes)
}

func TestServerPoolTrustedNoDiscovery(t *testing.T) { testServerPoolTrustedNoDiscovery(t, false) }
func TestServerPoolTrustedNoDiscovery(t *testing.T) {
t.Parallel()

testServerPoolTrustedNoDiscovery(t, false)
}
func TestServerPoolTrustedNoDiscoveryWithPreNeg(t *testing.T) {
t.Parallel()

testServerPoolTrustedNoDiscovery(t, true)
}
func testServerPoolTrustedNoDiscovery(t *testing.T, preNeg bool) {
Expand Down
8 changes: 8 additions & 0 deletions les/vflux/client/timestats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
)

func TestTransition(t *testing.T) {
t.Parallel()

var epsilon = 0.01
var cases = []time.Duration{
time.Millisecond, minResponseTime,
Expand All @@ -47,6 +49,8 @@ func TestTransition(t *testing.T) {
var maxResponseWeights = TimeoutWeights(maxResponseTime)

func TestValue(t *testing.T) {
t.Parallel()

noexp := utils.ExpirationFactor{Factor: 1}
for i := 0; i < 1000; i++ {
max := minResponseTime + time.Duration(rand.Int63n(int64(maxResponseTime-minResponseTime)))
Expand All @@ -70,6 +74,8 @@ func TestValue(t *testing.T) {
}

func TestAddSubExpire(t *testing.T) {
t.Parallel()

var (
sum1, sum2 ResponseTimeStats
sum1ValueExp, sum2ValueExp float64
Expand Down Expand Up @@ -110,6 +116,8 @@ func TestAddSubExpire(t *testing.T) {
}

func TestTimeout(t *testing.T) {
t.Parallel()

testTimeoutRange(t, 0, time.Second)
testTimeoutRange(t, time.Second, time.Second*2)
testTimeoutRange(t, time.Second, maxResponseTime)
Expand Down
2 changes: 2 additions & 0 deletions les/vflux/client/valuetracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ const (
)

func TestValueTracker(t *testing.T) {
t.Parallel()

db := memorydb.New()
clock := &mclock.Simulated{}
requestList := make([]RequestInfo, testReqTypes)
Expand Down
2 changes: 2 additions & 0 deletions les/vflux/client/wrsiterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ var (
const iterTestNodeCount = 6

func TestWrsIterator(t *testing.T) {
t.Parallel()

ns := nodestate.NewNodeStateMachine(nil, nil, &mclock.Simulated{}, testSetup)
w := NewWrsIterator(ns, sfTest2, sfTest3.Or(sfTest4), sfiTestWeight)
ns.Start()
Expand Down
20 changes: 20 additions & 0 deletions les/vflux/server/balance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ func (b *balanceTestSetup) stop() {
}

func TestAddBalance(t *testing.T) {
t.Parallel()

b := newBalanceTestSetup(nil, nil, nil)
defer b.stop()

Expand Down Expand Up @@ -143,6 +145,8 @@ func TestAddBalance(t *testing.T) {
}

func TestSetBalance(t *testing.T) {
t.Parallel()

b := newBalanceTestSetup(nil, nil, nil)
defer b.stop()
node := b.newNode(1000)
Expand All @@ -167,6 +171,8 @@ func TestSetBalance(t *testing.T) {
}

func TestBalanceTimeCost(t *testing.T) {
t.Parallel()

b := newBalanceTestSetup(nil, nil, nil)
defer b.stop()
node := b.newNode(1000)
Expand Down Expand Up @@ -207,6 +213,8 @@ func TestBalanceTimeCost(t *testing.T) {
}

func TestBalanceReqCost(t *testing.T) {
t.Parallel()

b := newBalanceTestSetup(nil, nil, nil)
defer b.stop()
node := b.newNode(1000)
Expand Down Expand Up @@ -235,6 +243,8 @@ func TestBalanceReqCost(t *testing.T) {
}

func TestBalanceToPriority(t *testing.T) {
t.Parallel()

b := newBalanceTestSetup(nil, nil, nil)
defer b.stop()
node := b.newNode(1000)
Expand All @@ -260,6 +270,8 @@ func TestBalanceToPriority(t *testing.T) {
}

func TestEstimatedPriority(t *testing.T) {
t.Parallel()

b := newBalanceTestSetup(nil, nil, nil)
defer b.stop()
node := b.newNode(1000000000)
Expand Down Expand Up @@ -299,6 +311,8 @@ func TestEstimatedPriority(t *testing.T) {
}

func TestPositiveBalanceCounting(t *testing.T) {
t.Parallel()

b := newBalanceTestSetup(nil, nil, nil)
defer b.stop()

Expand Down Expand Up @@ -340,6 +354,8 @@ func TestPositiveBalanceCounting(t *testing.T) {
}

func TestCallbackChecking(t *testing.T) {
t.Parallel()

b := newBalanceTestSetup(nil, nil, nil)
defer b.stop()
node := b.newNode(1000000)
Expand All @@ -363,6 +379,8 @@ func TestCallbackChecking(t *testing.T) {
}

func TestCallback(t *testing.T) {
t.Parallel()

b := newBalanceTestSetup(nil, nil, nil)
defer b.stop()
node := b.newNode(1000)
Expand Down Expand Up @@ -392,6 +410,8 @@ func TestCallback(t *testing.T) {
}

func TestBalancePersistence(t *testing.T) {
t.Parallel()

posExp := &utils.Expirer{}
negExp := &utils.Expirer{}
posExp.SetRate(0, math.Log(2)/float64(time.Hour*2)) // halves every two hours
Expand Down
4 changes: 4 additions & 0 deletions les/vflux/server/clientdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ func expval(v uint64) utils.ExpiredValue {
}

func TestNodeDB(t *testing.T) {
t.Parallel()

ndb := newNodeDB(rawdb.NewMemoryDatabase(), mclock.System{})
defer ndb.close()

Expand Down Expand Up @@ -85,6 +87,8 @@ func TestNodeDB(t *testing.T) {
}

func TestNodeDBExpiration(t *testing.T) {
t.Parallel()

var (
iterated int
done = make(chan struct{}, 1)
Expand Down
Loading

0 comments on commit 9d2cc00

Please sign in to comment.