Skip to content

Commit

Permalink
p2p/requestManager tests
Browse files Browse the repository at this point in the history
  • Loading branch information
didaunesp committed Sep 3, 2024
1 parent 109b12b commit 23fff98
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions p2p/node/requestManager/requestManager_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package requestManager

import (
"sync"
"testing"

"github.com/stretchr/testify/require"
)

func TestRequestManager(t *testing.T) {
rm := NewManager()

doTestRM(t, rm)
}

func TestMultipleRequestManager(t *testing.T) {
rm := NewManager()
var wg sync.WaitGroup

for i := 0; i < 50; i++ {
wg.Add(1)
go func() {
defer wg.Done()
doTestRM(t, rm)
}()
}

for i := 0; i < 50; i++ {
wg.Add(1)
go func() {
defer wg.Done()
doTestRM(t, rm)
}()
}

for i := 0; i < 50; i++ {
wg.Add(1)
go func() {
defer wg.Done()
doTestRM(t, rm)
}()
}

wg.Wait()
}

func doTestRM(t *testing.T, rm RequestManager) {
id := rm.CreateRequest()
require.NotZero(t, id, "Request ID should not be zero")

dataChan, err := rm.GetRequestChan(id)
require.NotNil(t, dataChan, "Data channel should not be nil")
require.NoError(t, err, "Error on getting data channel")

rm.CloseRequest(id)

dataChan, err = rm.GetRequestChan(id)
require.Nil(t, dataChan, "Data channel should not be nil")
require.Error(t, err, "Request Channel should be closed")
}

0 comments on commit 23fff98

Please sign in to comment.