• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kubevirt / kubevirt / 9ceebca7-c1a3-49dd-92ee-07a4480f420f

28 Oct 2025 02:43PM UTC coverage: 70.346% (-0.01%) from 70.358%
9ceebca7-c1a3-49dd-92ee-07a4480f420f

push

prow

web-flow
Merge pull request #15887 from fossedihelm/generalized-priority-queue

Generalized Migration Priority in KubeVirt

132 of 189 new or added lines in 11 files covered. (69.84%)

827 existing lines in 18 files now uncovered.

69371 of 98614 relevant lines covered (70.35%)

564.83 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/pkg/testutils/mock_priorityqueue.go
1
package testutils
2

3
import (
4
        "sync"
5
        "sync/atomic"
6
        "time"
7

8
        "sigs.k8s.io/controller-runtime/pkg/controller/priorityqueue"
9
)
10

11
/*
12
MockPriorityQueue is a helper workqueue which can be wrapped around
13
any RateLimitingInterface implementing queue. This allows synchronous
14
testing of the controller. The typical pattern is:
15

16
        MockQueue.ExpectAdd(3)
17
        vmiSource.Add(vmi)
18
        vmiSource.Add(vmi1)
19
        vmiSource.Add(vmi2)
20
        MockQueue.Wait()
21

22
This ensures that Source callbacks which are listening on vmiSource
23
enqueued three times an object. Since enqueing is typically the last
24
action in listener callbacks, we can assume that the wanted scenario for
25
a controller is set up, and an execution will process this scenario.
26
*/
27
type MockPriorityQueue[T comparable] struct {
28
        priorityqueue.PriorityQueue[T]
29
        addWG            *sync.WaitGroup
30
        rateLimitedEnque int32
31
        addAfterEnque    int32
32
        wgLock           sync.Mutex
33
}
34

UNCOV
35
func (q *MockPriorityQueue[T]) Add(item T) {
×
UNCOV
36
        q.PriorityQueue.Add(item)
×
UNCOV
37
        q.wgLock.Lock()
×
UNCOV
38
        defer q.wgLock.Unlock()
×
UNCOV
39
        if q.addWG != nil {
×
40
                q.addWG.Done()
×
41
        }
×
42
}
43

44
func (q *MockPriorityQueue[T]) AddRateLimited(item T) {
×
45
        q.PriorityQueue.AddRateLimited(item)
×
46
        atomic.AddInt32(&q.rateLimitedEnque, 1)
×
47
}
×
48

49
func (q *MockPriorityQueue[T]) AddAfter(item T, duration time.Duration) {
×
50
        q.PriorityQueue.AddAfter(item, duration)
×
51
        atomic.AddInt32(&q.addAfterEnque, 1)
×
52
        q.wgLock.Lock()
×
53
        defer q.wgLock.Unlock()
×
54
        if q.addWG != nil {
×
55
                q.addWG.Done()
×
56
        }
×
57
}
58

UNCOV
59
func (q *MockPriorityQueue[T]) AddWithOpts(o priorityqueue.AddOpts, Items ...T) {
×
UNCOV
60
        q.PriorityQueue.AddWithOpts(o, Items...)
×
UNCOV
61
        q.wgLock.Lock()
×
UNCOV
62
        defer q.wgLock.Unlock()
×
UNCOV
63
        if q.addWG != nil {
×
64
                for range Items {
×
65
                        q.addWG.Done()
×
66
                }
×
67
        }
68
}
69

70
func (q *MockPriorityQueue[T]) GetRateLimitedEnqueueCount() int {
×
71
        return int(atomic.LoadInt32(&q.rateLimitedEnque))
×
72
}
×
73

74
func (q *MockPriorityQueue[T]) GetAddAfterEnqueueCount() int {
×
75
        return int(atomic.LoadInt32(&q.addAfterEnque))
×
76
}
×
77

78
// ExpectAdds allows setting the amount of expected enqueues.
79
func (q *MockPriorityQueue[T]) ExpectAdds(diff int) {
×
80
        q.wgLock.Lock()
×
81
        defer q.wgLock.Unlock()
×
82
        q.addWG = &sync.WaitGroup{}
×
83
        q.addWG.Add(diff)
×
84
}
×
85

86
// Wait waits until the expected amount of ExpectedAdds has happened.
87
// It will not block if there were no expectations set.
88
func (q *MockPriorityQueue[T]) Wait() {
×
89
        q.wgLock.Lock()
×
90
        wg := q.addWG
×
91
        q.wgLock.Unlock()
×
92
        if wg != nil {
×
93
                wg.Wait()
×
94
                q.wgLock.Lock()
×
95
                q.addWG = nil
×
96
                q.wgLock.Unlock()
×
97
        }
×
98
}
99

UNCOV
100
func NewMockPriorityQueue[T comparable](queue priorityqueue.PriorityQueue[T]) *MockPriorityQueue[T] {
×
UNCOV
101
        return &MockPriorityQueue[T]{queue, nil, 0, 0, sync.Mutex{}}
×
UNCOV
102
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc