mirror of https://github.com/knative/pkg.git
SourceStatsReporter UT fix (#667)
* source stats reporter... should be used by well-behaved sources * public fields * moving serialization/deserialization of metrics and logging maps to pkg * nits * adding UT * same order * updates * sock-puppet * unregistration problem? * removing base64 encoding * removing TODO * removing config changes... done in another PR * to properly address the comment * changing importer to source * moving stats_reporter to new source folder * fixing UT
This commit is contained in:
parent
2b5e8011b8
commit
1bea34570b
|
@ -24,16 +24,8 @@ import (
|
|||
"knative.dev/pkg/metrics/metricstest"
|
||||
)
|
||||
|
||||
// unregister, ehm, unregisters the metrics that were registered, by
|
||||
// virtue of StatsReporter creation.
|
||||
// Since golang executes test iterations within the same process, the stats reporter
|
||||
// returns an error if the metric is already registered and the test panics.
|
||||
func unregister() {
|
||||
metricstest.Unregister("event_count")
|
||||
}
|
||||
|
||||
func TestStatsReporter(t *testing.T) {
|
||||
t.Skip("Fails in PROW but not locally, possibly due to the webhook stats_reporter test. Needs further investigation.")
|
||||
setup()
|
||||
|
||||
args := &ReportArgs{
|
||||
Namespace: "testns",
|
||||
|
@ -47,9 +39,6 @@ func TestStatsReporter(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("Failed to create a new reporter: %v", err)
|
||||
}
|
||||
// Without this `go test ... -count=X`, where X > 1, fails, since
|
||||
// we get an error about view already being registered.
|
||||
defer unregister()
|
||||
|
||||
wantTags := map[string]string{
|
||||
metricskey.LabelNamespaceName: "testns",
|
||||
|
@ -77,3 +66,13 @@ func expectSuccess(t *testing.T, f func() error) {
|
|||
t.Errorf("Reporter expected success but got error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func setup() {
|
||||
resetMetrics()
|
||||
}
|
||||
|
||||
func resetMetrics() {
|
||||
// OpenCensus metrics carry global state that need to be reset between unit tests.
|
||||
metricstest.Unregister("event_count")
|
||||
register()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue