@@ -17,7 +17,6 @@ import (
1717 coremock "github.com/yandex/pandora/core/mocks"
1818 "github.com/yandex/pandora/core/provider"
1919 "github.com/yandex/pandora/core/schedule"
20- "github.com/yandex/pandora/lib/monitoring"
2120 "go.uber.org/atomic"
2221 "go.uber.org/zap"
2322 "go.uber.org/zap/zapcore"
@@ -83,15 +82,15 @@ func Test_InstancePool(t *testing.T) {
8382 waitDoneCalled .Store (false )
8483 ctx , cancel = context .WithCancel (context .Background ())
8584 }
86- var justBeforeEach = func () {
87- metrics := newTestMetrics ( )
85+ var justBeforeEach = func (metricPrefix string ) {
86+ metrics := NewMetrics ( metricPrefix )
8887 p = newPool (newNopLogger (), metrics , onWaitDone , conf )
8988 }
9089 _ = cancel
9190
9291 t .Run ("shoot ok" , func (t * testing.T ) {
9392 beforeEach ()
94- justBeforeEach ()
93+ justBeforeEach ("shoot-ok" )
9594
9695 err := p .Run (ctx )
9796 require .NoError (t , err )
@@ -121,7 +120,7 @@ func Test_InstancePool(t *testing.T) {
121120
122121 beforeEach ()
123122 beforeEachContext ()
124- justBeforeEach ()
123+ justBeforeEach ("context-canceled" )
125124
126125 err := p .Run (ctx )
127126 require .Equal (t , context .Canceled , err )
@@ -170,7 +169,7 @@ func Test_InstancePool(t *testing.T) {
170169 })
171170 conf .Aggregator = aggr
172171
173- justBeforeEach ()
172+ justBeforeEach ("provider-failed" )
174173
175174 err := p .Run (ctx )
176175 require .Error (t , err )
@@ -201,7 +200,7 @@ func Test_InstancePool(t *testing.T) {
201200 aggr := & coremock.Aggregator {}
202201 aggr .On ("Run" , mock .Anything , mock .Anything ).Return (failErr )
203202 conf .Aggregator = aggr
204- justBeforeEach ()
203+ justBeforeEach ("aggregator-failed" )
205204
206205 err := p .Run (ctx )
207206 require .Error (t , err )
@@ -227,7 +226,7 @@ func Test_InstancePool(t *testing.T) {
227226 conf .NewGun = func () (core.Gun , error ) {
228227 return nil , failErr
229228 }
230- justBeforeEach ()
229+ justBeforeEach ("start-instances-failed" )
231230
232231 err := p .Run (ctx )
233232 require .Error (t , err )
@@ -259,7 +258,7 @@ func Test_MultipleInstance(t *testing.T) {
259258 schedule .NewOnce (2 ),
260259 schedule .NewConst (1 , 5 * time .Second ),
261260 )
262- pool := newPool (newNopLogger (), newTestMetrics ( ), nil , conf )
261+ pool := newPool (newNopLogger (), NewMetrics ( "test_engine_1" ), nil , conf )
263262 ctx := context .Background ()
264263
265264 err := pool .Run (ctx )
@@ -274,7 +273,7 @@ func Test_MultipleInstance(t *testing.T) {
274273 return schedule .NewOnce (1 ), nil
275274 }
276275 conf .StartupSchedule = schedule .NewOnce (3 )
277- pool := newPool (newNopLogger (), newTestMetrics ( ), nil , conf )
276+ pool := newPool (newNopLogger (), NewMetrics ( "test_engine_2" ), nil , conf )
278277 ctx := context .Background ()
279278
280279 err := pool .Run (ctx )
@@ -291,7 +290,7 @@ func Test_MultipleInstance(t *testing.T) {
291290 schedule .NewOnce (2 ),
292291 schedule .NewConst (1 , 2 * time .Second ),
293292 )
294- pool := newPool (newNopLogger (), newTestMetrics ( ), nil , conf )
293+ pool := newPool (newNopLogger (), NewMetrics ( "test_engine_3" ), nil , conf )
295294 ctx := context .Background ()
296295
297296 err := pool .Run (ctx )
@@ -319,14 +318,14 @@ func Test_Engine(t *testing.T) {
319318 ctx , cancel = context .WithCancel (context .Background ())
320319 }
321320
322- var justBeforeEach = func () {
323- metrics := newTestMetrics ( )
321+ var justBeforeEach = func (metricPrefix string ) {
322+ metrics := NewMetrics ( metricPrefix )
324323 engine = New (newNopLogger (), metrics , Config {confs })
325324 }
326325
327326 t .Run ("shoot ok" , func (t * testing.T ) {
328327 beforeEach ()
329- justBeforeEach ()
328+ justBeforeEach ("shoot-ok-2" )
330329
331330 err := engine .Run (ctx )
332331 require .NoError (t , err )
@@ -361,7 +360,7 @@ func Test_Engine(t *testing.T) {
361360 }
362361 beforeEach ()
363362 beforeEachCtx ()
364- justBeforeEach ()
363+ justBeforeEach ("context-canceled-2" )
365364
366365 err := engine .Run (ctx )
367366 require .Equal (t , err , context .Canceled )
@@ -398,7 +397,7 @@ func Test_Engine(t *testing.T) {
398397 aggr .On ("Run" , mock .Anything , mock .Anything ).Return (failErr )
399398 confs [0 ].Aggregator = aggr
400399
401- justBeforeEach ()
400+ justBeforeEach ("one-pool-failed" )
402401
403402 err := engine .Run (ctx )
404403 require .Error (t , err )
@@ -411,7 +410,7 @@ func Test_BuildInstanceSchedule(t *testing.T) {
411410 t .Run ("per instance schedule" , func (t * testing.T ) {
412411 conf , _ := newTestPoolConf ()
413412 conf .RPSPerInstance = true
414- pool := newPool (newNopLogger (), newTestMetrics ( ), nil , conf )
413+ pool := newPool (newNopLogger (), NewMetrics ( "per-instance-schedule" ), nil , conf )
415414 newInstanceSchedule , err := pool .buildNewInstanceSchedule (context .Background (), func () {
416415 panic ("should not be called" )
417416 })
@@ -428,7 +427,7 @@ func Test_BuildInstanceSchedule(t *testing.T) {
428427 conf .NewRPSSchedule = func () (core.Schedule , error ) {
429428 return nil , scheduleCreateErr
430429 }
431- pool := newPool (newNopLogger (), newTestMetrics ( ), nil , conf )
430+ pool := newPool (newNopLogger (), NewMetrics ( "shared-schedule-create-failed" ), nil , conf )
432431 newInstanceSchedule , err := pool .buildNewInstanceSchedule (context .Background (), func () {
433432 panic ("should not be called" )
434433 })
@@ -446,7 +445,7 @@ func Test_BuildInstanceSchedule(t *testing.T) {
446445 newScheduleCalled = true
447446 return schedule .NewOnce (1 ), nil
448447 }
449- pool := newPool (newNopLogger (), newTestMetrics ( ), nil , conf )
448+ pool := newPool (newNopLogger (), NewMetrics ( "shared-schedule-work" ), nil , conf )
450449 ctx , cancel := context .WithCancel (context .Background ())
451450 newInstanceSchedule , err := pool .buildNewInstanceSchedule (context .Background (), cancel )
452451 require .NoError (t , err )
@@ -532,12 +531,3 @@ func newNopLogger() *zap.Logger {
532531 log := zap .New (core )
533532 return log
534533}
535-
536- func newTestMetrics () Metrics {
537- return Metrics {
538- & monitoring.Counter {},
539- & monitoring.Counter {},
540- & monitoring.Counter {},
541- & monitoring.Counter {},
542- }
543- }
0 commit comments