Skip to content

Commit 02493ed

Browse files
Cherry-pick #20127 to 7.9: Fix failing unit tests on windows (#20180)
* [Ingest Manager] Fix failing unit tests on windows (#20127) * remove skip * close properly * changelog * space * prevent closing closed * changelog
1 parent 93c97cf commit 02493ed

File tree

5 files changed

+7
-13
lines changed

5 files changed

+7
-13
lines changed

x-pack/elastic-agent/CHANGELOG.asciidoc

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
- Remove support for logs type and use logfile {pull}19761[19761]
5353
- Avoid comparing uncomparable types on enroll {issue}19976[19976]
5454
- Fix issues with merging of elastic-agent.yml and fleet.yml {pull}20026[20026]
55+
- Fix failing unit tests on windows {pull}20127[20127]
56+
- Prevent closing closed reader {pull}20214[20214]
5557
- Improve GRPC stop to be more relaxed {pull}20118[20118]
5658

5759
==== New features

x-pack/elastic-agent/pkg/agent/application/action_store.go

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func newActionStore(log *logger.Logger, store storeLoad) (*actionStore, error) {
3333
if err != nil {
3434
return &actionStore{log: log, store: store}, nil
3535
}
36+
defer reader.Close()
3637

3738
var action actionConfigChangeSerializer
3839

x-pack/elastic-agent/pkg/agent/application/action_store_test.go

-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"io/ioutil"
1010
"os"
1111
"path/filepath"
12-
"runtime"
1312
"testing"
1413

1514
"github.com/stretchr/testify/require"
@@ -20,10 +19,6 @@ import (
2019
)
2120

2221
func TestActionStore(t *testing.T) {
23-
if runtime.GOOS == "windows" {
24-
t.Skip("Skipping on windows see https://github.com/elastic/beats/issues/19919")
25-
}
26-
2722
log, _ := logger.New("action_store")
2823
withFile := func(fn func(t *testing.T, file string)) func(*testing.T) {
2924
return func(t *testing.T) {

x-pack/elastic-agent/pkg/agent/application/info/agent_id.go

-8
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,6 @@ func getInfoFromStore(s ioStore) (*persistentAgentInfo, error) {
9494
errors.M(errors.MetaKeyPath, agentConfigFile))
9595
}
9696

97-
if err := reader.Close(); err != nil {
98-
return nil, err
99-
}
100-
10197
configMap, err := cfg.ToMapStr()
10298
if err != nil {
10399
return nil, errors.New(err,
@@ -137,10 +133,6 @@ func updateAgentInfo(s ioStore, agentInfo *persistentAgentInfo) error {
137133
errors.M(errors.MetaKeyPath, agentConfigFile))
138134
}
139135

140-
if err := reader.Close(); err != nil {
141-
return err
142-
}
143-
144136
configMap := make(map[string]interface{})
145137
if err := cfg.Unpack(&configMap); err != nil {
146138
return errors.New(err, "failed to unpack stored config to map")

x-pack/elastic-agent/pkg/config/config.go

+4
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ func NewConfigFrom(from interface{}) (*Config, error) {
4949
}
5050

5151
if in, ok := from.(io.Reader); ok {
52+
if closer, ok := from.(io.Closer); ok {
53+
defer closer.Close()
54+
}
55+
5256
content, err := ioutil.ReadAll(in)
5357
if err != nil {
5458
return nil, err

0 commit comments

Comments
 (0)