Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Vosmaer <jacob@gitlab.com>2020-03-24 13:27:49 +0300
committerJacob Vosmaer <jacob@gitlab.com>2020-03-24 13:27:49 +0300
commit768dda7a784657a05596c4925a0b3dd6d196ce3e (patch)
tree5ef9f51a3665797fa26c0d5ad2bb2c3bf0c3097d
parentcb86920bbcf385cf3329a7863356dc2660f4a85e (diff)
parentd9b7f97ee6082fdd22e0d393b0df663effab9438 (diff)
Merge branch 'po-fix-flaky-test-limiter' into 'master'
Fix flaky test TestLimiter Closes #2574 See merge request gitlab-org/gitaly!1965
-rw-r--r--changelogs/unreleased/po-fix-flaky-test-limiter.yml5
-rw-r--r--internal/middleware/limithandler/concurrency_limiter_test.go23
2 files changed, 26 insertions, 2 deletions
diff --git a/changelogs/unreleased/po-fix-flaky-test-limiter.yml b/changelogs/unreleased/po-fix-flaky-test-limiter.yml
new file mode 100644
index 000000000..34131c46f
--- /dev/null
+++ b/changelogs/unreleased/po-fix-flaky-test-limiter.yml
@@ -0,0 +1,5 @@
+---
+title: Fix flaky test TestLimiter
+merge_request: 1965
+author:
+type: fixed
diff --git a/internal/middleware/limithandler/concurrency_limiter_test.go b/internal/middleware/limithandler/concurrency_limiter_test.go
index 76797da2a..735ff77c6 100644
--- a/internal/middleware/limithandler/concurrency_limiter_test.go
+++ b/internal/middleware/limithandler/concurrency_limiter_test.go
@@ -141,6 +141,25 @@ func TestLimiter(t *testing.T) {
wg := sync.WaitGroup{}
wg.Add(tt.concurrency)
+ full := sync.NewCond(&sync.Mutex{})
+
+ // primePump waits for the gauge to reach the minimum
+ // expected max concurrency so that the limiter is
+ // "warmed" up before proceeding with the test
+ primePump := func() {
+ full.L.Lock()
+ defer full.L.Unlock()
+
+ gauge.up()
+
+ if gauge.max >= tt.wantMaxRange[0] {
+ full.Broadcast()
+ return
+ }
+
+ full.Wait() // wait until full is broadcast
+ }
+
// We know of an edge case that can lead to the rate limiter
// occasionally letting one or two extra goroutines run
// concurrently.
@@ -151,11 +170,11 @@ func TestLimiter(t *testing.T) {
lockKey := strconv.Itoa((i ^ counter) % tt.buckets)
limiter.Limit(context.Background(), lockKey, func() (interface{}, error) {
- gauge.up()
+ primePump()
+
current := gauge.currentVal()
assert.True(t, current <= tt.wantMaxRange[1], "Expected the number of concurrent operations (%v) to not exceed the maximum concurrency (%v)", current, tt.wantMaxRange[1])
assert.True(t, limiter.countSemaphores() <= tt.buckets, "Expected the number of semaphores (%v) to be lte number of buckets (%v)", limiter.countSemaphores(), tt.buckets)
- time.Sleep(tt.delay)
gauge.down()
return nil, nil