mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 14:37:00 +00:00
Fix TestPriorityLevelIsolation concurrency issue
This commit is contained in:
parent
e95f8f2e42
commit
73da6d15f9
@ -22,6 +22,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -104,22 +105,28 @@ func TestPriorityLevelIsolation(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
stopCh := make(chan struct{})
|
stopCh := make(chan struct{})
|
||||||
defer close(stopCh)
|
wg := sync.WaitGroup{}
|
||||||
|
defer func() {
|
||||||
|
close(stopCh)
|
||||||
|
wg.Wait()
|
||||||
|
}()
|
||||||
|
|
||||||
// "elephant"
|
// "elephant"
|
||||||
|
wg.Add(concurrencyShares + queueLength)
|
||||||
streamRequests(concurrencyShares+queueLength, func() {
|
streamRequests(concurrencyShares+queueLength, func() {
|
||||||
_, err := noxu1Client.CoreV1().Namespaces().List(context.Background(), metav1.ListOptions{})
|
_, err := noxu1Client.CoreV1().Namespaces().List(context.Background(), metav1.ListOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
}, stopCh)
|
}, &wg, stopCh)
|
||||||
// "mouse"
|
// "mouse"
|
||||||
|
wg.Add(3)
|
||||||
streamRequests(3, func() {
|
streamRequests(3, func() {
|
||||||
_, err := noxu2Client.CoreV1().Namespaces().List(context.Background(), metav1.ListOptions{})
|
_, err := noxu2Client.CoreV1().Namespaces().List(context.Background(), metav1.ListOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
}, stopCh)
|
}, &wg, stopCh)
|
||||||
|
|
||||||
time.Sleep(time.Second * 10) // running in background for a while
|
time.Sleep(time.Second * 10) // running in background for a while
|
||||||
|
|
||||||
@ -312,9 +319,10 @@ func createPriorityLevelAndBindingFlowSchemaForUser(c clientset.Interface, usern
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func streamRequests(parallel int, request func(), stopCh <-chan struct{}) {
|
func streamRequests(parallel int, request func(), wg *sync.WaitGroup, stopCh <-chan struct{}) {
|
||||||
for i := 0; i < parallel; i++ {
|
for i := 0; i < parallel; i++ {
|
||||||
go func() {
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-stopCh:
|
case <-stopCh:
|
||||||
|
Loading…
Reference in New Issue
Block a user