rpc: prefix log output with test name

This commit is contained in:
Frank Schroeder 2017-06-26 10:46:20 +02:00 committed by Frank Schröder
parent c33f7ecbe2
commit 457910b191
1 changed files with 15 additions and 6 deletions

View File

@ -2,10 +2,12 @@ package consul
import ( import (
"fmt" "fmt"
"log"
"math/rand" "math/rand"
"net" "net"
"os" "os"
"strings" "strings"
"sync/atomic"
"testing" "testing"
"time" "time"
@ -109,17 +111,19 @@ func testServerDCExpect(t *testing.T, dc string, expect int) (string, *Server) {
}) })
} }
func testServerWithConfig(t *testing.T, cb func(c *Config)) (string, *Server) { var id int64
name := fmt.Sprintf("Node %d", getPort())
dir, config := testServerConfig(t, name) func testServerWithConfig(t *testing.T, cb func(*Config)) (string, *Server) {
nodeName := fmt.Sprintf("%s-node-%d", t.Name(), atomic.AddInt64(&id, 1))
dir, config := testServerConfig(t, nodeName)
if cb != nil { if cb != nil {
cb(config) cb(config)
} }
server, err := newServer(config) srv, err := newServer(config)
if err != nil { if err != nil {
t.Fatalf("err: %v", err) t.Fatalf("err: %v", err)
} }
return dir, server return dir, srv
} }
func newServer(c *Config) (*Server, error) { func newServer(c *Config) (*Server, error) {
@ -134,7 +138,12 @@ func newServer(c *Config) (*Server, error) {
} }
// start server // start server
srv, err := NewServer(c) w := c.LogOutput
if w == nil {
w = os.Stderr
}
logger := log.New(w, c.NodeName+" - ", log.LstdFlags|log.Lmicroseconds)
srv, err := NewServerLogger(c, logger)
if err != nil { if err != nil {
return nil, err return nil, err
} }