github.com/yandex/pandora@v0.5.32/core/aggregator/reporter_test.go (about) 1 package aggregator 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 "github.com/stretchr/testify/require" 8 coremock "github.com/yandex/pandora/core/mocks" 9 "github.com/yandex/pandora/lib/testutil" 10 "go.uber.org/zap" 11 "go.uber.org/zap/zaptest/observer" 12 ) 13 14 func TestReporter_DroppedErr(t *testing.T) { 15 core, entries := observer.New(zap.DebugLevel) 16 zap.ReplaceGlobals(zap.New(core)) 17 defer testutil.ReplaceGlobalLogger() 18 reporter := NewReporter(ReporterConfig{1}) 19 reporter.Report(1) 20 21 assert.NoError(t, reporter.DroppedErr()) 22 reporter.Report(2) 23 err := reporter.DroppedErr() 24 require.Error(t, err) 25 26 assert.EqualValues(t, 1, err.(*SomeSamplesDropped).Dropped) 27 assert.Equal(t, 1, entries.Len()) 28 } 29 30 func TestReporter_BorrowedSampleReturnedOnDrop(t *testing.T) { 31 reporter := NewReporter(ReporterConfig{1}) 32 33 reporter.Report(1) 34 borrowed := &coremock.BorrowedSample{} 35 borrowed.On("Return").Once() 36 37 reporter.Report(borrowed) 38 borrowed.AssertExpectations(t) 39 }