Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Commit

Permalink
fix:unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Komey committed Jun 28, 2020
1 parent 6a87a33 commit 88b353f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 18 deletions.
6 changes: 3 additions & 3 deletions cmd/dfdaemon/app/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package app
import (
"bytes"
"fmt"
api "github.com/dragonflyoss/Dragonfly/dfget/core/api"
"github.com/dragonflyoss/Dragonfly/dfget/core/api"
"os"
"os/exec"
"os/user"
Expand Down Expand Up @@ -63,11 +63,11 @@ func getLocalIP(nodes []string) (localIP string) {
var (
e error
)
supernodeApi := api.NewSupernodeAPI()
supernodeAPI := api.NewSupernodeAPI()
for _, n := range nodes {
ip, port := netutils.GetIPAndPortFromNode(n, dfgetcfg.DefaultSupernodePort)
// step 1. query supernode api get request ip, check if request ip in local eth IPs
if localIP, e = supernodeApi.Ping(fmt.Sprintf("%s:%d", ip, port)); e == nil {
if localIP, e = supernodeAPI.Ping(fmt.Sprintf("%s:%d", ip, port)); e == nil {
logrus.Infof("Connect to supernode get self ip:%s", localIP)
if localIPs, err := netutils.GetAllIPs(); err == nil {
for _, lip := range localIPs {
Expand Down
6 changes: 3 additions & 3 deletions dfget/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,11 @@ func checkConnectSupernode(locator locator.SupernodeLocator) (localIP string) {
if locator == nil {
return ""
}
supernodeApi := api.NewSupernodeAPI()
supernodeAPI := api.NewSupernodeAPI()
for _, group := range locator.All() {
for _, n := range group.Nodes {
// step 1. query supernode api get request ip, check if request ip in local eth IPs
if localIP, e = supernodeApi.Ping(n.String()); e == nil {
if localIP, e = supernodeAPI.Ping(n.String()); e == nil {
logrus.Infof("Connect to supernode get self ip:%s", localIP)
if localIPs, err := netutils.GetAllIPs(); err == nil {
for _, lip := range localIPs {
Expand All @@ -306,7 +306,7 @@ func checkConnectSupernode(locator locator.SupernodeLocator) (localIP string) {
}
}
}
}else {
} else {
logrus.Warnf("Connect to supernode:%s error: %v", n, e)
}
// step 2. if request ip not in eth ips, it might behind NAT, try use TCP conn to get localIP
Expand Down
10 changes: 0 additions & 10 deletions pkg/httputils/http_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,6 @@ func (s *HTTPUtilTestSuite) TestCheckConnect(c *check.C) {
c.Assert(e, check.NotNil)
}

func (s *HTTPUtilTestSuite) TestCheckSuperNodeConnect(c *check.C) {
ip, e := CheckSuperNodeConnect("127.0.0.1", s.port, 0)
c.Assert(e, check.IsNil)
c.Assert(ip, check.Equals, "127.0.0.1")

// Test IPv6
_, e = CheckSuperNodeConnect("[::1]", s.port, 0)
c.Assert(e, check.NotNil)
}

func (s *HTTPUtilTestSuite) TestGetRangeSE(c *check.C) {
var cases = []struct {
rangeHTTPHeader string
Expand Down
4 changes: 2 additions & 2 deletions test/api_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ func (s *APIMetricsSuite) TestHttpMetrics(c *check.C) {
// Get httpRequest counter value equals 1.
CheckMetric(c, fmt.Sprintf(requestCounter, 200, "/_ping"), 1)

// Get httpResponse size sum value equals 2.
CheckMetric(c, fmt.Sprintf(responseSizeSum, "/_ping"), 2)
// Get httpResponse size sum value equals 9(127.0.0.1).
CheckMetric(c, fmt.Sprintf(responseSizeSum, "/_ping"), 9)

// Get httpResponse size count value equals 1.
CheckMetric(c, fmt.Sprintf(responseSizeCount, "/_ping"), 1)
Expand Down

0 comments on commit 88b353f

Please sign in to comment.