MCPcopy
hub / github.com/kubernetes/client-go / TestBasic

Function TestBasic

util/workqueue/queue_test.go:27–72  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

25)
26
27func TestBasic(t *testing.T) {
28 // If something is seriously wrong this test will never complete.
29 q := workqueue.New()
30
31 // Start producers
32 const producers = 50
33 producerWG := sync.WaitGroup{}
34 producerWG.Add(producers)
35 for i := 0; i < producers; i++ {
36 go func(i int) {
37 defer producerWG.Done()
38 for j := 0; j < 50; j++ {
39 q.Add(i)
40 time.Sleep(time.Millisecond)
41 }
42 }(i)
43 }
44
45 // Start consumers
46 const consumers = 10
47 consumerWG := sync.WaitGroup{}
48 consumerWG.Add(consumers)
49 for i := 0; i < consumers; i++ {
50 go func(i int) {
51 defer consumerWG.Done()
52 for {
53 item, quit := q.Get()
54 if item == "added after shutdown!" {
55 t.Errorf("Got an item added after shutdown.")
56 }
57 if quit {
58 return
59 }
60 t.Logf("Worker %v: begin processing %v", i, item)
61 time.Sleep(3 * time.Millisecond)
62 t.Logf("Worker %v: done processing %v", i, item)
63 q.Done(item)
64 }
65 }(i)
66 }
67
68 producerWG.Wait()
69 q.ShutDown()
70 q.Add("added after shutdown!")
71 consumerWG.Wait()
72}
73
74func TestAddWhileProcessing(t *testing.T) {
75 q := workqueue.New()

Callers

nothing calls this directly

Calls 8

NewFunction · 0.92
AddMethod · 0.65
DoneMethod · 0.65
SleepMethod · 0.65
GetMethod · 0.65
ErrorfMethod · 0.65
LogfMethod · 0.65
ShutDownMethod · 0.65

Tested by

no test coverage detected