Add sync channel to batch_uuids_provider_test

This commit is contained in:
ErickSkrauch 2019-11-21 19:33:05 +03:00
parent 0644dfe021
commit d27caa4922

View File

@ -118,7 +118,9 @@ func (suite *batchUuidsProviderTestSuite) SetupTest() {
suite.GetUuidAsync = func(username string) chan *batchUuidsProviderGetUuidResult {
c := make(chan *batchUuidsProviderGetUuidResult)
s := make(chan int)
go func() {
s <- 0
profile, err := suite.Provider.GetUuid(username)
c <- &batchUuidsProviderGetUuidResult{
Result: profile,
@ -126,6 +128,8 @@ func (suite *batchUuidsProviderTestSuite) SetupTest() {
}
}()
<-s
return c
}
@ -178,9 +182,7 @@ func (suite *batchUuidsProviderTestSuite) TestGetUuidForTwoUsernames() {
}, nil)
resultChan1 := suite.GetUuidAsync("username1")
time.Sleep(time.Millisecond) // Just to keep order for the usernames
resultChan2 := suite.GetUuidAsync("username2")
time.Sleep(time.Millisecond) // Allow to all goroutines begin
suite.Iterate()
@ -212,7 +214,6 @@ func (suite *batchUuidsProviderTestSuite) TestGetUuidForMoreThan10Usernames() {
channels := make([]chan *batchUuidsProviderGetUuidResult, 12)
for i, username := range usernames {
channels[i] = suite.GetUuidAsync(username)
time.Sleep(time.Millisecond) // Just to keep order for the usernames
}
suite.Iterate()
@ -257,9 +258,7 @@ func (suite *batchUuidsProviderTestSuite) TestGetUuidForTwoUsernamesWithAnError(
suite.MojangApi.On("UsernamesToUuids", []string{"username1", "username2"}).Once().Return(nil, expectedError)
resultChan1 := suite.GetUuidAsync("username1")
time.Sleep(time.Millisecond) // Just to keep order for the usernames
resultChan2 := suite.GetUuidAsync("username2")
time.Sleep(time.Millisecond) // Allow to all goroutines begin
suite.Iterate()