zrhoffman commented on code in PR #7302:
URL: https://github.com/apache/trafficcontrol/pull/7302#discussion_r1099371647
##########
traffic_monitor/todata/todata_test.go:
##########
@@ -142,3 +142,62 @@ func
TestGetDeliveryServiceServersWithNonTopologyBasedDeliveryService(t *testing
t.Fatalf("getDeliveryServiceServers with non-topology-based
delivery service expected: %+v actual: %+v", expectedNonTopologiesTOData,
nonTopologiesTOData)
}
}
+
+func TestGetSameIPServers(t *testing.T) {
+ mc := tc.TrafficMonitorConfigMap{TrafficServer:
make(map[string]tc.TrafficServer)}
+ mc.TrafficServer["server1_ip1"] = tc.TrafficServer{
+ Interfaces: []tc.ServerInterfaceInfo{
+ {
+ IPAddresses: []tc.ServerIPAddress{
+ {Address: "10.0.0.1", ServiceAddress:
true},
+ },
+ },
+ },
+ }
+ mc.TrafficServer["server2_ip1"] = tc.TrafficServer{
+ Interfaces: []tc.ServerInterfaceInfo{
+ {
+ IPAddresses: []tc.ServerIPAddress{
+ {Address: "10.0.0.1", ServiceAddress:
true},
+ },
+ },
+ },
+ }
+ mc.TrafficServer["server4_ip1_no_service"] = tc.TrafficServer{
+ Interfaces: []tc.ServerInterfaceInfo{
+ {
+ IPAddresses: []tc.ServerIPAddress{
+ {Address: "10.0.0.1"},
+ },
+ },
+ },
+ }
+ mc.TrafficServer["server3_ip3"] = tc.TrafficServer{
+ Interfaces: []tc.ServerInterfaceInfo{
+ {
+ IPAddresses: []tc.ServerIPAddress{
+ {Address: "10.0.0.3", ServiceAddress:
true},
+ },
+ },
+ },
+ }
+ sameIpServers := getSameIPServers(mc)
+ if _, ok := sameIpServers[("server1_ip1")]; !ok {
+ t.Fatal("getSameIPServers expected to find server1_ip1")
+ }
+ if _, ok := sameIpServers["server1_ip1"]["server2_ip1"]; !ok {
+ t.Fatal("getSameIPServers expected to find server1_ip1 to have
same ip as server2_ip1")
+ }
+ if _, ok := sameIpServers[tc.CacheName("server2_ip1")]; !ok {
+ t.Fatal("getSameIPServers expected to find server2_ip1")
+ }
+ if _, ok := sameIpServers["server1_ip1"]["server2_ip1"]; !ok {
+ t.Fatal("getSameIPServers expected to find server2_ip1 to have
same ip as server1_ip1")
+ }
+ if _, ok := sameIpServers["server1_ip1"]["server4_ip1_no_service"]; ok {
+ t.Fatal("getSameIPServers expected to find server1_ip1 not to
have same ip as server4_ip1_no_service")
+ }
+ if _, ok := sameIpServers[tc.CacheName("server3_ip3")]; ok {
+ t.Fatal("getSameIPServers expected to not find server3_ip3")
+ }
Review Comment:
The whole `sameIpServers` array can be checked once against an array
containing the expected result using `reflect.DeepEqual()` like this:
https://github.com/apache/trafficcontrol/blob/101304d5438e9ab487f0d94d075113a6858579db/traffic_monitor/todata/todata_test.go#L84
##########
traffic_monitor/datareq/crstate_test.go:
##########
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * 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
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package datareq
+
+import (
+ "github.com/apache/trafficcontrol/traffic_monitor/towrap"
+ "sync"
+ "testing"
+
+ "github.com/apache/trafficcontrol/lib/go-tc"
+ "github.com/apache/trafficcontrol/traffic_monitor/peer"
+ "github.com/apache/trafficcontrol/traffic_monitor/todata"
+)
+
+func TestUpdateStatusAnycast(t *testing.T) {
+
+ localStates := peer.NewCRStatesThreadsafe()
+ sameIpServers := map[tc.CacheName]map[tc.CacheName]bool{}
+
+ toData := todata.NewThreadsafe()
+ towrap.TrafficOpsSessionThreadsafe{}
+ toData.Update()
+
+ TODataThreadsafe{m: &sync.RWMutex{}, toData: New()}
+
+ localStates.AddCache("available", tc.IsAvailable{IsAvailable: true,
Ipv4Available: true, Ipv6Available: true})
+ localStates.AddCache("tooHigh", tc.IsAvailable{IsAvailable: false,
Ipv4Available: true, Ipv6Available: true, Status: "too high"})
Review Comment:
Maybe you can reuse (or copy) this code that does something similar?
https://github.com/apache/trafficcontrol/blob/d95a16c57f69cc186da237919be61387bf154e95/traffic_monitor/ds/stat_test.go#L59-L79
##########
traffic_monitor/todata/todata_test.go:
##########
@@ -142,3 +142,62 @@ func
TestGetDeliveryServiceServersWithNonTopologyBasedDeliveryService(t *testing
t.Fatalf("getDeliveryServiceServers with non-topology-based
delivery service expected: %+v actual: %+v", expectedNonTopologiesTOData,
nonTopologiesTOData)
}
}
+
+func TestGetSameIPServers(t *testing.T) {
+ mc := tc.TrafficMonitorConfigMap{TrafficServer:
make(map[string]tc.TrafficServer)}
+ mc.TrafficServer["server1_ip1"] = tc.TrafficServer{
Review Comment:
The lines initializing `mc.TrafficServer` and adding to it can be combined:
```go
mc := tc.TrafficMonitorConfigMap{TrafficServer:
map[string]tc.TrafficServer{
"server1_ip1": tc.TrafficServer{Interfaces:
[]tc.ServerInterfaceInfo{
{IPAddresses: []tc.ServerIPAddress{{Address:
"10.0.0.1", ServiceAddress: true}}},
}},
/* and so on */
}}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]