Skip to content

Commit 47eba1d

Browse files
authored
Merge pull request #266 from newrelic/daff/fix-more-flakiness
fix(tests): Apply more fixes for Windows Integration test flakiness
2 parents 9f3431f + f043217 commit 47eba1d

3 files changed

Lines changed: 54 additions & 10 deletions

File tree

tasks/infra/agent/integrationTests_windows.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
- ADD https://download.newrelic.com/infrastructure_agent/binaries/windows/amd64/newrelic-infra-amd64.1.77.1.zip C:/nra.zip
44
- RUN Expand-Archive -Path 'C:\nra.zip' -DestinationPath 'C:\' -Force; Write-Host '=== EXTRACTED CONTENTS ==='; Get-ChildItem 'C:\Program Files\New Relic\newrelic-infra\' | Select-Object FullName
55
- COPY ["tasks/infra/config/fixtures/minimal_infra_config/newrelic-infra.yml", "C:/Program Files/New Relic/newrelic-infra/newrelic-infra.yml"]
6-
docker_cmd: ./nrdiag_x64.exe -y -filter all
6+
- RUN (Get-Date).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ') | Out-File -FilePath C:/app/release_date.txt -Encoding ascii -NoNewline
7+
docker_cmd: $d = Get-Content C:/app/release_date.txt; ./nrdiag_x64.exe -y -filter all -o Infra/Agent/Version.releaseDateOverride=$d
78
log_entry_expected:
89
- Info.*Infra/Agent/Version.*
910
log_entry_not_expected:

tasks/infra/agent/version.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ var (
1919
errRecommendedUpgrade = fmt.Errorf("New Relic Infrastructure Agent upgrade is recommended, installed agent was released more than one year ago")
2020
)
2121

22+
const releaseDateOverrideKey = "releaseDateOverride"
23+
2224
type githubReleaseData struct {
2325
PublishedAt string `json:"published_at"`
2426
}
@@ -118,7 +120,7 @@ func (p InfraAgentVersion) Execute(options tasks.Options, upstream map[string]ta
118120
}
119121
}
120122

