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

Fixing flaky tests #3563

Merged
merged 5 commits into from
Apr 18, 2023
Merged
Changes from 1 commit
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
Next Next commit
Fixing test race condition
  • Loading branch information
thampiotr committed Apr 18, 2023
commit cb9c090e0471f1a37f141365416a522bcf69359f
24 changes: 21 additions & 3 deletions component/module/file/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,21 @@ func TestModule(t *testing.T) {
require.NoError(t, err)

go c.Run(context.Background())
time.Sleep(200 * time.Millisecond)
require.Eventually(
t,
func() bool { return tc.expectedHealthType == c.CurrentHealth().Health },
5*time.Second,
50*time.Millisecond,
"did not reach required health status before timeout: %v != %v",
tc.expectedHealthType,
c.CurrentHealth().Health,
)

require.Equal(t, tc.expectedHealthType, c.CurrentHealth().Health)
require.True(t, strings.HasPrefix(c.CurrentHealth().Message, tc.expectedHealthMessagePrefix))
requirePrefix(t, c.CurrentHealth().Message, tc.expectedHealthMessagePrefix)

require.Equal(t, tc.expectedModuleHealthType, c.managedLocalFile.CurrentHealth().Health)
require.True(t, strings.HasPrefix(c.managedLocalFile.CurrentHealth().Message, tc.expectedModuleHealthMessagePrefix))
requirePrefix(t, c.managedLocalFile.CurrentHealth().Message, tc.expectedModuleHealthMessagePrefix)
})
}
}
Expand Down Expand Up @@ -125,6 +133,16 @@ func TestBadFile(t *testing.T) {
}
}

func requirePrefix(t *testing.T, s string, prefix string) {
require.True(
t,
strings.HasPrefix(s, prefix),
"expected '%v' to have '%v' prefix",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adds more useful error message.

s,
prefix,
)
}

func riverEscape(filePath string) string {
if runtime.GOOS == "windows" {
return strings.Replace(filePath, `\`, `\\`, -1)
Expand Down