Skip to content

Commit

Permalink
testing:support parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
lochjin committed Dec 10, 2023
1 parent 7544fd8 commit 5458bda
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 0 deletions.
3 changes: 3 additions & 0 deletions meerdag/anticone/anticone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
)

func TestSigma(t *testing.T) {
t.Parallel()
k := 1
factor := 0.9
sum := 0.0
Expand All @@ -25,6 +26,7 @@ func TestSigma(t *testing.T) {
}

func TestAntiCone(t *testing.T) {
t.Parallel()
result := []int{12, 8, 6, 5, 4, 4, 4, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2}
index := 0
for i := 5; i < 100; i += 5 {
Expand All @@ -37,6 +39,7 @@ func TestAntiCone(t *testing.T) {
}

func TestShowParamsAntiCone(t *testing.T) {
t.Parallel()
rate := 1.0 / float64(params.TestNetParams.TargetTimePerBlock/time.Second)
fmt.Printf("testnet:%d\n", GetSize(BlockDelay, rate, SecurityLevel))

Expand Down
7 changes: 7 additions & 0 deletions meerdag/hashset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
)

func Test_Add(t *testing.T) {
t.Parallel()
hs := NewHashSet()
hs.Add(&hash.ZeroHash)

Expand All @@ -16,6 +17,7 @@ func Test_Add(t *testing.T) {
}

func Test_AddSet(t *testing.T) {
t.Parallel()
hs := NewHashSet()
other := NewHashSet()
other.Add(&hash.ZeroHash)
Expand All @@ -27,6 +29,7 @@ func Test_AddSet(t *testing.T) {
}

func Test_AddPair(t *testing.T) {
t.Parallel()
var intData int = 123
hs := NewHashSet()
hs.AddPair(&hash.ZeroHash, int(intData))
Expand All @@ -37,6 +40,7 @@ func Test_AddPair(t *testing.T) {
}

func Test_Remove(t *testing.T) {
t.Parallel()
hs := NewHashSet()
hs.Add(&hash.ZeroHash)
hs.Remove(&hash.ZeroHash)
Expand All @@ -47,6 +51,7 @@ func Test_Remove(t *testing.T) {
}

func Test_RemoveSet(t *testing.T) {
t.Parallel()
hs := NewHashSet()
other := NewHashSet()
other.Add(&hash.ZeroHash)
Expand All @@ -60,6 +65,7 @@ func Test_RemoveSet(t *testing.T) {
}

func Test_SortList(t *testing.T) {
t.Parallel()
hs := NewHashSet()
hl := HashSlice{}
var hashNum int = 5
Expand All @@ -86,6 +92,7 @@ func Test_SortList(t *testing.T) {
}

func Test_For(t *testing.T) {
t.Parallel()
hs := NewHashSet()
var hashNum int = 5
for i := 0; i < hashNum; i++ {
Expand Down
1 change: 1 addition & 0 deletions meerdag/hashslice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
)

func Test_Has(t *testing.T) {
t.Parallel()
hl := HashSlice{}
hl = append(hl, &hash.ZeroHash)

Expand Down
11 changes: 11 additions & 0 deletions meerdag/idset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
)

func Test_AddId(t *testing.T) {
t.Parallel()
hs := NewIdSet()
hs.Add(1)

Expand All @@ -26,6 +27,7 @@ func Test_AddId(t *testing.T) {
}

func Test_AddSetId(t *testing.T) {
t.Parallel()
hs := NewIdSet()
other := NewIdSet()
other.Add(1)
Expand All @@ -37,6 +39,7 @@ func Test_AddSetId(t *testing.T) {
}

func Test_AddPairId(t *testing.T) {
t.Parallel()
var intData int = 123
hs := NewIdSet()
hs.AddPair(1, int(intData))
Expand All @@ -47,6 +50,7 @@ func Test_AddPairId(t *testing.T) {
}

func Test_RemoveId(t *testing.T) {
t.Parallel()
hs := NewIdSet()
hs.Add(1)
hs.Remove(1)
Expand All @@ -57,6 +61,7 @@ func Test_RemoveId(t *testing.T) {
}

func Test_RemoveSetId(t *testing.T) {
t.Parallel()
hs := NewIdSet()
other := NewIdSet()
other.Add(1)
Expand All @@ -70,6 +75,7 @@ func Test_RemoveSetId(t *testing.T) {
}

func Test_SortListId(t *testing.T) {
t.Parallel()
hs := NewIdSet()
hl := IdSlice{}
var hashNum uint = 5
Expand All @@ -94,6 +100,7 @@ func Test_SortListId(t *testing.T) {
}

func Test_SortListHash(t *testing.T) {
t.Parallel()
hs := NewIdSet()
hl := BlockHashSlice{}
var hashNum uint = 5
Expand Down Expand Up @@ -121,6 +128,7 @@ func Test_SortListHash(t *testing.T) {
}

func Test_ForId(t *testing.T) {
t.Parallel()
hs := NewIdSet()
var hashNum uint = 5
for i := uint(0); i < hashNum; i++ {
Expand Down Expand Up @@ -163,6 +171,7 @@ func (tb *TestBlock) GetPriority() int {
}

func Test_SortListPriority(t *testing.T) {
t.Parallel()
hs := NewIdSet()
hl := BlockPrioritySlice{}
var hashNum uint = 5
Expand Down Expand Up @@ -191,6 +200,7 @@ func Test_SortListPriority(t *testing.T) {
}

func Test_SortListHeight(t *testing.T) {
t.Parallel()
hs := NewIdSet()
hl := BlockHeightSlice{}
var hashNum uint = 5
Expand Down Expand Up @@ -218,6 +228,7 @@ func Test_SortListHeight(t *testing.T) {
}

func TestIsDataEmpty(t *testing.T) {
t.Parallel()
hs := NewIdSet()
hs.Add(1)
hs.AddPair(2, int(2))
Expand Down
1 change: 1 addition & 0 deletions meerdag/idslice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
)

func Test_HasId(t *testing.T) {
t.Parallel()
hl := IdSlice{}
hl = append(hl, 0)

Expand Down
1 change: 1 addition & 0 deletions meerdag/spectrerisk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
)

func TestOnlineRiskInSpectre(t *testing.T) {
t.Parallel()
if scalar.EqualWithinAbs(GetRisk(300, 0.1, 10, 5, 10, 30), 0.1509544, tol) {
t.FailNow()
}
Expand Down
4 changes: 4 additions & 0 deletions node/service/serviceregistry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func (s *secondMockService) Status() error {
}

func TestRegisterService_Twice(t *testing.T) {
t.Parallel()
registry := &ServiceRegistry{
services: make(map[reflect.Type]IService),
}
Expand All @@ -72,6 +73,7 @@ func TestRegisterService_Twice(t *testing.T) {
}

func TestRegisterService_Different(t *testing.T) {
t.Parallel()
registry := &ServiceRegistry{
services: make(map[reflect.Type]IService),
}
Expand Down Expand Up @@ -100,6 +102,7 @@ func TestRegisterService_Different(t *testing.T) {
}

func TestFetchService_OK(t *testing.T) {
t.Parallel()
registry := &ServiceRegistry{
services: make(map[reflect.Type]IService),
}
Expand Down Expand Up @@ -129,6 +132,7 @@ func TestFetchService_OK(t *testing.T) {
}

func TestServiceStatus_OK(t *testing.T) {
t.Parallel()
registry := &ServiceRegistry{
services: make(map[reflect.Type]IService),
}
Expand Down
3 changes: 3 additions & 0 deletions p2p/qnode/idscheme_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var (
)

func TestEmptyNodeID(t *testing.T) {
t.Parallel()
var r qnr.Record
if addr := ValidSchemes.NodeAddr(&r); addr != nil {
t.Errorf("wrong address on empty record: got %v, want %v", addr, nil)
Expand All @@ -36,6 +37,7 @@ func TestEmptyNodeID(t *testing.T) {

// Checks that failure to sign leaves the record unmodified.
func TestSignError(t *testing.T) {
t.Parallel()
invalidKey := &ecdsa.PrivateKey{D: new(big.Int), PublicKey: *pubkey}

var r qnr.Record
Expand All @@ -51,6 +53,7 @@ func TestSignError(t *testing.T) {

// TestGetSetSecp256k1 tests encoding/decoding and setting/getting of the Secp256k1 key.
func TestGetSetSecp256k1(t *testing.T) {
t.Parallel()
var r qnr.Record
if err := SignV4(&r, privkey); err != nil {
t.Fatal(err)
Expand Down
8 changes: 8 additions & 0 deletions p2p/qnode/iter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ import (
)

func TestReadNodes(t *testing.T) {
t.Parallel()
nodes := ReadNodes(new(genIter), 10)
checkNodes(t, nodes, 10)
}

// This test checks that ReadNodes terminates when reading N nodes from an iterator
// which returns less than N nodes in an endless cycle.
func TestReadNodesCycle(t *testing.T) {
t.Parallel()
iter := &callCountIter{
Iterator: CycleNodes([]*Node{
testNode(0, 0),
Expand All @@ -37,6 +39,7 @@ func TestReadNodesCycle(t *testing.T) {
}

func TestFilterNodes(t *testing.T) {
t.Parallel()
nodes := make([]*Node, 100)
for i := range nodes {
nodes[i] = testNode(uint64(i), uint64(i))
Expand Down Expand Up @@ -80,6 +83,7 @@ func checkNodes(t *testing.T, nodes []*Node, wantLen int) {
// This test checks fairness of FairMix in the happy case where all sources return nodes
// within the context's deadline.
func TestFairMix(t *testing.T) {
t.Parallel()
for i := 0; i < 500; i++ {
testMixerFairness(t)
}
Expand Down Expand Up @@ -108,6 +112,7 @@ func testMixerFairness(t *testing.T) {
// This test checks that FairMix falls back to an alternative source when
// the 'fair' choice doesn't return a node within the timeout.
func TestFairMixNextFromAll(t *testing.T) {
t.Parallel()
mix := NewFairMix(1 * time.Millisecond)
mix.AddSource(&genIter{index: 1})
mix.AddSource(CycleNodes(nil))
Expand All @@ -124,6 +129,7 @@ func TestFairMixNextFromAll(t *testing.T) {

// This test ensures FairMix works for Next with no sources.
func TestFairMixEmpty(t *testing.T) {
t.Parallel()
var (
mix = NewFairMix(1 * time.Second)
testN = testNode(1, 1)
Expand All @@ -144,6 +150,7 @@ func TestFairMixEmpty(t *testing.T) {

// This test checks closing a source while Next runs.
func TestFairMixRemoveSource(t *testing.T) {
t.Parallel()
mix := NewFairMix(1 * time.Second)
source := make(blockingIter)
mix.AddSource(source)
Expand Down Expand Up @@ -187,6 +194,7 @@ func (it blockingIter) Close() {
}

func TestFairMixClose(t *testing.T) {
t.Parallel()
for i := 0; i < 20 && !t.Failed(); i++ {
testMixerClose(t)
}
Expand Down
3 changes: 3 additions & 0 deletions p2p/qnode/localnode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func newLocalNodeForTesting() (*LocalNode, *DB) {
}

func TestLocalNode(t *testing.T) {
t.Parallel()
ln, db := newLocalNodeForTesting()
defer db.Close()

Expand All @@ -38,6 +39,7 @@ func TestLocalNode(t *testing.T) {
}

func TestLocalNodeSeqPersist(t *testing.T) {
t.Parallel()
ln, db := newLocalNodeForTesting()
defer db.Close()

Expand Down Expand Up @@ -68,6 +70,7 @@ func TestLocalNodeSeqPersist(t *testing.T) {

// This test checks behavior of the endpoint predictor.
func TestLocalNodeEndpoint(t *testing.T) {
t.Parallel()
var (
fallback = &net.UDPAddr{IP: net.IP{127, 0, 0, 1}, Port: 80}
predicted = &net.UDPAddr{IP: net.IP{127, 0, 1, 2}, Port: 81}
Expand Down
7 changes: 7 additions & 0 deletions p2p/qnode/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var pyRecord, _ = hex.DecodeString("f884b8407098ad865b00a582051940cb9cf368365724
// TestPythonInterop checks that we can decode and verify a record produced by the Python
// implementation.
func TestPythonInterop(t *testing.T) {
t.Parallel()
var r qnr.Record
if err := rlp.DecodeBytes(pyRecord, &r); err != nil {
t.Fatalf("can't decode: %v", err)
Expand Down Expand Up @@ -53,6 +54,7 @@ func TestPythonInterop(t *testing.T) {
}

func TestHexID(t *testing.T) {
t.Parallel()
ref := ID{0, 0, 0, 0, 0, 0, 0, 128, 106, 217, 182, 31, 165, 174, 1, 67, 7, 235, 220, 150, 66, 83, 173, 205, 159, 44, 10, 57, 42, 161, 26, 188}
id1 := HexID("0x00000000000000806ad9b61fa5ae014307ebdc964253adcd9f2c0a392aa11abc")
id2 := HexID("00000000000000806ad9b61fa5ae014307ebdc964253adcd9f2c0a392aa11abc")
Expand All @@ -66,6 +68,7 @@ func TestHexID(t *testing.T) {
}

func TestID_textEncoding(t *testing.T) {
t.Parallel()
ref := ID{
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10,
0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x20,
Expand All @@ -92,6 +95,7 @@ func TestID_textEncoding(t *testing.T) {
}

func TestID_distcmp(t *testing.T) {
t.Parallel()
distcmpBig := func(target, a, b ID) int {
tbig := new(big.Int).SetBytes(target[:])
abig := new(big.Int).SetBytes(a[:])
Expand All @@ -106,6 +110,7 @@ func TestID_distcmp(t *testing.T) {
// The random tests is likely to miss the case where a and b are equal,
// this test checks it explicitly.
func TestID_distcmpEqual(t *testing.T) {
t.Parallel()
base := ID{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}
x := ID{15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}
if DistCmp(base, x, x) != 0 {
Expand All @@ -114,6 +119,7 @@ func TestID_distcmpEqual(t *testing.T) {
}

func TestID_logdist(t *testing.T) {
t.Parallel()
logdistBig := func(a, b ID) int {
abig, bbig := new(big.Int).SetBytes(a[:]), new(big.Int).SetBytes(b[:])
return new(big.Int).Xor(abig, bbig).BitLen()
Expand All @@ -126,6 +132,7 @@ func TestID_logdist(t *testing.T) {
// The random tests is likely to miss the case where a and b are equal,
// this test checks it explicitly.
func TestID_logdistEqual(t *testing.T) {
t.Parallel()
x := ID{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}
if LogDist(x, x) != 0 {
t.Errorf("LogDist(x, x) != 0")
Expand Down
Loading

0 comments on commit 5458bda

Please sign in to comment.