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

Add client function to return ping latency #201

Merged
merged 6 commits into from
Sep 27, 2024
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
20 changes: 15 additions & 5 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ import (
"time"
)

var startPortMutex sync.Mutex
var startPort = 10000
var (
startPortMutex sync.Mutex
startPort = 10000
)

func newPort() (r int) {
startPortMutex.Lock()
Expand Down Expand Up @@ -1916,7 +1918,15 @@ func TestLatency(t *testing.T) {

returnedLatency = returnedLatency.Round(time.Millisecond)

if returnedLatency != expectedLatency {
latencyDiff := func() time.Duration {
diff := returnedLatency - expectedLatency
if diff < 0 {
return -diff
}
return diff
}()

if latencyDiff > time.Millisecond*3 {
Copy link
Owner

Choose a reason for hiding this comment

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

This is so flakey... I don't like this at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah true but I don't see an alternative, I was getting 0ms locally and it worked consistently, but when actions runs the test it fails. Do you have a better idea?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could try reverting the last 2 commits and using returnedLatency.Truncate instead ofreturnedLatency.Round, but even if that works now I'm not sure it won't eventually cause your tests to fail because actions ran too slowly.

t.Fatalf("Latency %s should be equal to %s", returnedLatency, expectedLatency)
}

Expand Down Expand Up @@ -2143,7 +2153,7 @@ func TestCapabilities(t *testing.T) {
in []string
expected string
}
var tests = []testTable{
tests := []testTable{
{
"Default Capabilities (not modifying)",
nil,
Expand Down Expand Up @@ -2218,7 +2228,7 @@ func TestEmptyCapabilities(t *testing.T) {
name string
in []string
}
var tests = []testTable{
tests := []testTable{
{"nil", nil},
{"Empty list", []string{}},
}
Expand Down