Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix flaky test TestDownloadBodyError #730

Merged
merged 1 commit into from
Jul 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions internal/pkg/artifact/download/http/downloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
)

func TestDownloadBodyError(t *testing.T) {
t.Skip("Skipping flaky test: https://github.com/elastic/elastic-agent/issues/640")
// This tests the scenario where the download encounters a network error
// part way through the download, while copying the response body.

Expand Down Expand Up @@ -65,9 +64,9 @@ func TestDownloadBodyError(t *testing.T) {
}

require.GreaterOrEqual(t, len(log.info), 1, "download error not logged at info level")
assert.Equal(t, log.info[len(log.info)-1].record, "download from %s failed at %s @ %sps: %s")
assert.True(t, containsMessage(log.info, "download from %s failed at %s @ %sps: %s"))
require.GreaterOrEqual(t, len(log.warn), 1, "download error not logged at warn level")
assert.Equal(t, log.warn[len(log.warn)-1].record, "download from %s failed at %s @ %sps: %s")
assert.True(t, containsMessage(log.warn, "download from %s failed at %s @ %sps: %s"))
}

func TestDownloadLogProgressWithLength(t *testing.T) {
Expand Down Expand Up @@ -208,3 +207,12 @@ func (f *recordLogger) Warnf(record string, args ...interface{}) {
defer f.lock.Unlock()
f.warn = append(f.warn, logMessage{record, args})
}

func containsMessage(logs []logMessage, msg string) bool {
for _, item := range logs {
if item.record == msg {
return true
}
}
return false
}