mirror of
https://github.com/elyby/chrly.git
synced 2024-11-23 05:33:18 +05:30
Ensure that queue for Mojang textures provider is initialized before any job will be scheduled
This commit is contained in:
parent
dfe024756e
commit
fd05220299
@ -194,8 +194,12 @@ func (ctx *BatchUuidsProvider) GetUuid(username string) (*mojang.ProfileInfo, er
|
||||
}
|
||||
|
||||
func (ctx *BatchUuidsProvider) startQueue() {
|
||||
// This synchronization chan is used to ensure that strategy's jobs provider
|
||||
// will be initialized before any job will be scheduled
|
||||
d := make(chan struct{})
|
||||
go func() {
|
||||
jobsChan := ctx.strategy.GetJobs(ctx.context)
|
||||
close(d)
|
||||
for {
|
||||
select {
|
||||
case <-ctx.context.Done():
|
||||
@ -208,6 +212,8 @@ func (ctx *BatchUuidsProvider) startQueue() {
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
<-d
|
||||
}
|
||||
|
||||
func (ctx *BatchUuidsProvider) performRequest(iteration *JobsIteration) {
|
||||
|
@ -105,21 +105,10 @@ type batchUuidsProviderTestSuite struct {
|
||||
Strategy *manualStrategy
|
||||
MojangApi *mojangUsernamesToUuidsRequestMock
|
||||
|
||||
GetUuidAsync func(username string) <-chan *batchUuidsProviderGetUuidResult
|
||||
stop context.CancelFunc
|
||||
}
|
||||
|
||||
func (suite *batchUuidsProviderTestSuite) SetupTest() {
|
||||
suite.Emitter = &mockEmitter{}
|
||||
suite.Strategy = &manualStrategy{}
|
||||
ctx, stop := context.WithCancel(context.Background())
|
||||
suite.stop = stop
|
||||
suite.MojangApi = &mojangUsernamesToUuidsRequestMock{}
|
||||
usernamesToUuids = suite.MojangApi.UsernamesToUuids
|
||||
|
||||
suite.Provider = NewBatchUuidsProvider(ctx, suite.Strategy, suite.Emitter)
|
||||
|
||||
suite.GetUuidAsync = func(username string) <-chan *batchUuidsProviderGetUuidResult {
|
||||
func (suite *batchUuidsProviderTestSuite) GetUuidAsync(username string) <-chan *batchUuidsProviderGetUuidResult {
|
||||
s := make(chan struct{})
|
||||
// This dirty hack ensures, that the username will be queued before we return control to the caller.
|
||||
// It's needed to keep expected calls order and prevent cases when iteration happens before
|
||||
@ -144,6 +133,16 @@ func (suite *batchUuidsProviderTestSuite) SetupTest() {
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
func (suite *batchUuidsProviderTestSuite) SetupTest() {
|
||||
suite.Emitter = &mockEmitter{}
|
||||
suite.Strategy = &manualStrategy{}
|
||||
ctx, stop := context.WithCancel(context.Background())
|
||||
suite.stop = stop
|
||||
suite.MojangApi = &mojangUsernamesToUuidsRequestMock{}
|
||||
usernamesToUuids = suite.MojangApi.UsernamesToUuids
|
||||
|
||||
suite.Provider = NewBatchUuidsProvider(ctx, suite.Strategy, suite.Emitter)
|
||||
}
|
||||
|
||||
func (suite *batchUuidsProviderTestSuite) TearDownTest() {
|
||||
@ -196,15 +195,11 @@ func (suite *batchUuidsProviderTestSuite) TestShouldNotSendRequestWhenNoJobsAreR
|
||||
close(done)
|
||||
})
|
||||
|
||||
r := suite.GetUuidAsync("username") // Schedule one username to run the queue
|
||||
suite.GetUuidAsync("username") // Schedule one username to run the queue
|
||||
|
||||
suite.Strategy.Iterate(0, 1) // Return no jobs and indicate that there is one job in queue
|
||||
select {
|
||||
case <-r:
|
||||
// fail
|
||||
case <-done:
|
||||
return
|
||||
}
|
||||
|
||||
<-done
|
||||
}
|
||||
|
||||
// Test written for multiple usernames to ensure that the error
|
||||
|
Loading…
Reference in New Issue
Block a user