1// Copyright 2017 Istio Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15// Package test supplies a fake Mixer server for use in testing. It should NOT
16// be used outside of testing contexts.
17package perftests
18
19import (
20	"testing"
21
22	"istio.io/istio/mixer/pkg/perf"
23)
24
25// Basic reporting setup using a single reported value in a request.
26//
27// Tests the most basic end-to-end report execution using the shortest possible path of execution. This does not
28// include any expression evaluation.
29var baseSingleReportSetup = perf.Setup{
30	Config: perf.Config{
31		Global:         minimalServiceConfig,
32		Service:        joinConfigs(h1Noop, i1ReportNothing, r1UsingH1AndI1),
33		SingleThreaded: true,
34	},
35
36	Loads: []perf.Load{{
37		Multiplier: 1,
38		Requests: []perf.Request{
39			perf.BuildBasicReport(map[string]interface{}{
40				"attr.bool":   false,
41				"attr.string": "str1",
42				"attr.double": float64(23.45),
43				"attr.int64":  int64(42),
44			}),
45		},
46	}},
47}
48
49func Benchmark_Single_Report(b *testing.B) {
50	settings := baseSettings
51	settings.RunMode = perf.InProcessBypassGrpc
52
53	setup := baseSingleReportSetup
54	perf.Run(b, &setup, settings)
55}
56
57func Benchmark_Single_Report_Rpc(b *testing.B) {
58	settings := baseSettings
59	settings.RunMode = perf.InProcess
60
61	setup := baseSingleReportSetup
62
63	perf.Run(b, &setup, settings)
64}
65
66func Benchmark_Single_Report_SuccessCondition(b *testing.B) {
67	settings := baseSettings
68	settings.RunMode = perf.InProcessBypassGrpc
69
70	setup := baseSingleReportSetup
71	setup.Config.Global = joinConfigs(h1Noop, i1ReportNothing, r3UsingH1AndI1Conditional)
72
73	perf.Run(b, &setup, settings)
74}
75
76func Benchmark_Single_Report_SuccessCondition_Rpc(b *testing.B) {
77	settings := baseSettings
78	settings.RunMode = perf.InProcess
79
80	setup := baseSingleReportSetup
81	setup.Config.Global = joinConfigs(h1Noop, i1ReportNothing, r3UsingH1AndI1Conditional)
82
83	perf.Run(b, &setup, settings)
84}
85