-
Notifications
You must be signed in to change notification settings - Fork 475
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |