Skip to content

Commit 2db4175

Browse files
authored
Fix IWRR scheduler UpdateWeight test (#3961)
1 parent 0bb6884 commit 2db4175

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

common/tasks/interleaved_weighted_round_robin_test.go

+23-6
Original file line numberDiff line numberDiff line change
@@ -378,15 +378,32 @@ func (s *interleavedWeightedRoundRobinSchedulerSuite) TestUpdateWeight() {
378378
2: 1,
379379
3: 1,
380380
}
381+
totalWeight := 0
382+
for _, weight := range s.channelKeyToWeight {
383+
totalWeight += weight
384+
}
381385
s.channelWeightUpdateCh <- struct{}{}
382386

383-
taskWG.Add(1)
384-
s.scheduler.Submit(mockTask0)
385-
taskWG.Wait()
387+
// we don't know when the weight update signal will be picked up
388+
// so need to retry a few times here.
389+
for i := 0; i != 10; i++ {
390+
// submit a task may or may not trigger a new round of dispatch loop
391+
// which updates weight
392+
taskWG.Add(1)
393+
s.scheduler.Submit(mockTask0)
394+
taskWG.Wait()
395+
396+
flattenedChannels := s.scheduler.channels().flattenedChannels
397+
if len(flattenedChannels) != totalWeight {
398+
time.Sleep(50 * time.Millisecond)
399+
continue
400+
}
401+
402+
channelWeights = []int{}
403+
for _, channel := range flattenedChannels {
404+
channelWeights = append(channelWeights, channel.Weight())
405+
}
386406

387-
channelWeights = []int{}
388-
for _, channel := range s.scheduler.channels().flattenedChannels {
389-
channelWeights = append(channelWeights, channel.Weight())
390407
}
391408
s.Equal([]int{8, 8, 8, 8, 5, 8, 5, 8, 5, 8, 5, 8, 5, 1, 1}, channelWeights)
392409
}

0 commit comments

Comments
 (0)