Drops the Serving-specific stats reporter logic from knative/pkg (#1114)

This commit is contained in:
Matt Moore 2020-02-21 10:02:07 -08:00 committed by GitHub
parent 1d60dd6107
commit 3bada55aab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 56 deletions

View File

@ -1,40 +0,0 @@
/*
Copyright 2019 The Knative Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package testing
import (
"fmt"
"time"
)
// FakeStatsReporter is a fake implementation of StatsReporter
type FakeStatsReporter struct {
servicesReady map[string]int
}
func (r *FakeStatsReporter) ReportServiceReady(namespace, service string, d time.Duration) error {
key := fmt.Sprintf("%s/%s", namespace, service)
if r.servicesReady == nil {
r.servicesReady = make(map[string]int)
}
r.servicesReady[key]++
return nil
}
func (r *FakeStatsReporter) GetServiceReadyStats() map[string]int {
return r.servicesReady
}

View File

@ -79,9 +79,6 @@ type TableRow struct {
// WantEvents holds the ordered list of events we expect during reconciliation.
WantEvents []string
// WantServiceReadyStats holds the ServiceReady stats we expect during reconciliation.
WantServiceReadyStats map[string]int
// WithReactors is a set of functions that are installed as Reactors for the execution
// of this row of the table-driven-test.
WithReactors []clientgotesting.ReactionFunc
@ -123,15 +120,14 @@ func objKey(o runtime.Object) string {
return path.Join(typeOf, on.GetNamespace(), on.GetName())
}
// Factory returns a Reconciler.Interface to perform reconciliation in table test,
// ActionRecorderList/EventList to capture k8s actions/events produced during reconciliation
// and FakeStatsReporter to capture stats.
type Factory func(*testing.T, *TableRow) (controller.Reconciler, ActionRecorderList, EventList, *FakeStatsReporter)
// Factory returns a Reconciler.Interface to perform reconciliation in table test, and
// ActionRecorderList/EventList to capture k8s actions/events produced during reconciliation.
type Factory func(*testing.T, *TableRow) (controller.Reconciler, ActionRecorderList, EventList)
// Test executes the single table test.
func (r *TableRow) Test(t *testing.T, factory Factory) {
t.Helper()
c, recorderList, eventList, statsReporter := factory(t, r)
c, recorderList, eventList := factory(t, r)
// Set the Reconciler for PostConditions to access it post-Reconcile()
r.Reconciler = c
@ -355,11 +351,6 @@ func (r *TableRow) Test(t *testing.T, factory Factory) {
}
}
gotStats := statsReporter.GetServiceReadyStats()
if diff := cmp.Diff(r.WantServiceReadyStats, gotStats); diff != "" {
t.Errorf("Unexpected service ready stats (-want, +got): %s", diff)
}
for _, verify := range r.PostConditions {
verify(t, r)
}

View File

@ -51,7 +51,7 @@ type Ctor func(context.Context, *Listers, configmap.Watcher) controller.Reconcil
// MakeFactory creates a reconciler factory with fake clients and controller created by `ctor`.
func MakeFactory(ctor Ctor) rtesting.Factory {
return func(t *testing.T, r *rtesting.TableRow) (
controller.Reconciler, rtesting.ActionRecorderList, rtesting.EventList, *rtesting.FakeStatsReporter) {
controller.Reconciler, rtesting.ActionRecorderList, rtesting.EventList) {
ls := NewListers(r.Objects)
ctx := r.Ctx
@ -76,7 +76,6 @@ func MakeFactory(ctor Ctor) rtesting.Factory {
eventRecorder := record.NewFakeRecorder(maxEventBufferSize)
ctx = controller.WithEventRecorder(ctx, eventRecorder)
statsReporter := &rtesting.FakeStatsReporter{}
// This is needed for the tests that use generated names and
// the object cannot be created beforehand.
@ -109,7 +108,7 @@ func MakeFactory(ctor Ctor) rtesting.Factory {
actionRecorderList := rtesting.ActionRecorderList{dynamicClient, kubeClient, apixClient}
eventList := rtesting.EventList{Recorder: eventRecorder}
return c, actionRecorderList, eventList, statsReporter
return c, actionRecorderList, eventList
}
}