Skip to content

Commit

Permalink
Merge pull request #62829 from MrHohn/e2e-inrgess-scale-race
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue (batch tested with PRs 62495, 63003, 62829, 62151, 62002). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

[e2e ingress-gce] Fix race condition for appending services and ingresses

**What this PR does / why we need it**:
From kubernetes/ingress-gce#219, how the test appends services and ingresses is not thread-safe. This PR fixes it by using channel.

**Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*:
Fixes #kubernetes/ingress-gce#219

**Special notes for your reviewer**:
/assign @nicksardo 
I picked this up as it is fun :) Hoping you haven't worked on it yet.

**Release note**:

```release-note
NONE
```
  • Loading branch information
Kubernetes Submit Queue committed Apr 24, 2018
2 parents b0fb272 + 9a5ce37 commit 1aa67be
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions test/e2e/network/scale/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,25 +179,27 @@ func (f *IngressScaleFramework) RunScaleTest() []error {
}
}

// currentNum keeps track of how many ingresses have been created.
currentNum := new(int)
// numIngsCreated keeps track of how many ingresses have been created.
numIngsCreated := 0

prepareIngsFunc := func(goalNum int) {
prepareIngsFunc := func(numIngsNeeded int) {
var ingWg sync.WaitGroup
numToCreate := goalNum - *currentNum
ingWg.Add(numToCreate)
errQueue := make(chan error, numToCreate)
latencyQueue := make(chan time.Duration, numToCreate)
numIngsToCreate := numIngsNeeded - numIngsCreated
ingWg.Add(numIngsToCreate)
svcQueue := make(chan *v1.Service, numIngsToCreate)
ingQueue := make(chan *extensions.Ingress, numIngsToCreate)
errQueue := make(chan error, numIngsToCreate)
latencyQueue := make(chan time.Duration, numIngsToCreate)
start := time.Now()
for ; *currentNum < goalNum; *currentNum++ {
suffix := fmt.Sprintf("%d", *currentNum)
for ; numIngsCreated < numIngsNeeded; numIngsCreated++ {
suffix := fmt.Sprintf("%d", numIngsCreated)
go func() {
defer ingWg.Done()

start := time.Now()
svcCreated, ingCreated, err := f.createScaleTestServiceIngress(suffix, f.EnableTLS)
f.ScaleTestSvcs = append(f.ScaleTestSvcs, svcCreated)
f.ScaleTestIngs = append(f.ScaleTestIngs, ingCreated)
svcQueue <- svcCreated
ingQueue <- ingCreated
if err != nil {
errQueue <- err
return
Expand All @@ -214,11 +216,19 @@ func (f *IngressScaleFramework) RunScaleTest() []error {
}

// Wait until all ingress creations are complete.
f.Logger.Infof("Waiting for %d ingresses to come up...", numToCreate)
f.Logger.Infof("Waiting for %d ingresses to come up...", numIngsToCreate)
ingWg.Wait()
close(svcQueue)
close(ingQueue)
close(errQueue)
close(latencyQueue)
elapsed := time.Since(start)
for svc := range svcQueue {
f.ScaleTestSvcs = append(f.ScaleTestSvcs, svc)
}
for ing := range ingQueue {
f.ScaleTestIngs = append(f.ScaleTestIngs, ing)
}
var createLatencies []time.Duration
for latency := range latencyQueue {
createLatencies = append(createLatencies, latency)
Expand All @@ -231,15 +241,15 @@ func (f *IngressScaleFramework) RunScaleTest() []error {
}
return
}
f.Logger.Infof("Spent %s for %d ingresses to come up", elapsed, numToCreate)
f.Logger.Infof("Spent %s for %d ingresses to come up", elapsed, numIngsToCreate)
f.BatchDurations = append(f.BatchDurations, elapsed)
}

measureCreateUpdateFunc := func() {
f.Logger.Infof("Create one more ingress and wait for it to come up")
start := time.Now()
svcCreated, ingCreated, err := f.createScaleTestServiceIngress(fmt.Sprintf("%d", *currentNum), f.EnableTLS)
*currentNum = *currentNum + 1
svcCreated, ingCreated, err := f.createScaleTestServiceIngress(fmt.Sprintf("%d", numIngsCreated), f.EnableTLS)
numIngsCreated = numIngsCreated + 1
f.ScaleTestSvcs = append(f.ScaleTestSvcs, svcCreated)
f.ScaleTestIngs = append(f.ScaleTestIngs, ingCreated)
if err != nil {
Expand Down

0 comments on commit 1aa67be

Please sign in to comment.