Skip to content

Commit

Permalink
Merge branch 'master' into x
Browse files Browse the repository at this point in the history
  • Loading branch information
robertodauria committed Jul 1, 2021
2 parents 100604f + 6958d23 commit 07a331d
Show file tree
Hide file tree
Showing 28 changed files with 1,840 additions and 833 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: go
go:
- 1.13.x
dist: xenial
- 1.16
dist: bionic

before_script:
- go get golang.org/x/tools/cmd/cover
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
[![GoDoc](https://godoc.org/github.com/m-lab/ndt7-client-go?status.svg)](https://godoc.org/github.com/m-lab/ndt7-client-go) [![Build Status](https://travis-ci.org/m-lab/ndt7-client-go.svg?branch=master)](https://travis-ci.org/m-lab/ndt7-client-go) [![Coverage Status](https://coveralls.io/repos/github/m-lab/ndt7-client-go/badge.svg?branch=master)](https://coveralls.io/github/m-lab/ndt7-client-go?branch=master) [![Go Report Card](https://goreportcard.com/badge/github.com/m-lab/ndt7-client-go)](https://goreportcard.com/report/github.com/m-lab/ndt7-client-go)

:exclamation: **Breaking changes are planned for some ndt7 clients.** :exclamation:

> If you are using ndt7-client.exe to target specific M-Lab servers, please
contact support@measurementlab.net. These clients should be scheduled
randomly rather than synchronously to improve server & client measurements.
We are deploying changes to the ndt-server to require access tokens in the
near future.

# ndt7 Go client

Reference ndt7 Go client implementation. Useful resources:
Expand Down
112 changes: 0 additions & 112 deletions cmd/ndt7-client/internal/emitter/batch.go

This file was deleted.

7 changes: 6 additions & 1 deletion cmd/ndt7-client/internal/emitter/emitter.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Package emitter contains the ndt7-client emitter.
package emitter

import "github.com/m-lab/ndt7-client-go/spec"
import (
"github.com/m-lab/ndt7-client-go/spec"
)

// Emitter is a generic emitter. When an event occurs, the
// corresponding method will be called. An error will generally
Expand Down Expand Up @@ -29,4 +31,7 @@ type Emitter interface {

// OnComplete is always emitted when the test is over.
OnComplete(test spec.TestKind) error

// OnSummary is emitted after the test is over.
OnSummary(s *Summary) error
}
100 changes: 100 additions & 0 deletions cmd/ndt7-client/internal/emitter/humanreadable.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package emitter

import (
"errors"
"fmt"
"io"
"os"

"github.com/m-lab/ndt7-client-go/spec"
)

// HumanReadable is a human readable emitter. It emits the events generated
// by running a ndt7 test as pleasant stdout messages.
type HumanReadable struct {
out io.Writer
}

// NewHumanReadable returns a new human readable emitter.
func NewHumanReadable() Emitter {
return HumanReadable{os.Stdout}
}

// NewHumanReadableWithWriter returns a new human readable emitter using the
// specified writer.
func NewHumanReadableWithWriter(w io.Writer) Emitter {
return HumanReadable{w}
}

// OnStarting handles the start event
func (h HumanReadable) OnStarting(test spec.TestKind) error {
_, err := fmt.Fprintf(h.out, "\rstarting %s", test)
return err
}

// OnError handles the error event
func (h HumanReadable) OnError(test spec.TestKind, err error) error {
_, failure := fmt.Fprintf(h.out, "\r%s failed: %s\n", test, err.Error())
return failure
}

// OnConnected handles the connected event
func (h HumanReadable) OnConnected(test spec.TestKind, fqdn string) error {
_, err := fmt.Fprintf(h.out, "\r%s in progress with %s\n", test, fqdn)
return err
}

// OnDownloadEvent handles an event emitted by the download test
func (h HumanReadable) OnDownloadEvent(m *spec.Measurement) error {
return h.onSpeedEvent(m)
}

// OnUploadEvent handles an event emitted during the upload test
func (h HumanReadable) OnUploadEvent(m *spec.Measurement) error {
return h.onSpeedEvent(m)
}

func (h HumanReadable) onSpeedEvent(m *spec.Measurement) error {
// The specification recommends that we show application level
// measurements. Let's just do that in interactive mode. To this
// end, we ignore any measurement coming from the server.
if m.Origin != spec.OriginClient {
return nil
}
if m.AppInfo == nil || m.AppInfo.ElapsedTime <= 0 {
return errors.New("Missing m.AppInfo or invalid m.AppInfo.ElapsedTime")
}
elapsed := float64(m.AppInfo.ElapsedTime) / 1e06
v := (8.0 * float64(m.AppInfo.NumBytes)) / elapsed / (1000.0 * 1000.0)
_, err := fmt.Fprintf(h.out, "\rAvg. speed : %7.1f Mbit/s", v)
return err
}

// OnComplete handles the complete event
func (h HumanReadable) OnComplete(test spec.TestKind) error {
_, err := fmt.Fprintf(h.out, "\n%s: complete\n", test)
return err
}

// OnSummary handles the summary event.
func (h HumanReadable) OnSummary(s *Summary) error {
const summaryFormat = `%15s: %s
%15s: %s
%15s: %7.1f %s
%15s: %7.1f %s
%15s: %7.1f %s
%15s: %7.2f %s
`
_, err := fmt.Fprintf(h.out, summaryFormat,
"Server", s.ServerFQDN,
"Client", s.ClientIP,
"Latency", s.MinRTT.Value, s.MinRTT.Unit,
"Download", s.Download.Value, s.Upload.Unit,
"Upload", s.Upload.Value, s.Upload.Unit,
"Retransmission", s.DownloadRetrans.Value, s.DownloadRetrans.Unit)
if err != nil {
return err
}

return nil
}
Loading

0 comments on commit 07a331d

Please sign in to comment.