Skip to content

Commit

Permalink
chore: typos fix
Browse files Browse the repository at this point in the history
  • Loading branch information
r3inbowari committed May 4, 2024
1 parent 8afeb37 commit 268cec0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
8 changes: 3 additions & 5 deletions speedtest/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,6 @@ func uploadRequest(ctx context.Context, s *Server, w int) error {
size := ulSizes[w]
dc := s.Context.NewChunk().UploadHandler(int64(size*100-51) * 10)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, s.URL, dc)
req.ContentLength = dc.(*DataChunk).ContentLength
dbg.Printf("Len=%d, XulURL: %s\n", req.ContentLength, s.URL)
if err != nil {
return err
}
Expand Down Expand Up @@ -208,12 +206,12 @@ func (s *Server) PingTestContext(ctx context.Context, callback func(latency time
return err
}
dbg.Printf("Before StandardDeviation: %v\n", vectorPingResult)
mean, _, std, min, max := StandardDeviation(vectorPingResult)
mean, _, std, minLatency, maxLatency := StandardDeviation(vectorPingResult)
duration := time.Since(start)
s.Latency = time.Duration(mean) * time.Nanosecond
s.Jitter = time.Duration(std) * time.Nanosecond
s.MinLatency = time.Duration(min) * time.Nanosecond
s.MaxLatency = time.Duration(max) * time.Nanosecond
s.MinLatency = time.Duration(minLatency) * time.Nanosecond
s.MaxLatency = time.Duration(maxLatency) * time.Nanosecond
s.TestDuration.Ping = &duration
s.testDurationTotalCount()
return nil
Expand Down
12 changes: 6 additions & 6 deletions speedtest/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func (s *Speedtest) FetchServerListContext(ctx context.Context) (Servers, error)
return Servers{}, err
}

payloadType := typeJSONPayload
_payloadType := typeJSONPayload

if resp.ContentLength == 0 {
_ = resp.Body.Close()
Expand All @@ -237,14 +237,14 @@ func (s *Speedtest) FetchServerListContext(ctx context.Context) (Servers, error)
return Servers{}, err
}

payloadType = typeXMLPayload
_payloadType = typeXMLPayload
}

defer resp.Body.Close()

var servers Servers

switch payloadType {
switch _payloadType {
case typeJSONPayload:
// Decode xml
decoder := json.NewDecoder(resp.Body)
Expand Down Expand Up @@ -360,14 +360,14 @@ func (servers Servers) FindServer(serverID []int) (Servers, error) {

if len(retServer) == 0 {
// choose the lowest latency server
var min int64 = math.MaxInt64
var minLatency int64 = math.MaxInt64
var minServerIndex int
for index, server := range servers {
if server.Latency <= 0 {
continue
}
if min > server.Latency.Milliseconds() {
min = server.Latency.Milliseconds()
if minLatency > server.Latency.Milliseconds() {
minLatency = server.Latency.Milliseconds()
minServerIndex = index
}
}
Expand Down
4 changes: 4 additions & 0 deletions speedtest/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ func TestCustomServer(t *testing.T) {
if err != nil {
t.Errorf(err.Error())
}
if got == nil {
t.Error("empty server")
return
}
if got.Host != "example.com" {
t.Error("did not properly set the Host field on a custom server")
}
Expand Down
4 changes: 4 additions & 0 deletions speedtest/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ func TestFetchUserInfo(t *testing.T) {
if err != nil {
t.Errorf(err.Error())
}
if user == nil {
t.Error("empty user info")
return
}
// IP
if len(user.IP) < 7 || len(user.IP) > 15 {
t.Errorf("invalid IP length. got: %v;", user.IP)
Expand Down

0 comments on commit 268cec0

Please sign in to comment.