@@ -116,64 +116,88 @@ func TestDisableConsolidator(t *testing.T) {
116
116
}
117
117
118
118
func TestConsolidatorReplicasOnly (t * testing.T ) {
119
- totalConsolidationsTag := "Waits/Histograms/Consolidations/Count"
120
- initial := framework .FetchInt (framework .DebugVars (), totalConsolidationsTag )
121
- var wg sync.WaitGroup
122
- wg .Add (2 )
123
- go func () {
124
- framework .NewClient ().Execute ("select sleep(0.5) from dual" , nil )
125
- wg .Done ()
126
- }()
127
- go func () {
128
- framework .NewClient ().Execute ("select sleep(0.5) from dual" , nil )
129
- wg .Done ()
130
- }()
131
- wg .Wait ()
132
- afterOne := framework .FetchInt (framework .DebugVars (), totalConsolidationsTag )
133
- assert .Equal (t , initial + 1 , afterOne , "expected one consolidation" )
134
-
135
- revert := changeVar (t , "Consolidator" , tabletenv .NotOnPrimary )
136
- defer revert ()
137
-
138
- // primary should not do query consolidation
139
- var wg2 sync.WaitGroup
140
- wg2 .Add (2 )
141
- go func () {
142
- framework .NewClient ().Execute ("select sleep(0.5) from dual" , nil )
143
- wg2 .Done ()
144
- }()
145
- go func () {
146
- framework .NewClient ().Execute ("select sleep(0.5) from dual" , nil )
147
- wg2 .Done ()
148
- }()
149
- wg2 .Wait ()
150
- noNewConsolidations := framework .FetchInt (framework .DebugVars (), totalConsolidationsTag )
151
- assert .Equal (t , afterOne , noNewConsolidations , "expected no new consolidations" )
152
-
153
- // become a replica, where query consolidation should happen
154
- client := framework .NewClientWithTabletType (topodatapb .TabletType_REPLICA )
155
-
156
- err := client .SetServingType (topodatapb .TabletType_REPLICA )
157
- require .NoError (t , err )
158
- defer func () {
159
- err = client .SetServingType (topodatapb .TabletType_PRIMARY )
160
- require .NoError (t , err )
161
- }()
119
+ type executeFn func (
120
+ query string , bindvars map [string ]* querypb.BindVariable ,
121
+ ) (* sqltypes.Result , error )
122
+
123
+ testCases := []struct {
124
+ name string
125
+ getExecuteFn func (qc * framework.QueryClient ) executeFn
126
+ totalConsolidationsTag string
127
+ }{
128
+ {
129
+ name : "Execute" ,
130
+ getExecuteFn : func (qc * framework.QueryClient ) executeFn { return qc .Execute },
131
+ totalConsolidationsTag : "Waits/Histograms/Consolidations/Count" ,
132
+ },
133
+ {
134
+ name : "StreamExecute" ,
135
+ getExecuteFn : func (qc * framework.QueryClient ) executeFn { return qc .StreamExecute },
136
+ totalConsolidationsTag : "Waits/Histograms/StreamConsolidations/Count" ,
137
+ },
138
+ }
162
139
163
- initial = framework .FetchInt (framework .DebugVars (), totalConsolidationsTag )
164
- var wg3 sync.WaitGroup
165
- wg3 .Add (2 )
166
- go func () {
167
- client .Execute ("select sleep(0.5) from dual" , nil )
168
- wg3 .Done ()
169
- }()
170
- go func () {
171
- client .Execute ("select sleep(0.5) from dual" , nil )
172
- wg3 .Done ()
173
- }()
174
- wg3 .Wait ()
175
- afterOne = framework .FetchInt (framework .DebugVars (), totalConsolidationsTag )
176
- assert .Equal (t , initial + 1 , afterOne , "expected another consolidation" )
140
+ for _ , testCase := range testCases {
141
+ t .Run (testCase .name , func (t * testing.T ) {
142
+ initial := framework .FetchInt (framework .DebugVars (), testCase .totalConsolidationsTag )
143
+ var wg sync.WaitGroup
144
+ wg .Add (2 )
145
+ go func () {
146
+ testCase .getExecuteFn (framework .NewClient ())("select sleep(0.5) from dual" , nil )
147
+ wg .Done ()
148
+ }()
149
+ go func () {
150
+ testCase .getExecuteFn (framework .NewClient ())("select sleep(0.5) from dual" , nil )
151
+ wg .Done ()
152
+ }()
153
+ wg .Wait ()
154
+ afterOne := framework .FetchInt (framework .DebugVars (), testCase .totalConsolidationsTag )
155
+ assert .Equal (t , initial + 1 , afterOne , "expected one consolidation" )
156
+
157
+ revert := changeVar (t , "Consolidator" , tabletenv .NotOnPrimary )
158
+ defer revert ()
159
+
160
+ // primary should not do query consolidation
161
+ var wg2 sync.WaitGroup
162
+ wg2 .Add (2 )
163
+ go func () {
164
+ testCase .getExecuteFn (framework .NewClient ())("select sleep(0.5) from dual" , nil )
165
+ wg2 .Done ()
166
+ }()
167
+ go func () {
168
+ testCase .getExecuteFn (framework .NewClient ())("select sleep(0.5) from dual" , nil )
169
+ wg2 .Done ()
170
+ }()
171
+ wg2 .Wait ()
172
+ noNewConsolidations := framework .FetchInt (framework .DebugVars (), testCase .totalConsolidationsTag )
173
+ assert .Equal (t , afterOne , noNewConsolidations , "expected no new consolidations" )
174
+
175
+ // become a replica, where query consolidation should happen
176
+ client := framework .NewClientWithTabletType (topodatapb .TabletType_REPLICA )
177
+
178
+ err := client .SetServingType (topodatapb .TabletType_REPLICA )
179
+ require .NoError (t , err )
180
+ defer func () {
181
+ err = client .SetServingType (topodatapb .TabletType_PRIMARY )
182
+ require .NoError (t , err )
183
+ }()
184
+
185
+ initial = framework .FetchInt (framework .DebugVars (), testCase .totalConsolidationsTag )
186
+ var wg3 sync.WaitGroup
187
+ wg3 .Add (2 )
188
+ go func () {
189
+ testCase .getExecuteFn (client )("select sleep(0.5) from dual" , nil )
190
+ wg3 .Done ()
191
+ }()
192
+ go func () {
193
+ testCase .getExecuteFn (client )("select sleep(0.5) from dual" , nil )
194
+ wg3 .Done ()
195
+ }()
196
+ wg3 .Wait ()
197
+ afterOne = framework .FetchInt (framework .DebugVars (), testCase .totalConsolidationsTag )
198
+ assert .Equal (t , initial + 1 , afterOne , "expected another consolidation" )
199
+ })
200
+ }
177
201
}
178
202
179
203
func TestQueryPlanCache (t * testing.T ) {
0 commit comments