Skip to content

Commit

Permalink
Remove Created state from collector to make shutdown behave more in l…
Browse files Browse the repository at this point in the history
…ine with language standards

Signed-off-by: Corbin Phelps <corbin.phelps@bluemedora.com>
  • Loading branch information
Corbin Phelps committed Feb 28, 2022
1 parent bdc446b commit 5a0f6e4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 14 deletions.
3 changes: 1 addition & 2 deletions service/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ const (
Running
Closing
Closed
Created
)

// (Internal note) Collector Lifecycle:
Expand Down Expand Up @@ -91,7 +90,7 @@ func New(set CollectorSettings) (*Collector, error) {
}

state := atomic.Value{}
state.Store(Created)
state.Store(Starting)
return &Collector{
logger: zap.NewNop(), // Set a Nop logger as a place holder until a logger is created based on configuration

Expand Down
14 changes: 2 additions & 12 deletions service/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func TestCollector_ShutdownBeforeRun(t *testing.T) {
collectorTelemetry = &colTelemetry{}
defer func() { collectorTelemetry = preservedAppTelemetry }()

factories, err := testcomponents.DefaultFactories()
factories, err := testcomponents.NewDefaultFactories()
require.NoError(t, err)

set := CollectorSettings{
Expand All @@ -170,14 +170,8 @@ func TestCollector_ShutdownBeforeRun(t *testing.T) {
col, err := New(set)
require.NoError(t, err)

// Calling shutdown before collector is running should not stop it from running
// Calling shutdown before collector is running should cause it to return quickly
col.Shutdown()
select {
case <-col.shutdownChan:
require.Fail(t, "shutdownChan was closed early")
case <-time.After(time.Second):
// Channel did not report closed after 1 second move on with test.
}

colDone := make(chan struct{})
go func() {
Expand All @@ -188,10 +182,6 @@ func TestCollector_ShutdownBeforeRun(t *testing.T) {
}
}()

assert.Eventually(t, func() bool {
return Running == col.GetState()
}, time.Second*2, time.Millisecond*200)

col.Shutdown()
<-colDone
assert.Eventually(t, func() bool {
Expand Down

0 comments on commit 5a0f6e4

Please sign in to comment.