You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2018/08/14 19:18:51 UTC
[GitHub] rob05c closed pull request #1647: Fix Monitor Go tests
rob05c closed pull request #1647: Fix Monitor Go tests
URL: https://github.com/apache/trafficcontrol/pull/1647
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/traffic_monitor/cache/cache_test.go b/traffic_monitor/cache/cache_test.go
index e08e81eb7..1c5a57446 100644
--- a/traffic_monitor/cache/cache_test.go
+++ b/traffic_monitor/cache/cache_test.go
@@ -26,7 +26,6 @@ import (
"time"
"github.com/apache/incubator-trafficcontrol/lib/go-tc"
- "github.com/apache/incubator-trafficcontrol/traffic_monitor/peer"
"github.com/apache/incubator-trafficcontrol/traffic_monitor/srvhttp"
"github.com/apache/incubator-trafficcontrol/traffic_monitor/todata"
)
@@ -35,7 +34,7 @@ func TestHandlerPrecompute(t *testing.T) {
if NewHandler().Precompute() {
t.Errorf("expected NewHandler().Precompute() false, actual true")
}
- if !NewPrecomputeHandler(todata.NewThreadsafe(), peer.NewCRStatesPeersThreadsafe()).Precompute() {
+ if !NewPrecomputeHandler(todata.NewThreadsafe()).Precompute() {
t.Errorf("expected NewPrecomputeHandler().Precompute() true, actual false")
}
}
@@ -56,12 +55,18 @@ func (f DummyFilterNever) WithinStatHistoryMax(i int) bool {
}
func TestStatsMarshall(t *testing.T) {
- hist := randResultHistory()
+ hist := randResultStatHistory()
filter := DummyFilterNever{}
params := url.Values{}
+ info := randResultInfoHistory()
+ combinedStates := tc.CRStates{}
+ monitorConfig := tc.TrafficMonitorConfigMap{}
+ statMaxKbpses := randKbpses()
+
beforeStatsMarshall := time.Now()
- bytes, err := StatsMarshall(hist, filter, params)
+ bytes, err := StatsMarshall(hist, info, combinedStates, monitorConfig, statMaxKbpses, filter, params)
afterStatsMarshall := time.Now()
+
if err != nil {
t.Fatalf("StatsMarshall return expected nil err, actual err: %v", err)
}
@@ -82,8 +87,8 @@ func TestStatsMarshall(t *testing.T) {
if err != nil {
t.Errorf(`stats.CommonAPIData.DateStr expected format %v, actual %v`, srvhttp.CommonAPIDataDateFormat, stats.CommonAPIData.DateStr)
}
- if beforeStatsMarshall.Round(time.Second).After(statsDate) || statsDate.After(afterStatsMarshall.Round(time.Second)) { // round to second, because CommonAPIDataDateFormat is second-precision
- t.Errorf(`unmarshalling stats.CommonAPIData.DateStr expected between %v and %v, actual %v`, beforeStatsMarshall, afterStatsMarshall, stats.CommonAPIData.DateStr)
+ if beforeStatsMarshall.Truncate(time.Second).After(statsDate) || statsDate.After(afterStatsMarshall.Truncate(time.Second).Add(time.Second)) { // +/- 1 second, because CommonAPIDataDateFormat is second-precision
+ t.Errorf(`unmarshalling stats.CommonAPIData.DateStr expected between %v and %v, actual (%v) %v`, beforeStatsMarshall, afterStatsMarshall, statsDate, stats.CommonAPIData.DateStr)
}
if len(stats.Caches) > 0 {
t.Errorf(`unmarshalling stats.Caches expected empty, actual %+v`, stats.Caches)
diff --git a/traffic_monitor/cache/data_test.go b/traffic_monitor/cache/data_test.go
index 6d90774a6..d86c0d548 100644
--- a/traffic_monitor/cache/data_test.go
+++ b/traffic_monitor/cache/data_test.go
@@ -130,7 +130,7 @@ func randStatCacheStats() dsdata.StatCacheStats {
Tps3xx: dsdata.StatFloat{Value: rand.Float64(), StatMeta: randStatMeta()},
Tps2xx: dsdata.StatFloat{Value: rand.Float64(), StatMeta: randStatMeta()},
ErrorString: dsdata.StatString{Value: randStr(), StatMeta: randStatMeta()},
- TpsTotal: dsdata.StatInt{Value: rand.Int63(), StatMeta: randStatMeta()},
+ TpsTotal: dsdata.StatFloat{Value: rand.Float64(), StatMeta: randStatMeta()},
}
}
@@ -219,6 +219,45 @@ func randResult() Result {
}
+func randResultInfo() ResultInfo {
+ return ResultInfo{
+ ID: tc.CacheName(randStr()),
+ Error: fmt.Errorf(randStr()),
+ Time: time.Now(),
+ RequestTime: time.Millisecond * time.Duration(rand.Int()),
+ Vitals: randVitals(),
+ System: randAstatsSystem(),
+ PollID: uint64(rand.Int63()),
+ Available: randBool(),
+ }
+}
+
+func randResultStatVal() ResultStatVal {
+ return ResultStatVal{
+ Val: randStr(),
+ Time: time.Now(),
+ Span: uint64(rand.Int63()),
+ }
+}
+
+func randResultStatHistory() ResultStatHistory {
+ a := ResultStatHistory{}
+ num := 5
+ for i := 0; i < num; i++ {
+ a[tc.CacheName(randStr())] = randResultStatValHistory()
+ }
+ return a
+}
+
+func randResultStatValHistory() ResultStatValHistory {
+ a := ResultStatValHistory{}
+ num := 5
+ for i := 0; i < num; i++ {
+ a[randStr()] = randResultStatValSlice()
+ }
+ return a
+}
+
func randResultSlice() []Result {
a := []Result{}
num := 5
@@ -228,6 +267,42 @@ func randResultSlice() []Result {
return a
}
+func randResultStatValSlice() []ResultStatVal {
+ a := []ResultStatVal{}
+ num := 5
+ for i := 0; i < num; i++ {
+ a = append(a, randResultStatVal())
+ }
+ return a
+}
+
+func randResultInfoSlice() []ResultInfo {
+ a := []ResultInfo{}
+ num := 5
+ for i := 0; i < num; i++ {
+ a = append(a, randResultInfo())
+ }
+ return a
+}
+
+func randResultInfoHistory() ResultInfoHistory {
+ a := ResultInfoHistory{}
+ num := 5
+ for i := 0; i < num; i++ {
+ a[tc.CacheName(randStr())] = randResultInfoSlice()
+ }
+ return a
+}
+
+func randKbpses() Kbpses {
+ a := Kbpses{}
+ num := 5
+ for i := 0; i < num; i++ {
+ a[tc.CacheName(randStr())] = rand.Int63()
+ }
+ return a
+}
+
func randResultHistory() ResultHistory {
a := ResultHistory{}
num := 5
diff --git a/traffic_monitor/peer/peer_test.go b/traffic_monitor/peer/peer_test.go
index 627a8259e..18172d36c 100644
--- a/traffic_monitor/peer/peer_test.go
+++ b/traffic_monitor/peer/peer_test.go
@@ -8,9 +8,9 @@ package peer
* to you 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
@@ -19,11 +19,12 @@ package peer
* under the License.
*/
-
import (
"fmt"
"io/ioutil"
"testing"
+
+ "github.com/apache/incubator-trafficcontrol/lib/go-tc"
)
func TestCrStates(t *testing.T) {
@@ -33,7 +34,7 @@ func TestCrStates(t *testing.T) {
if err != nil {
t.Log(err)
}
- crStates, err := CrstatesUnMarshall(text)
+ crStates, err := tc.CRStatesUnMarshall(text)
if err != nil {
t.Log(err)
}
@@ -42,8 +43,8 @@ func TestCrStates(t *testing.T) {
t.Logf("%v -> %v", cacheName, crState.IsAvailable)
}
- fmt.Println(len(crStates.Deliveryservice), "deliveryservices found")
- for dsName, deliveryService := range crStates.Deliveryservice {
+ fmt.Println(len(crStates.DeliveryService), "deliveryservices found")
+ for dsName, deliveryService := range crStates.DeliveryService {
t.Logf("%v -> %v (len:%v)", dsName, deliveryService.IsAvailable, len(deliveryService.DisabledLocations))
}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services