121-
err = p.validatePublishDate(ver)
123+
err = p.validatePublishDate(ver, options)
122124
if err != nil {
123125
urlUpdateTask := tasks.Result{
124126
URL: "https://docs.newrelic.com/docs/infrastructure/new-relic-infrastructure/installation/update-infrastructure-agent",
@@ -166,13 +168,13 @@ func (p InfraAgentVersion) getBinaryPath(envVars map[string]string) (string, err
166168
}
167169

168170
// validatePublishDate returns an error if the version was released more than one year ago
169-
func (p InfraAgentVersion) validatePublishDate(version tasks.Ver) error {
171+
func (p InfraAgentVersion) validatePublishDate(version tasks.Ver, options tasks.Options) error {
170172
// Github releases started on version 1.12.0
171173
if version.IsLessThanEq(oldestGithubRelease) {
172174
return errUnsupportedVersion
173175
}
174176

175-
publishData, err := p.getGithubPublishDate(fmt.Sprintf("%d.%d.%d", version.Major, version.Minor, version.Patch))
177+
publishData, err := p.getGithubPublishDate(fmt.Sprintf("%d.%d.%d", version.Major, version.Minor, version.Patch), options)
176178
if err != nil {
177179
return fmt.Errorf("Unable to get New Relic Infrastructure Agent release date: %w", err)
178180
}
@@ -187,7 +189,12 @@ func (p InfraAgentVersion) validatePublishDate(version tasks.Ver) error {
187189
return nil
188190
}
189191

190-
func (p InfraAgentVersion) getGithubPublishDate(version string) (time.Time, error) {
192+
func (p InfraAgentVersion) getGithubPublishDate(version string, options tasks.Options) (time.Time, error) {
193+
if override := options.Options[releaseDateOverrideKey]; override != "" {
194+
log.Debug("Infra/Agent/Version - using releaseDateOverride, skipping GitHub API call")
195+
return time.Parse(time.RFC3339, override)
196+
}
197+
191198
wrapper := httpHelper.RequestWrapper{
192199
Method: "GET",
193200
URL: githubAPIReleaseURL + version,

tasks/infra/agent/version_test.go

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package agent
55
import (
66
"bytes"
77
"errors"
8-
"io/ioutil"
8+
"io"
99
"net/http"
1010
"time"
1111

@@ -145,7 +145,7 @@ var _ = Describe("Infra/Agent/Version", func() {
145145
p.runtimeOS = "darwin"
146146
p.httpGetter = func(wrapper httpHelper.RequestWrapper) (*http.Response, error) {
147147
return &http.Response{
148-
Body: ioutil.NopCloser(bytes.NewReader([]byte(`{"published_at": "2022-11-17T10:50:43Z"}`))),
148+
Body: io.NopCloser(bytes.NewReader([]byte(`{"published_at": "2022-11-17T10:50:43Z"}`))),
149149
}, nil
150150
}
151151
p.now = func() time.Time { return time.Date(2022, time.Month(11), 21, 1, 10, 30, 0, time.UTC) }
@@ -180,7 +180,7 @@ var _ = Describe("Infra/Agent/Version", func() {
180180
p.runtimeOS = "darwin"
181181
p.httpGetter = func(wrapper httpHelper.RequestWrapper) (*http.Response, error) {
182182
return &http.Response{
183-
Body: ioutil.NopCloser(bytes.NewReader([]byte(`{"published_at": "2020-11-17T10:50:43Z"}`))),
183+
Body: io.NopCloser(bytes.NewReader([]byte(`{"published_at": "2020-11-17T10:50:43Z"}`))),
184184
}, nil
185185
}
186186
p.now = func() time.Time { return time.Date(2022, time.Month(11), 21, 1, 10, 30, 0, time.UTC) }
@@ -355,13 +355,15 @@ var _ = Describe("Infra/Agent/Version", func() {
355355
var (
356356
version tasks.Ver
357357
err error
358+
options tasks.Options
358359
)
359360

360361
JustBeforeEach(func() {
361-
err = p.validatePublishDate(version)
362+
err = p.validatePublishDate(version, options)
362363
})
363364
Context("Version prior to 1.12.0", func() {
364365
BeforeEach(func() {
366+
options = tasks.Options{}
365367
version = tasks.Ver{Major: 1, Minor: 11, Patch: 0, Build: 0}
366368
})
367369

@@ -372,10 +374,11 @@ var _ = Describe("Infra/Agent/Version", func() {
372374

373375
Context("Up-to-date version", func() {
374376
BeforeEach(func() {
377+
options = tasks.Options{}
375378
version = tasks.Ver{Major: 1, Minor: 33, Patch: 0, Build: 0}
376379
p.httpGetter = func(wrapper httpHelper.RequestWrapper) (*http.Response, error) {
377380
return &http.Response{
378-
Body: ioutil.NopCloser(bytes.NewReader([]byte(`{"published_at": "2021-11-22T10:50:43Z"}`))),
381+
Body: io.NopCloser(bytes.NewReader([]byte(`{"published_at": "2021-11-22T10:50:43Z"}`))),
379382
}, nil
380383
}
381384
p.now = func() time.Time { return time.Date(2022, time.Month(11), 21, 1, 10, 30, 0, time.UTC) }
@@ -385,6 +388,39 @@ var _ = Describe("Infra/Agent/Version", func() {
385388
Expect(err).To(BeNil())
386389
})
387390
})
391+
392+
Context("releaseDateOverride option is provided", func() {
393+
BeforeEach(func() {
394+
version = tasks.Ver{Major: 1, Minor: 77, Patch: 1, Build: 0}
395+
options = tasks.Options{Options: map[string]string{releaseDateOverrideKey: "2026-07-13T18:04:00Z"}}
396+
p.now = func() time.Time { return time.Date(2026, time.Month(7), 13, 18, 5, 0, 0, time.UTC) }
397+
p.httpGetter = func(wrapper httpHelper.RequestWrapper) (*http.Response, error) {
398+
Fail("httpGetter must not be called when releaseDateOverride is set")
399+
return nil, nil
400+
}
401+
})
402+
403+
It("should not return an error and should not hit the network", func() {
404+
Expect(err).To(BeNil())
405+
})
406+
})
407+
408+
Context("releaseDateOverride option is empty", func() {
409+
BeforeEach(func() {
410+
version = tasks.Ver{Major: 1, Minor: 33, Patch: 0, Build: 0}
411+
options = tasks.Options{Options: map[string]string{releaseDateOverrideKey: ""}}
412+
p.httpGetter = func(wrapper httpHelper.RequestWrapper) (*http.Response, error) {
413+
return &http.Response{
414+
Body: io.NopCloser(bytes.NewReader([]byte(`{"published_at": "2021-11-22T10:50:43Z"}`))),
415+
}, nil
416+
}
417+
p.now = func() time.Time { return time.Date(2022, time.Month(11), 21, 1, 10, 30, 0, time.UTC) }
418+
})
419+
420+
It("should fall back to the GitHub API path", func() {
421+
Expect(err).To(BeNil())
422+
})
423+
})
388424
})
389425
})
390426
})

0 commit comments

Comments
 (0)