Skip to content

Commit

Permalink
fix panic in manager tests
Browse files Browse the repository at this point in the history
  • Loading branch information
barrettj12 committed Jul 3, 2023
1 parent 926e99a commit 27ed015
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
9 changes: 7 additions & 2 deletions internals/overlord/logstate/gatherer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"io"
"time"

"github.com/canonical/pebble/internals/plan"
"gopkg.in/yaml.v3"

"github.com/canonical/pebble/internals/servicelog"
Expand All @@ -31,7 +32,7 @@ var _ = Suite(&gathererSuite{})

func (s *gathererSuite) TestGathererTimeout(c *C) {
recv := make(chan []servicelog.Entry)
g := newLogGathererForTest(1*time.Microsecond, 2, recv)
g := newLogGathererForTest(nil, 1*time.Microsecond, 2, recv)
go g.loop()

entry := servicelog.Entry{
Expand All @@ -50,8 +51,12 @@ func (s *gathererSuite) TestGathererTimeout(c *C) {
}
}

func newLogGathererForTest(tickPeriod time.Duration, bufferCapacity int, recv chan []servicelog.Entry) *logGatherer {
func newLogGathererForTest(
target *plan.LogTarget,
tickPeriod time.Duration, bufferCapacity int, recv chan []servicelog.Entry,
) *logGatherer {
return &logGatherer{
target: target,
tickPeriod: tickPeriod,
buffer: &testBuffer{
capacity: bufferCapacity,
Expand Down
24 changes: 14 additions & 10 deletions internals/overlord/logstate/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package logstate
import (
"bytes"
"sync"
"time"

"github.com/canonical/pebble/internals/logger"
"github.com/canonical/pebble/internals/plan"
Expand All @@ -40,7 +41,7 @@ func (s *managerSuite) TearDownTest(c *C) {
}

func (s *managerSuite) TestLogManager(c *C) {
m := newLogManagerForTest()
m := newLogManagerForTest(1*time.Second, 10, make(chan []servicelog.Entry))
// Fake ringbuffer so that log manager can create forwarders
rb := servicelog.RingBuffer{}

Expand Down Expand Up @@ -207,19 +208,22 @@ func checkGatherers(c *C, gatherers map[string]*logGatherer, expected []string)
//}

func (s *managerSuite) TestFlushLogsOnInterrupt(c *C) {
m := newLogManagerForTest()
m := newLogManagerForTest(1*time.Second, 10, make(chan []servicelog.Entry))

m.Stop()

// check buffered logs are sent through
}

func newLogManagerForTest() *LogManager {
return NewLogManager()
//return &LogManager{
// forwarders: map[string]*logForwarder{},
// gatherers: map[string]*logGatherer{},
// newForwarder: newLogForwarderForTest,
// newGatherer: newLogGathererForTest,
//}
func newLogManagerForTest(
tickPeriod time.Duration, bufferCapacity int, recv chan []servicelog.Entry,
) *LogManager {
return &LogManager{
forwarders: map[string]*logForwarder{},
gatherers: map[string]*logGatherer{},
newForwarder: newLogForwarder, // ForTest ?
newGatherer: func(target *plan.LogTarget) *logGatherer {
return newLogGathererForTest(target, tickPeriod, bufferCapacity, recv)
},
}
}

0 comments on commit 27ed015

Please sign in to comment.