kaspad/testing/integration/64_incoming_connections_test.go
stasatdaglabs d14809694f
[NOD-1223] Reorganize directory structure (#874)
* [NOD-1223] Delete unused files/packages.

* [NOD-1223] Move signal and limits to the os package.

* [NOD-1223] Put database and dbaccess into the db package.

* [NOD-1223] Fold the logs package into the logger package.

* [NOD-1223] Rename domainmessage to appmessage.

* [NOD-1223] Rename to/from DomainMessage to AppMessage.

* [NOD-1223] Move appmessage to the app packge.

* [NOD-1223] Move protocol to the app packge.

* [NOD-1223] Move the network package to the infrastructure packge.

* [NOD-1223] Rename cmd to executables.

* [NOD-1223] Fix go.doc in the logger package.
2020-08-18 10:26:39 +03:00

62 lines
1.5 KiB
Go

package integration
import (
"fmt"
"sync"
"testing"
"time"
"github.com/kaspanet/kaspad/util/locks"
"github.com/kaspanet/kaspad/app/appmessage"
)
func Test64IncomingConnections(t *testing.T) {
// Much more than 64 hosts creates a risk of running out of available file descriptors for leveldb
const numBullies = 64
harnessesParams := make([]*harnessParams, numBullies+1)
for i := 0; i < numBullies+1; i++ {
harnessesParams[i] = &harnessParams{
p2pAddress: fmt.Sprintf("127.0.0.1:%d", 12345+i),
rpcAddress: fmt.Sprintf("127.0.0.1:%d", 22345+i),
miningAddress: miningAddress1,
miningAddressPrivateKey: miningAddress1PrivateKey,
}
}
appHarnesses, teardown := setupHarnesses(t, harnessesParams)
defer teardown()
victim, bullies := appHarnesses[0], appHarnesses[1:]
for _, bully := range bullies {
connect(t, victim, bully)
}
blockAddedWG := sync.WaitGroup{}
blockAddedWG.Add(numBullies)
for _, bully := range bullies {
err := bully.rpcClient.NotifyBlocks()
if err != nil {
t.Fatalf("Error from NotifyBlocks: %+v", err)
}
blockAdded := false
bully.rpcClient.onBlockAdded = func(header *appmessage.BlockHeader) {
if blockAdded {
t.Fatalf("Single bully reported block added twice")
}
blockAdded = true
blockAddedWG.Done()
}
}
_ = mineNextBlock(t, victim)
select {
case <-time.After(defaultTimeout):
t.Fatalf("Timeout waiting for block added notification from the bullies")
case <-locks.ReceiveFromChanWhenDone(func() { blockAddedWG.Wait() }):
}
}