Skip to content

Commit

Permalink
Bump up coverage numbers in a few packages. (istio#4519)
Browse files Browse the repository at this point in the history
  • Loading branch information
geeknoid authored Mar 24, 2018
1 parent e0f2810 commit 773b667
Show file tree
Hide file tree
Showing 15 changed files with 61 additions and 31 deletions.
4 changes: 2 additions & 2 deletions codecov.requirement
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ istio.io/istio/mixer/pkg/runtime/handler:94 [96.9]
istio.io/istio/mixer/pkg/runtime/routing:100 [100.0]
istio.io/istio/mixer/pkg/runtime/testing/data:2 [4.6]
istio.io/istio/mixer/pkg/runtime/testing/util:0 [0.0]
istio.io/istio/mixer/pkg/server:97 [99.4]
istio.io/istio/mixer/pkg/status:77 [79.3]
istio.io/istio/mixer/pkg/server:100 [100.0]
istio.io/istio/mixer/pkg/status:100 [100.0]
istio.io/istio/mixer/pkg/template:46 [48.9]
istio.io/istio/mixer/template:0 [0.0]
istio.io/istio/mixer/template/apikey:0 [0.0]
Expand Down
1 change: 1 addition & 0 deletions codecov.skip
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
istio.io/istio/mixer/pkg/config/storetest
istio.io/istio/mixer/pkg/mockapi
istio.io/istio/mixer/pkg/perf
istio.io/istio/mixer/pkg/runtime/testing
Expand Down
3 changes: 3 additions & 0 deletions mixer/adapter/denier/denier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ func TestBasic(t *testing.T) {
}

b := info.NewBuilder().(*builder)
b.SetCheckNothingTypes(nil)
b.SetListEntryTypes(nil)
b.SetQuotaTypes(nil)
b.SetAdapterConfig(info.DefaultConfig)

if err := b.Validate(); err != nil {
Expand Down
8 changes: 8 additions & 0 deletions mixer/adapter/noop/noop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ func TestBasic(t *testing.T) {

cfg := info.DefaultConfig
b := info.NewBuilder().(*builder)
b.SetCheckNothingTypes(nil)
b.SetAuthorizationTypes(nil)
b.SetReportNothingTypes(nil)
b.SetListEntryTypes(nil)
b.SetLogEntryTypes(nil)
b.SetMetricTypes(nil)
b.SetQuotaTypes(nil)
b.SetTraceSpanTypes(nil)
b.SetAdapterConfig(cfg)

if err := b.Validate(); err != nil {
Expand Down
13 changes: 13 additions & 0 deletions mixer/pkg/attribute/bag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,19 @@ func TestFakeMutableBag(t *testing.T) {
}
}

func TestGlobalList(t *testing.T) {
l := GlobalList()

// check that there's a known string in there...
for _, s := range l {
if s == "destination.service" {
return
}
}

t.Error("Did not find destination.service")
}

func init() {
// bump up the log level so log-only logic runs during the tests, for correctness and coverage.
o := log.DefaultOptions()
Expand Down
1 change: 0 additions & 1 deletion mixer/pkg/perf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ type Config struct {
EnableLog bool `json:"enableLog,omitempty"`
EnableDebugLog bool `json:"enableDebugLog,omitempty"`
SingleThreaded bool `json:"singleThreaded,omitempty"`
UseRuntime2 bool `json:"useRuntime2,omitempty"`

// Templates is the name of the templates to use in this test. If left empty, a standard set of templates
// will be used.
Expand Down
8 changes: 4 additions & 4 deletions mixer/pkg/runtime/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var hgp = pool.NewGoroutinePool(1, true)
var adapters = data.BuildAdapters(nil)
var templates = data.BuildTemplates(nil)

func TestRuntime2_Basic(t *testing.T) {
func TestRuntime_Basic(t *testing.T) {
s := &mockStore{}

rt := New(
Expand Down Expand Up @@ -85,7 +85,7 @@ func TestRuntime2_Basic(t *testing.T) {
}
}

func TestRuntime2_ErrorDuringWatch(t *testing.T) {
func TestRuntime_ErrorDuringWatch(t *testing.T) {
s := &mockStore{}
s.watchErrorToReturn = errors.New("error during watch")

Expand All @@ -103,7 +103,7 @@ func TestRuntime2_ErrorDuringWatch(t *testing.T) {
}
}

func TestRuntime2_OnConfigChange(t *testing.T) {
func TestRuntime_OnConfigChange(t *testing.T) {
s := &mockStore{
listResultToReturn: map[store.Key]*store.Resource{},
}
Expand Down Expand Up @@ -169,7 +169,7 @@ Attributes:
}
}

func TestRuntime2_InFlightRequestsDuringConfigChange(t *testing.T) {
func TestRuntime_InFlightRequestsDuringConfigChange(t *testing.T) {
s := &mockStore{
listResultToReturn: map[store.Key]*store.Resource{},
}
Expand Down
20 changes: 7 additions & 13 deletions mixer/pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ type listenFunc func(network string, address string) (net.Listener, error)

// replaceable set of functions for fault injection
type patchTable struct {
newStore func(r2 *store.Registry, configURL string) (store.Store, error)
newRuntime2 func(s store.Store, templates map[string]*template.Info, adapters map[string]*adapter.Info,
newRuntime func(s store.Store, templates map[string]*template.Info, adapters map[string]*adapter.Info,
identityAttribute string, defaultConfigNamespace string, executorPool *pool.GoroutinePool,
handlerPool *pool.GoroutinePool, enableTracing bool) *runtime.Runtime
configTracing func(serviceName string, options *tracing.Options) (io.Closer, error)
Expand All @@ -79,8 +78,7 @@ func New(a *Args) (*Server, error) {

func newPatchTable() *patchTable {
return &patchTable{
newStore: func(r2 *store.Registry, configURL string) (store.Store, error) { return r2.NewStore(configURL) },
newRuntime2: runtime.New,
newRuntime: runtime.New,
configTracing: tracing.Configure,
startMonitor: startMonitor,
listen: net.Listen,
Expand Down Expand Up @@ -152,14 +150,15 @@ func newServer(a *Args, p *patchTable) (*Server, error) {
_ = s.Close()
return nil, fmt.Errorf("invalid arguments: both ConfigStore and ConfigStoreURL are specified")
}

if st == nil {
configStoreURL := a.ConfigStoreURL
if configStoreURL == "" {
configStoreURL = "k8s://"
}

reg := store.NewRegistry(config.StoreInventory()...)
if st, err = p.newStore(reg, configStoreURL); err != nil {
if st, err = reg.NewStore(configStoreURL); err != nil {
_ = s.Close()
return nil, fmt.Errorf("unable to connect to the configuration server: %v", err)
}
Expand All @@ -172,12 +171,12 @@ func newServer(a *Args, p *patchTable) (*Server, error) {
templateMap[k] = &t
}

rt = p.newRuntime2(st, templateMap, adapterMap, a.ConfigIdentityAttribute, a.ConfigDefaultNamespace,
rt = p.newRuntime(st, templateMap, adapterMap, a.ConfigIdentityAttribute, a.ConfigDefaultNamespace,
s.gp, s.adapterGP, a.TracingOptions.TracingEnabled())

if err = p.runtimeListen(rt); err != nil {
_ = s.Close()
return nil, fmt.Errorf("unable to create runtime dispatcherForTesting: %v", err)
return nil, fmt.Errorf("unable to listen: %v", err)
}
s.dispatcher = rt.Dispatcher()

Expand All @@ -194,12 +193,7 @@ func newServer(a *Args, p *patchTable) (*Server, error) {

if a.ReadinessProbeOptions.IsValid() {
s.readinessProbe = probe.NewFileController(a.ReadinessProbeOptions)
if e, ok := s.dispatcher.(probe.SupportsProbe); ok {
e.RegisterProbe(s.readinessProbe, "dispatcher")
}
if rt != nil {
rt.RegisterProbe(s.readinessProbe, "dispatcher2")
}
rt.RegisterProbe(s.readinessProbe, "dispatcher")
st.RegisterProbe(s.readinessProbe, "store")
s.readinessProbe.Start()
}
Expand Down
10 changes: 6 additions & 4 deletions mixer/pkg/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"google.golang.org/grpc"

mixerpb "istio.io/api/mixer/v1"
"istio.io/istio/mixer/pkg/config/store"
"istio.io/istio/mixer/pkg/config/storetest"
"istio.io/istio/mixer/pkg/runtime"
generatedTmplRepo "istio.io/istio/mixer/template"
Expand Down Expand Up @@ -120,10 +119,12 @@ func newTestServer(globalCfg, serviceCfg string) (*Server, error) {
a.LivenessProbeOptions.UpdateInterval = 2
a.ReadinessProbeOptions.Path = "def"
a.ReadinessProbeOptions.UpdateInterval = 3

var err error
if a.ConfigStore, err = storetest.SetupStoreForTest(globalCfg, serviceCfg); err != nil {
return nil, err
}

return New(a)
}

Expand Down Expand Up @@ -208,11 +209,12 @@ func TestErrors(t *testing.T) {
a.ConfigStoreURL = ""
pt := newPatchTable()
switch i {
case 1:
a.ConfigStore = nil
a.ConfigStoreURL = ""
case 2:
a.ConfigStore = nil
pt.newStore = func(reg *store.Registry, configURL string) (store.Store, error) {
return nil, errors.New("BAD")
}
a.ConfigStoreURL = "DEADBEEF"
case 3:
pt.configTracing = func(_ string, _ *tracing.Options) (io.Closer, error) {
return nil, errors.New("BAD")
Expand Down
17 changes: 17 additions & 0 deletions mixer/pkg/status/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,21 @@ func TestStatus(t *testing.T) {
if s.Code != int32(rpc.DEADLINE_EXCEEDED) || s.Message != "Aborted!" {
t.Errorf("Got %v %v, expected rpc.DEADLINE_EXCEEDED Aborted!", s.Code, s.Message)
}

msg := String(s)
if msg == "" {
t.Errorf("Expecting valid string, got nothing")
}

s = rpc.Status{Code: -123}
msg = String(s)
if msg == "" {
t.Errorf("Expecting valid string, got nothing")
}

s = OK
msg = String(s)
if msg == "" {
t.Errorf("Expecting valid string, got nothing")
}
}
1 change: 0 additions & 1 deletion mixer/test/perf/multimetric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ func Benchmark_Multi_Metric_R2(b *testing.B) {
settings.RunMode = perf.InProcessBypassGrpc

setup := baseMultiMetricSetup
setup.Config.UseRuntime2 = true

perf.Run(b, &setup, settings)
}
2 changes: 0 additions & 2 deletions mixer/test/perf/norule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ func Benchmark_NoRule_Report_R2(b *testing.B) {
settings.RunMode = perf.InProcessBypassGrpc

setup := baseNoRuleReportSetup
setup.Config.UseRuntime2 = true

perf.Run(b, &setup, settings)
}
Expand All @@ -99,7 +98,6 @@ func Benchmark_NoRule_Check_R2(b *testing.B) {
settings.RunMode = perf.InProcessBypassGrpc

setup := baseNoRuleCheckSetup
setup.Config.UseRuntime2 = true

perf.Run(b, &setup, settings)
}
1 change: 0 additions & 1 deletion mixer/test/perf/singlecheck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ func Benchmark_Single_Check_R2(b *testing.B) {
settings.RunMode = perf.InProcessBypassGrpc

setup := baseSingleCheckSetup
setup.Config.UseRuntime2 = true

perf.Run(b, &setup, settings)
}
1 change: 0 additions & 1 deletion mixer/test/perf/singlemetric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ func Benchmark_Single_Metric_R2(b *testing.B) {
settings.RunMode = perf.InProcessBypassGrpc

setup := baseSingleMetricSetup
setup.Config.UseRuntime2 = true

perf.Run(b, &setup, settings)
}
2 changes: 0 additions & 2 deletions mixer/test/perf/singlereport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ func Benchmark_Single_Report_R2(b *testing.B) {
settings.RunMode = perf.InProcessBypassGrpc

setup := baseSingleReportSetup
setup.Config.UseRuntime2 = true

perf.Run(b, &setup, settings)
}
Expand All @@ -83,7 +82,6 @@ func Benchmark_Single_Report_SuccessCondition_R2(b *testing.B) {
settings.RunMode = perf.InProcessBypassGrpc

setup := baseSingleReportSetup
setup.Config.UseRuntime2 = true
setup.Config.Global = joinConfigs(h1Noop, i1ReportNothing, r3UsingH1AndI1Conditional)

perf.Run(b, &setup, settings)
Expand Down

0 comments on commit 773b667

Please sign in to comment.