From 5fd6dadcaa6317bbce49a61a15bcd0988565272c Mon Sep 17 00:00:00 2001 From: Shawn Poulson Date: Fri, 8 Mar 2024 14:13:09 -0500 Subject: [PATCH] Tidy code. --- functional_test.go | 9 +++++++-- global.go | 20 ++++++++++---------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/functional_test.go b/functional_test.go index 03dcc051..d81a1f19 100644 --- a/functional_test.go +++ b/functional_test.go @@ -1009,8 +1009,7 @@ func TestGlobalRateLimitsWithLoadBalancing(t *testing.T) { assert.Equal(t, status, item.Status, fmt.Sprintf("mismatch status, iteration %d", i)) } - require.NoError(t, waitForBroadcast(1*clock.Minute, owner, 0)) - require.NoError(t, waitForBroadcast(1*clock.Minute, nonOwner, 0)) + require.NoError(t, waitForIdle(1*clock.Minute, cluster.GetDaemons()...)) // Send two hits that should be processed by the owner and non-owner and // deplete the limit consistently. @@ -1541,6 +1540,8 @@ func TestGlobalBehavior(t *testing.T) { upgCounters := getPeerCounters(t, cluster.GetDaemons(), "gubernator_grpc_request_duration_count{method=\"/pb.gubernator.PeersV1/UpdatePeerGlobals\"}") gprlCounters := getPeerCounters(t, cluster.GetDaemons(), "gubernator_grpc_request_duration_count{method=\"/pb.gubernator.PeersV1/GetPeerRateLimits\"}") + require.NoError(t, waitForIdle(1*clock.Minute, cluster.GetDaemons()...)) + // When for i := int64(0); i < testCase.Hits; i++ { sendHit(t, owner, makeReq(name, key, 1), guber.Status_UNDER_LIMIT, 999-i) @@ -1657,6 +1658,8 @@ func TestGlobalBehavior(t *testing.T) { upgCounters := getPeerCounters(t, cluster.GetDaemons(), "gubernator_grpc_request_duration_count{method=\"/pb.gubernator.PeersV1/UpdatePeerGlobals\"}") gprlCounters := getPeerCounters(t, cluster.GetDaemons(), "gubernator_grpc_request_duration_count{method=\"/pb.gubernator.PeersV1/GetPeerRateLimits\"}") + require.NoError(t, waitForIdle(1*clock.Minute, cluster.GetDaemons()...)) + // When for i := int64(0); i < testCase.Hits; i++ { sendHit(t, peers[0], makeReq(name, key, 1), guber.Status_UNDER_LIMIT, 999-i) @@ -1787,6 +1790,8 @@ func TestGlobalBehavior(t *testing.T) { var wg sync.WaitGroup var mutex sync.Mutex + require.NoError(t, waitForIdle(1*clock.Minute, cluster.GetDaemons()...)) + // When wg.Add(testCase.Hits) for i := 0; i < testCase.Hits; i++ { diff --git a/global.go b/global.go index d8ba66f8..e8c17d64 100644 --- a/global.go +++ b/global.go @@ -27,17 +27,17 @@ import ( // globalManager manages async hit queue and updates peers in // the cluster periodically when a global rate limit we own updates. type globalManager struct { - hitsQueue chan *RateLimitReq - updatesQueue chan *RateLimitReq - wg syncutil.WaitGroup - conf BehaviorConfig - log FieldLogger - instance *V1Instance // todo circular import? V1Instance also holds a reference to globalManager - metricGlobalSendDuration prometheus.Summary + hitsQueue chan *RateLimitReq + updatesQueue chan *RateLimitReq + wg syncutil.WaitGroup + conf BehaviorConfig + log FieldLogger + instance *V1Instance // todo circular import? V1Instance also holds a reference to globalManager + metricGlobalSendDuration prometheus.Summary metricGlobalSendQueueLength prometheus.Gauge - metricBroadcastDuration prometheus.Summary - metricBroadcastCounter *prometheus.CounterVec - metricGlobalQueueLength prometheus.Gauge + metricBroadcastDuration prometheus.Summary + metricBroadcastCounter *prometheus.CounterVec + metricGlobalQueueLength prometheus.Gauge } func newGlobalManager(conf BehaviorConfig, instance *V1Instance) *globalManager {