From 85d07ae73293e888cfb2c45ad7c246d67c85451d Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Thu, 23 Jul 2020 21:34:07 +0200 Subject: [PATCH] Cherry-pick #20127 to 7.x: Fix failing unit tests on windows (#20181) * [Ingest Manager] Fix failing unit tests on windows (#20127) * remove skip * close properly * changelog * space * Changelog * prevent closing closed * changelog --- x-pack/elastic-agent/CHANGELOG.asciidoc | 2 ++ .../elastic-agent/pkg/agent/application/action_store.go | 1 + .../pkg/agent/application/action_store_test.go | 5 ----- .../elastic-agent/pkg/agent/application/info/agent_id.go | 8 -------- x-pack/elastic-agent/pkg/config/config.go | 4 ++++ 5 files changed, 7 insertions(+), 13 deletions(-) diff --git a/x-pack/elastic-agent/CHANGELOG.asciidoc b/x-pack/elastic-agent/CHANGELOG.asciidoc index 822e7b9b56a..e7616a8b620 100644 --- a/x-pack/elastic-agent/CHANGELOG.asciidoc +++ b/x-pack/elastic-agent/CHANGELOG.asciidoc @@ -52,6 +52,8 @@ - Remove support for logs type and use logfile {pull}19761[19761] - Avoid comparing uncomparable types on enroll {issue}19976[19976] - Fix issues with merging of elastic-agent.yml and fleet.yml {pull}20026[20026] +- Fix failing unit tests on windows {pull}20127[20127] +- Prevent closing closed reader {pull}20214[20214] - Improve GRPC stop to be more relaxed {pull}20118[20118] ==== New features diff --git a/x-pack/elastic-agent/pkg/agent/application/action_store.go b/x-pack/elastic-agent/pkg/agent/application/action_store.go index a0b008d9623..25dbf7a5b82 100644 --- a/x-pack/elastic-agent/pkg/agent/application/action_store.go +++ b/x-pack/elastic-agent/pkg/agent/application/action_store.go @@ -33,6 +33,7 @@ func newActionStore(log *logger.Logger, store storeLoad) (*actionStore, error) { if err != nil { return &actionStore{log: log, store: store}, nil } + defer reader.Close() var action actionConfigChangeSerializer diff --git a/x-pack/elastic-agent/pkg/agent/application/action_store_test.go b/x-pack/elastic-agent/pkg/agent/application/action_store_test.go index a3ccb5b9e48..4205deda8b6 100644 --- a/x-pack/elastic-agent/pkg/agent/application/action_store_test.go +++ b/x-pack/elastic-agent/pkg/agent/application/action_store_test.go @@ -9,7 +9,6 @@ import ( "io/ioutil" "os" "path/filepath" - "runtime" "testing" "github.com/stretchr/testify/require" @@ -20,10 +19,6 @@ import ( ) func TestActionStore(t *testing.T) { - if runtime.GOOS == "windows" { - t.Skip("Skipping on windows see https://github.com/elastic/beats/issues/19919") - } - log, _ := logger.New("action_store") withFile := func(fn func(t *testing.T, file string)) func(*testing.T) { return func(t *testing.T) { diff --git a/x-pack/elastic-agent/pkg/agent/application/info/agent_id.go b/x-pack/elastic-agent/pkg/agent/application/info/agent_id.go index 60462b7da4f..f58ab5c2a5e 100644 --- a/x-pack/elastic-agent/pkg/agent/application/info/agent_id.go +++ b/x-pack/elastic-agent/pkg/agent/application/info/agent_id.go @@ -94,10 +94,6 @@ func getInfoFromStore(s ioStore) (*persistentAgentInfo, error) { errors.M(errors.MetaKeyPath, agentConfigFile)) } - if err := reader.Close(); err != nil { - return nil, err - } - configMap, err := cfg.ToMapStr() if err != nil { return nil, errors.New(err, @@ -137,10 +133,6 @@ func updateAgentInfo(s ioStore, agentInfo *persistentAgentInfo) error { errors.M(errors.MetaKeyPath, agentConfigFile)) } - if err := reader.Close(); err != nil { - return err - } - configMap := make(map[string]interface{}) if err := cfg.Unpack(&configMap); err != nil { return errors.New(err, "failed to unpack stored config to map") diff --git a/x-pack/elastic-agent/pkg/config/config.go b/x-pack/elastic-agent/pkg/config/config.go index e8845840137..a7620a7f630 100644 --- a/x-pack/elastic-agent/pkg/config/config.go +++ b/x-pack/elastic-agent/pkg/config/config.go @@ -49,6 +49,10 @@ func NewConfigFrom(from interface{}) (*Config, error) { } if in, ok := from.(io.Reader); ok { + if closer, ok := from.(io.Closer); ok { + defer closer.Close() + } + content, err := ioutil.ReadAll(in) if err != nil { return nil, err