Merge master into resover-refactor

This commit is contained in:
Ben Toogood 2020-04-09 12:42:34 +01:00
commit f9cfbe96c0
19 changed files with 140 additions and 63 deletions

View File

@ -18,7 +18,7 @@ import (
func TestCertMagic(t *testing.T) {
if len(os.Getenv("IN_TRAVIS_CI")) != 0 {
t.Skip("Travis doesn't let us bind :443")
t.Skip()
}
l, err := NewProvider().Listen()
if err != nil {
@ -52,6 +52,10 @@ func TestCertMagic(t *testing.T) {
}
func TestStorageImplementation(t *testing.T) {
if len(os.Getenv("IN_TRAVIS_CI")) != 0 {
t.Skip()
}
apiToken, accountID := os.Getenv("CF_API_TOKEN"), os.Getenv("CF_ACCOUNT_ID")
kvID := os.Getenv("KV_NAMESPACE_ID")
if len(apiToken) == 0 || len(accountID) == 0 || len(kvID) == 0 {
@ -189,6 +193,10 @@ func TestStorageImplementation(t *testing.T) {
// Full test with a real zone, with against LE staging
func TestE2e(t *testing.T) {
if len(os.Getenv("IN_TRAVIS_CI")) != 0 {
t.Skip()
}
apiToken, accountID := os.Getenv("CF_API_TOKEN"), os.Getenv("CF_ACCOUNT_ID")
kvID := os.Getenv("KV_NAMESPACE_ID")
if len(apiToken) == 0 || len(accountID) == 0 || len(kvID) == 0 {

View File

@ -1,6 +1,7 @@
package selector
import (
"os"
"testing"
"github.com/micro/go-micro/v2/registry/memory"
@ -25,5 +26,7 @@ func TestRegistrySelector(t *testing.T) {
counts[node.Id]++
}
t.Logf("Selector Counts %v", counts)
if len(os.Getenv("IN_TRAVIS_CI")) == 0 {
t.Logf("Selector Counts %v", counts)
}
}

View File

@ -1,6 +1,7 @@
package selector
import (
"os"
"testing"
"github.com/micro/go-micro/v2/registry"
@ -50,6 +51,8 @@ func TestStrategies(t *testing.T) {
counts[node.Id]++
}
t.Logf("%s: %+v\n", name, counts)
if len(os.Getenv("IN_TRAVIS_CI")) == 0 {
t.Logf("%s: %+v\n", name, counts)
}
}
}

View File

@ -231,7 +231,7 @@ var (
},
&cli.StringFlag{
Name: "store_table",
EnvVars: []string{"MICRO_STORE_Table"},
EnvVars: []string{"MICRO_STORE_TABLE"},
Usage: "Table option for the underlying store",
},
&cli.StringFlag{

View File

@ -59,8 +59,8 @@ func TestFile(t *testing.T) {
if err != nil {
t.Error(err)
}
t.Logf("%+v", c)
if string(c.Data) != string(data) {
t.Logf("%+v", c)
t.Error("data from file does not match")
}
}

View File

@ -2,6 +2,7 @@ package memory
import (
"fmt"
"os"
"testing"
"time"
@ -205,7 +206,9 @@ func TestMemoryRegistryTTLConcurrent(t *testing.T) {
}
}
t.Logf("test will wait %v, then check TTL timeouts", waitTime)
if len(os.Getenv("IN_TRAVIS_CI")) == 0 {
t.Logf("test will wait %v, then check TTL timeouts", waitTime)
}
errChan := make(chan error, concurrency)
syncChan := make(chan struct{})

View File

@ -1,6 +1,7 @@
package registry
import (
"os"
"testing"
)
@ -32,7 +33,9 @@ func TestRemove(t *testing.T) {
if i := len(servs); i > 0 {
t.Errorf("Expected 0 nodes, got %d: %+v", i, servs)
}
t.Logf("Services %+v", servs)
if len(os.Getenv("IN_TRAVIS_CI")) == 0 {
t.Logf("Services %+v", servs)
}
}
func TestRemoveNodes(t *testing.T) {
@ -67,5 +70,7 @@ func TestRemoveNodes(t *testing.T) {
if i := len(nodes); i != 1 {
t.Errorf("Expected only 1 node, got %d: %+v", i, nodes)
}
t.Logf("Nodes %+v", nodes)
if len(os.Getenv("IN_TRAVIS_CI")) == 0 {
t.Logf("Nodes %+v", nodes)
}
}

View File

@ -2,6 +2,7 @@ package router
import (
"fmt"
"os"
"sync"
"testing"
"time"
@ -29,7 +30,9 @@ func TestRouterStartStop(t *testing.T) {
if err := r.Stop(); err != nil {
t.Errorf("failed to stop router: %v", err)
}
t.Logf("TestRouterStartStop STOPPED")
if len(os.Getenv("IN_TRAVIS_CI")) == 0 {
t.Logf("TestRouterStartStop STOPPED")
}
}
func TestRouterAdvertise(t *testing.T) {
@ -49,7 +52,9 @@ func TestRouterAdvertise(t *testing.T) {
// receive announce event
ann := <-ch
t.Logf("received announce advert: %v", ann)
if len(os.Getenv("IN_TRAVIS_CI")) == 0 {
t.Logf("received announce advert: %v", ann)
}
// Generate random unique routes
nrRoutes := 5
@ -81,9 +86,13 @@ func TestRouterAdvertise(t *testing.T) {
wg.Done()
defer close(createDone)
for _, route := range routes {
t.Logf("Creating route %v", route)
if len(os.Getenv("IN_TRAVIS_CI")) == 0 {
t.Logf("Creating route %v", route)
}
if err := r.Table().Create(route); err != nil {
t.Logf("Failed to create route: %v", err)
if len(os.Getenv("IN_TRAVIS_CI")) == 0 {
t.Logf("Failed to create route: %v", err)
}
errChan <- err
return
}
@ -105,7 +114,9 @@ func TestRouterAdvertise(t *testing.T) {
t.Errorf("failed advertising events: %v", advertErr)
default:
// do nothing for now
t.Logf("Router advert received: %v", advert)
if len(os.Getenv("IN_TRAVIS_CI")) == 0 {
t.Logf("Router advert received: %v", advert)
}
adverts += len(advert.Events)
}
return

View File

@ -204,7 +204,6 @@ func (r *runtime) Create(s *Service, opts ...CreateOption) error {
service := newService(s, options)
f, err := os.OpenFile(logFile(service.Name), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
logger.Info(f, err)
if err != nil {
log.Fatal(err)
}

View File

@ -713,7 +713,7 @@ func (g *grpcServer) Register() error {
}
if logger.V(logger.DebugLevel, logger.DefaultLogger) {
logger.Debug("Subscribing to topic: %s", sb.Topic())
logger.Debugf("Subscribing to topic: %s", sb.Topic())
}
sub, err := config.Broker.Subscribe(sb.Topic(), handler, opts...)
if err != nil {

View File

@ -11,6 +11,10 @@ import (
)
func TestCloudflare(t *testing.T) {
if len(os.Getenv("IN_TRAVIS_CI")) != 0 {
t.Skip()
}
apiToken, accountID := os.Getenv("CF_API_TOKEN"), os.Getenv("CF_ACCOUNT_ID")
kvID := os.Getenv("KV_NAMESPACE_ID")
if len(apiToken) == 0 || len(accountID) == 0 || len(kvID) == 0 {
@ -31,7 +35,9 @@ func TestCloudflare(t *testing.T) {
if err != nil {
t.Fatalf("List: %s\n", err.Error())
} else {
t.Log("Listed " + strconv.Itoa(len(records)) + " records")
if len(os.Getenv("IN_TRAVIS_CI")) == 0 {
t.Log("Listed " + strconv.Itoa(len(records)) + " records")
}
}
err = wkv.Write(&store.Record{

View File

@ -3,6 +3,7 @@ package cockroach
import (
"database/sql"
"fmt"
"os"
"testing"
"time"
@ -11,6 +12,10 @@ import (
)
func TestSQL(t *testing.T) {
if len(os.Getenv("IN_TRAVIS_CI")) != 0 {
t.Skip()
}
connection := fmt.Sprintf(
"host=%s port=%d user=%s sslmode=disable dbname=%s",
"localhost",
@ -23,7 +28,7 @@ func TestSQL(t *testing.T) {
t.Fatal(err)
}
if err := db.Ping(); err != nil {
t.Skip(err)
t.Fatal(err)
}
db.Close()

View File

@ -53,8 +53,9 @@ func TestFileStoreDatabaseTable(t *testing.T) {
}
func fileTest(s store.Store, t *testing.T) {
t.Logf("Options %s %v\n", s.String(), s.Options())
if len(os.Getenv("IN_TRAVIS_CI")) == 0 {
t.Logf("Options %s %v\n", s.String(), s.Options())
}
// Read and Write an expiring Record
if err := s.Write(&store.Record{
Key: "Hello",
@ -109,7 +110,7 @@ func fileTest(s store.Store, t *testing.T) {
} else {
if len(results) != 2 {
t.Errorf("Expected 2 items, got %d", len(results))
t.Logf("Table test: %v\n", spew.Sdump(results))
//t.Logf("Table test: %v\n", spew.Sdump(results))
}
}
@ -120,7 +121,7 @@ func fileTest(s store.Store, t *testing.T) {
t.Errorf("Couldn't read all \"foo\" keys, got %# v (%s)", spew.Sdump(results), err)
} else if len(results) != 1 {
t.Errorf("Expected 1 item, got %d", len(results))
t.Logf("Table test: %v\n", spew.Sdump(results))
//t.Logf("Table test: %v\n", spew.Sdump(results))
}
if err := s.Delete("foo"); err != nil {
@ -163,7 +164,7 @@ func fileTest(s store.Store, t *testing.T) {
} else {
if len(results) != 3 {
t.Errorf("Expected 3 items, got %d", len(results))
t.Logf("Table test: %v\n", spew.Sdump(results))
//t.Logf("Table test: %v\n", spew.Sdump(results))
}
}
@ -173,7 +174,7 @@ func fileTest(s store.Store, t *testing.T) {
} else {
if len(results) != 2 {
t.Errorf("Expected 2 items, got %d", len(results))
t.Logf("Table test: %v\n", spew.Sdump(results))
//t.Logf("Table test: %v\n", spew.Sdump(results))
}
}
@ -183,7 +184,7 @@ func fileTest(s store.Store, t *testing.T) {
} else {
if len(results) != 1 {
t.Errorf("Expected 1 item, got %d", len(results))
t.Logf("Table test: %# v\n", spew.Sdump(results))
// t.Logf("Table test: %# v\n", spew.Sdump(results))
}
}
if err := s.Delete("foo"); err != nil {

View File

@ -2,6 +2,7 @@ package memory
import (
"fmt"
"os"
"testing"
"time"
@ -42,7 +43,9 @@ func TestMemoryNamespacePrefix(t *testing.T) {
}
func basictest(s store.Store, t *testing.T) {
t.Logf("Testing store %s, with options %# v\n", s.String(), pretty.Formatter(s.Options()))
if len(os.Getenv("IN_TRAVIS_CI")) == 0 {
t.Logf("Testing store %s, with options %# v\n", s.String(), pretty.Formatter(s.Options()))
}
// Read and Write an expiring Record
if err := s.Write(&store.Record{
Key: "Hello",
@ -97,7 +100,9 @@ func basictest(s store.Store, t *testing.T) {
if len(results) != 3 {
t.Errorf("Expected 3 items, got %d", len(results))
}
t.Logf("Prefix test: %v\n", pretty.Formatter(results))
if len(os.Getenv("IN_TRAVIS_CI")) == 0 {
t.Logf("Prefix test: %v\n", pretty.Formatter(results))
}
}
time.Sleep(time.Millisecond * 100)
if results, err := s.Read("foo", store.ReadPrefix()); err != nil {
@ -106,7 +111,9 @@ func basictest(s store.Store, t *testing.T) {
if len(results) != 2 {
t.Errorf("Expected 2 items, got %d", len(results))
}
t.Logf("Prefix test: %v\n", pretty.Formatter(results))
if len(os.Getenv("IN_TRAVIS_CI")) == 0 {
t.Logf("Prefix test: %v\n", pretty.Formatter(results))
}
}
time.Sleep(time.Millisecond * 100)
if results, err := s.Read("foo", store.ReadPrefix()); err != nil {
@ -115,7 +122,9 @@ func basictest(s store.Store, t *testing.T) {
if len(results) != 1 {
t.Errorf("Expected 1 item, got %d", len(results))
}
t.Logf("Prefix test: %# v\n", pretty.Formatter(results))
if len(os.Getenv("IN_TRAVIS_CI")) == 0 {
t.Logf("Prefix test: %# v\n", pretty.Formatter(results))
}
}
if err := s.Delete("foo", func(d *store.DeleteOptions) {}); err != nil {
t.Errorf("Delete failed (%v)", err)
@ -156,7 +165,9 @@ func basictest(s store.Store, t *testing.T) {
if len(results) != 3 {
t.Errorf("Expected 3 items, got %d", len(results))
}
t.Logf("Prefix test: %v\n", pretty.Formatter(results))
if len(os.Getenv("IN_TRAVIS_CI")) == 0 {
t.Logf("Prefix test: %v\n", pretty.Formatter(results))
}
}
time.Sleep(time.Millisecond * 100)
if results, err := s.Read("foo", store.ReadSuffix()); err != nil {
@ -165,7 +176,9 @@ func basictest(s store.Store, t *testing.T) {
if len(results) != 2 {
t.Errorf("Expected 2 items, got %d", len(results))
}
t.Logf("Prefix test: %v\n", pretty.Formatter(results))
if len(os.Getenv("IN_TRAVIS_CI")) == 0 {
t.Logf("Prefix test: %v\n", pretty.Formatter(results))
}
}
time.Sleep(time.Millisecond * 100)
if results, err := s.Read("foo", store.ReadSuffix()); err != nil {
@ -174,7 +187,9 @@ func basictest(s store.Store, t *testing.T) {
if len(results) != 1 {
t.Errorf("Expected 1 item, got %d", len(results))
}
t.Logf("Prefix test: %# v\n", pretty.Formatter(results))
if len(os.Getenv("IN_TRAVIS_CI")) == 0 {
t.Logf("Prefix test: %# v\n", pretty.Formatter(results))
}
}
if err := s.Delete("foo"); err != nil {
t.Errorf("Delete failed (%v)", err)

View File

@ -16,18 +16,15 @@ import (
type serviceStore struct {
options store.Options
// Namespace to use
Namespace string
// The database to use
Database string
// The table to use
Table string
// Addresses of the nodes
Nodes []string
// Prefix to use
Prefix string
// Suffix to use
Suffix string
// store service client
Client pb.StoreService
}
@ -40,8 +37,8 @@ func (s *serviceStore) Init(opts ...store.Option) error {
for _, o := range opts {
o(&s.options)
}
s.Namespace = s.options.Database
s.Prefix = s.options.Table
s.Database = s.options.Database
s.Table = s.options.Table
s.Nodes = s.options.Nodes
return nil
@ -52,12 +49,12 @@ func (s *serviceStore) Context() context.Context {
md := make(metadata.Metadata)
if len(s.Namespace) > 0 {
md["Micro-Namespace"] = s.Namespace
if len(s.Database) > 0 {
md["Micro-Database"] = s.Database
}
if len(s.Prefix) > 0 {
md["Micro-Prefix"] = s.Prefix
if len(s.Table) > 0 {
md["Micro-Table"] = s.Table
}
return metadata.NewContext(ctx, md)
@ -168,11 +165,11 @@ func NewStore(opts ...store.Option) store.Store {
}
service := &serviceStore{
options: options,
Namespace: options.Database,
Prefix: options.Table,
Nodes: options.Nodes,
Client: pb.NewStoreService("go.micro.store", client.DefaultClient),
options: options,
Database: options.Database,
Table: options.Table,
Nodes: options.Nodes,
Client: pb.NewStoreService("go.micro.store", client.DefaultClient),
}
return service

View File

@ -1,6 +1,7 @@
package memory
import (
"os"
"testing"
"github.com/micro/go-micro/v2/transport"
@ -24,7 +25,9 @@ func TestMemoryTransport(t *testing.T) {
if err := sock.Recv(&m); err != nil {
return
}
t.Logf("Server Received %s", string(m.Body))
if len(os.Getenv("IN_TRAVIS_CI")) == 0 {
t.Logf("Server Received %s", string(m.Body))
}
if err := sock.Send(&transport.Message{
Body: []byte(`pong`),
}); err != nil {
@ -54,7 +57,9 @@ func TestMemoryTransport(t *testing.T) {
if err := c.Recv(&m); err != nil {
return
}
t.Logf("Client Received %s", string(m.Body))
if len(os.Getenv("IN_TRAVIS_CI")) == 0 {
t.Logf("Client Received %s", string(m.Body))
}
}
}

View File

@ -1,6 +1,7 @@
package tunnel
import (
"os"
"sync"
"testing"
"time"
@ -288,12 +289,15 @@ func TestTunnelRTTRate(t *testing.T) {
// wait until done
wg.Wait()
for _, link := range tunA.Links() {
t.Logf("Link %s length %v rate %v", link.Id(), link.Length(), link.Rate())
}
if len(os.Getenv("IN_TRAVIS_CI")) == 0 {
// only needed for debug
for _, link := range tunA.Links() {
t.Logf("Link %s length %v rate %v", link.Id(), link.Length(), link.Rate())
}
for _, link := range tunB.Links() {
t.Logf("Link %s length %v rate %v", link.Id(), link.Length(), link.Rate())
for _, link := range tunB.Links() {
t.Logf("Link %s length %v rate %v", link.Id(), link.Length(), link.Rate())
}
}
}

View File

@ -226,8 +226,8 @@ func (s *service) start() error {
ch <- l.Close()
}()
if logger.V(logger.InfoLevel, log) {
log.Infof("Listening on %v", l.Addr().String())
if logger.V(logger.DebugLevel, log) {
log.Debugf("Listening on %v", l.Addr().String())
}
return nil
}
@ -370,6 +370,10 @@ func (s *service) Init(opts ...Option) error {
return nil
}))
// pass in own name and version
serviceOpts = append(serviceOpts, micro.Name(s.opts.Name))
serviceOpts = append(serviceOpts, micro.Version(s.opts.Version))
s.opts.Service.Init(serviceOpts...)
srv := s.genSrv()
srv.Endpoints = s.srv.Endpoints

View File

@ -110,7 +110,9 @@ func TestService(t *testing.T) {
t.Fatalf("service.Run():%v", err)
}
case <-time.After(time.Duration(time.Second)):
t.Logf("service.Run() survived a client request without an error")
if len(os.Getenv("IN_TRAVIS_CI")) == 0 {
t.Logf("service.Run() survived a client request without an error")
}
}
ch := make(chan os.Signal, 1)
@ -125,10 +127,14 @@ func TestService(t *testing.T) {
if err != nil {
t.Fatalf("service.Run():%v", err)
} else {
t.Log("service.Run() nil return on syscall.SIGTERM")
if len(os.Getenv("IN_TRAVIS_CI")) == 0 {
t.Log("service.Run() nil return on syscall.SIGTERM")
}
}
case <-time.After(time.Duration(time.Second)):
t.Logf("service.Run() survived a client request without an error")
if len(os.Getenv("IN_TRAVIS_CI")) == 0 {
t.Logf("service.Run() survived a client request without an error")
}
}
eventually(func() bool {
@ -286,7 +292,9 @@ func TestTLS(t *testing.T) {
t.Fatalf("service.Run():%v", err)
}
case <-time.After(time.Duration(time.Second)):
t.Logf("service.Run() survived a client request without an error")
if len(os.Getenv("IN_TRAVIS_CI")) == 0 {
t.Logf("service.Run() survived a client request without an error")
}
}
}