File: sharded_parallel_spec_iterator.go

package info (click to toggle)
golang-ginkgo 1.16.5-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,004 kB
  • sloc: sh: 14; makefile: 7
file content (47 lines) | stat: -rw-r--r-- 1,079 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package spec_iterator

import "github.com/onsi/ginkgo/internal/spec"

type ShardedParallelIterator struct {
	specs    []*spec.Spec
	index    int
	maxIndex int
}

func NewShardedParallelIterator(specs []*spec.Spec, total int, node int) *ShardedParallelIterator {
	startIndex, count := ParallelizedIndexRange(len(specs), total, node)

	return &ShardedParallelIterator{
		specs:    specs,
		index:    startIndex,
		maxIndex: startIndex + count,
	}
}

func (s *ShardedParallelIterator) Next() (*spec.Spec, error) {
	if s.index >= s.maxIndex {
		return nil, ErrClosed
	}

	spec := s.specs[s.index]
	s.index += 1
	return spec, nil
}

func (s *ShardedParallelIterator) NumberOfSpecsPriorToIteration() int {
	return len(s.specs)
}

func (s *ShardedParallelIterator) NumberOfSpecsToProcessIfKnown() (int, bool) {
	return s.maxIndex - s.index, true
}

func (s *ShardedParallelIterator) NumberOfSpecsThatWillBeRunIfKnown() (int, bool) {
	count := 0
	for i := s.index; i < s.maxIndex; i += 1 {
		if !s.specs[i].Skipped() && !s.specs[i].Pending() {
			count += 1
		}
	}
	return count, true
}