@@ -33,7 +33,6 @@ import (
3333 "k8s.io/apimachinery/pkg/types"
3434 "k8s.io/apimachinery/pkg/util/wait"
3535 clientgotesting "k8s.io/client-go/testing"
36- rcl "knative.dev/pkg/reconciler"
3736
3837 "knative.dev/pkg/configmap"
3938 "knative.dev/pkg/controller"
@@ -285,27 +284,30 @@ func TestReconcilePaused(t *testing.T) {
285284 scs .AutoscalingV1alpha1 ().PodAutoscalers (a .Namespace ).Create (ctx , a , metav1.CreateOptions {})
286285 autoscalerinformer .Get (ctx ).Informer ().GetIndexer ().Add (a )
287286
288- if la , ok := ctl .Reconciler .(rcl.LeaderAware ); ok {
289- la .Promote (rcl .UniversalBucket (), func (rcl.Bucket , types.NamespacedName ) {})
290- }
291-
292- err = ctl .Reconciler .Reconcile (ctx , m .Namespace + "/" + m .Name )
293-
294- if err != nil {
295- t .Fatal ("Error reconciling metric %w" , err )
296- } else if collector .paused .Load () {
297- t .Fatal ("collector should not be paused" )
287+ if err := wait .PollUntilContextTimeout (ctx , 10 * time .Millisecond , 1 * time .Second , false , func (context.Context ) (bool , error ) {
288+ return ! collector .paused .Load (), nil
289+ }); err != nil {
290+ t .Fatal ("collector is paused, should not be paused" )
298291 }
299292
300293 // pause metrics
301294 a .Status .MetricsPaused = true
302295 updatePodAutoscaler (t , ctx , a )
303296
304- err = ctl .Reconciler .Reconcile (ctx , m .Namespace + "/" + m .Name )
305- if err != nil {
306- t .Fatal ("Error reconciling metric" )
307- } else if ! collector .paused .Load () {
308- t .Fatal ("collector should be paused" )
297+ if err := wait .PollUntilContextTimeout (ctx , 10 * time .Millisecond , 1 * time .Second , false , func (context.Context ) (bool , error ) {
298+ return collector .paused .Load (), nil
299+ }); err != nil {
300+ t .Fatal ("collector is not paused, should be paused" )
301+ }
302+
303+ // test when empty revision label found
304+ m .Labels [serving .RevisionLabelKey ] = ""
305+ updateMetric (t , ctx , m )
306+
307+ if err := wait .PollUntilContextTimeout (ctx , 10 * time .Millisecond , 1 * time .Second , false , func (context.Context ) (bool , error ) {
308+ return ! collector .paused .Load (), nil
309+ }); err != nil {
310+ t .Fatal ("collector is paused, should not be paused" )
309311 }
310312}
311313
@@ -327,6 +329,16 @@ func ready(m *autoscalingv1alpha1.Metric) {
327329 m .Status .MarkMetricReady ()
328330}
329331
332+ func updateMetric (
333+ t * testing.T ,
334+ ctx context.Context ,
335+ m * autoscalingv1alpha1.Metric ,
336+ ) {
337+ t .Helper ()
338+ servingclient .Get (ctx ).AutoscalingV1alpha1 ().Metrics (m .Namespace ).Update (ctx , m , metav1.UpdateOptions {})
339+ metricinformer .Get (ctx ).Informer ().GetIndexer ().Update (m )
340+ }
341+
330342func metric (namespace , name string , opts ... metricOption ) * autoscalingv1alpha1.Metric {
331343 m := & autoscalingv1alpha1.Metric {
332344 ObjectMeta : metav1.ObjectMeta {
0 commit comments