Repository: knative/pkg
Pull request #1632 (2020-08-18 22:07:40)

Fix the flaky test.
The test assumes the threads would schedule in particular way, but they don't.
But what we really care to check is that we thread in the proper RL and it works.
We don't need to check that underlying queue impl works, that's done in its own tests.
So just verify these two things.

/assign mattmoor

knative-prow-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/knative/pkg/pull/1632#" title="Author self-approved">vagababov</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=knative%2Fpkg).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[controller/OWNERS](https://github.com/knative/pkg/blob/master/controller/OWNERS)~~ [vagababov]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->
vagababov: /cc @Cynocracy 

Patch:
diff --git a/RELEASE-LEADS.md b/RELEASE-LEADS.md
index f3294ebe0..4c6b37272 100644
--- a/RELEASE-LEADS.md
+++ b/RELEASE-LEADS.md
@@ -227,6 +227,16 @@ automation to kick in (runs on a 2 hour interval). Once the release automation
 passed, it will create a release tag in both repositories. Enhance the
 respective tags with the collected release-notes using the Github UI.
 
+### Cut `release-x.y` branches of `net-*`
+
+Cut a `release-x.y` branch in each of the following repositories which do not
+depend on `serving` or `eventing`:
+
+- [knative-sandbox/net-certmanager](https://github.com/knative-sandbox/net-certmanager)
+- [knative-sandbox/net-contour](https://github.com/knative-sandbox/net-contour)
+- [knative-sandbox/net-http01](https://github.com/knative-sandbox/net-http01)
+- [knative-sandbox/net-istio](https://github.com/knative-sandbox/net-istio)
+
 ### Pin `serving` and `eventing` releases in dependent repositories
 
 **After** the tags for `serving` and `eventing` are created, their version needs
@@ -234,10 +244,6 @@ to be pinned in all repositories that depend on them.
 
 For **serving** that is:
 
-- [knative-sandbox/net-certmanager](https://github.com/knative-sandbox/net-certmanager)
-- [knative-sandbox/net-contour](https://github.com/knative-sandbox/net-contour)
-- [knative-sandbox/net-http01](https://github.com/knative-sandbox/net-http01)
-- [knative-sandbox/net-istio](https://github.com/knative-sandbox/net-istio)
 - [knative-sandbox/net-kourier](https://github.com/knative-sandbox/net-kourier)
 - [knative/eventing-contrib](https://github.com/knative/eventing-contrib)
 
@@ -255,10 +261,6 @@ branch of each repository respectively.
 After the pin PRs are merged, cut the `release-x.y` branch in each of the
 remaining repositories (except `operator`):
 
-- [knative-sandbox/net-certmanager](https://github.com/knative-sandbox/net-certmanager)
-- [knative-sandbox/net-contour](https://github.com/knative-sandbox/net-contour)
-- [knative-sandbox/net-http01](https://github.com/knative-sandbox/net-http01)
-- [knative-sandbox/net-istio](https://github.com/knative-sandbox/net-istio)
 - [knative-sandbox/net-kourier](https://github.com/knative-sandbox/net-kourier)
 - [knative/eventing-contrib](https://github.com/knative/eventing-contrib)
 - [knative-sandbox/eventing-kafka-broker](https://github.com/knative-sandbox/eventing-kafka-broker)


Test patch:
diff --git a/controller/stats_reporter_test.go b/controller/stats_reporter_test.go
index ff56d99a3..35895f764 100644
--- a/controller/stats_reporter_test.go
+++ b/controller/stats_reporter_test.go
@@ -38,7 +38,6 @@ func TestNewStatsReporterErrors(t *testing.T) {
 		if err == nil {
 			t.Errorf("Expected err to not be nil for value %q, got nil", v)
 		}
-
 	}
 }
 
diff --git a/controller/two_lane_queue_test.go b/controller/two_lane_queue_test.go
index a6998e735..187cd2fb1 100644
--- a/controller/two_lane_queue_test.go
+++ b/controller/two_lane_queue_test.go
@@ -29,64 +29,60 @@ type chanRateLimiter struct {
 	t *testing.T
 	// Called when this ratelimiter is consulted for when to process a value.
 	whenCalled chan interface{}
-	retryCount map[interface{}]int
 }
 
-func (r chanRateLimiter) When(item interface{}) time.Duration {
+func (r *chanRateLimiter) When(item interface{}) time.Duration {
 	r.whenCalled <- item
-	return 0 * time.Second
+	return 0
 }
-func (r chanRateLimiter) Forget(item interface{}) {
+
+func (r *chanRateLimiter) Forget(item interface{}) {
 	r.t.Fatalf("Forgetting item %+v, we should not be forgetting any items.", item)
 }
-func (r chanRateLimiter) NumRequeues(item interface{}) int {
-	return r.retryCount[item]
+
+func (r *chanRateLimiter) NumRequeues(item interface{}) int {
+	return 0
 }
 
 var _ workqueue.RateLimiter = &chanRateLimiter{}
 
 func TestRateLimit(t *testing.T) {
-	whenCalled := make(chan interface{}, 2)
-	rl := chanRateLimiter{
-		t,
-		whenCalled,
-		make(map[interface{}]int),
+	// Verifies that we properly pass the rate limiter to the queue.
+	rl := &chanRateLimiter{
+		t:          t,
+		whenCalled: make(chan interface{}, 1),
 	}
-	q := newTwoLaneWorkQueue("live-in-the-limited-lane", rl)
-	q.SlowLane().Add("1")
-	q.Add("2")
 
-	k, done := q.Get()
-	q.Done(k)
-	q.AddRateLimited(k)
-	rlK := <-whenCalled
-	if got, want := k.(string), rlK.(string); got != want {
-		t.Errorf(`Got = %q, want: "%q"`, got, want)
-	}
-	if done {
-		t.Error("The queue is unexpectedly shutdown")
+	q := newTwoLaneWorkQueue("live-in-the-limited-lane", rl)
+	// Verify the slow lane has the proper RL.
+	q.SlowLane().AddRateLimited("1")
+	select {
+	case <-rl.whenCalled:
+		// As desired.
+	default:
+		t.Error("Didn't go to the proper rate limiter.")
 	}
 
-	k2, done := q.Get()
-	q.Done(k2)
-	q.AddRateLimited(k2)
-	rlK2 := <-whenCalled
-	if got, want := k2.(string), rlK2.(string); got != want {
-		t.Errorf(`Got = %q, want: "%q"`, got, want)
-	}
-	if s1, s2 := k.(string), k2.(string); (s1 != "1" || s2 != "2") && (s1 != "2" || s2 != "1") {
-		t.Errorf("Expected to see 1 and 2, instead saw %q and %q", s1, s2)
-	}
-	if done {
-		t.Error("The queue is unexpectedly shutdown")
+	// Verify the fast lane has the proper RL.
+	q.AddRateLimited("2")
+	select {
+	case <-rl.whenCalled:
+		// As desired.
+	default:
+		t.Error("Didn't go to the proper rate limiter.")
 	}
 
-	// Queue has async moving parts so if we check at the wrong moment, this might still be 0 or 1.
+	// Verify the items were properly added for consumption.
 	if wait.PollImmediate(10*time.Millisecond, 250*time.Millisecond, func() (bool, error) {
 		return q.Len() == 2, nil
 	}) != nil {
 		t.Error("Queue length was never 2")
 	}
+	// And drain.
+	q.ShutDown()
+	for q.Len() > 0 {
+		q.Get()
+	}
 }
 
 func TestSlowQueue(t *testing.T) {