-
Notifications
You must be signed in to change notification settings - Fork 918
GODRIVER-3255 Await heartbeat checks upto freq when polling #1720
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
Changes from 6 commits
b7cd19d
54aea0f
5427a32
e0e656e
2c97d0c
235a5b7
8377b6d
815cf1b
cc589b1
61a0124
25de6fc
f83f6a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ import ( | |
| "net" | ||
| "os" | ||
| "runtime" | ||
| "sync/atomic" | ||
| "testing" | ||
| "time" | ||
|
|
||
|
|
@@ -144,7 +145,7 @@ func TestSDAMProse(t *testing.T) { | |
| }) | ||
| }) | ||
|
|
||
| mt.RunOpts("client waits between failed Hellos", mtest.NewOptions().MinServerVersion("4.9").Topologies(mtest.Single), func(mt *mtest.T) { | ||
| mt.RunOpts("client waits between failed Hellos", mtest.NewOptions().MinServerVersion("4.9"), func(mt *mtest.T) { | ||
| // Force hello requests to fail 5 times. | ||
| mt.SetFailPoint(mtest.FailPoint{ | ||
| ConfigureFailPoint: "failCommand", | ||
|
|
@@ -232,4 +233,36 @@ func TestServerHeartbeatStartedEvent(t *testing.T) { | |
| } | ||
| assert.Equal(t, expectedEvents, actualEvents) | ||
| }) | ||
|
|
||
| mt := mtest.New(t) | ||
|
|
||
| mt.Run("polling must await frequency", func(mt *mtest.T) { | ||
| var heartbeatStartedCount atomic.Int64 | ||
| servers := map[string]bool{} | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm fairly certain there are no concurrency concerns here since this is a set (i.e. nothing is aggregated).
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Go maps are not concurrent safe except for read-only use, independent of the keys or data written. Here's the data race detector error:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the sake of this test it seems like it shouldn't matter. We're just checking that the number of heartbeats doesn't get ahead of discovery, AFAIK the size of the set doesn't have to be precise at the time we make the assertion. Anyway, updated with a mutex.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even though there is a race concern I don't think you can actually break what is being tested. I wasn't sure the race detector would care in this case 🤷 |
||
|
|
||
| serverMonitor := &event.ServerMonitor{ | ||
| ServerHeartbeatStarted: func(*event.ServerHeartbeatStartedEvent) { | ||
| heartbeatStartedCount.Add(1) | ||
| }, | ||
| TopologyDescriptionChanged: func(evt *event.TopologyDescriptionChangedEvent) { | ||
| for _, srv := range evt.NewDescription.Servers { | ||
| servers[srv.Addr.String()] = true | ||
| } | ||
| }, | ||
| } | ||
|
|
||
| // Create a client with heartbeatFrequency=100ms, | ||
| // serverMonitoringMode=poll. Use SDAM to record the number of times the | ||
| // a heartbeat is started and the number of servers discovered. | ||
| mt.ResetClient(options.Client(). | ||
| SetServerMonitor(serverMonitor). | ||
| SetServerMonitoringMode(options.ServerMonitoringModePoll)) | ||
|
|
||
| // Per specifications, minHeartbeatFrequencyMS=500ms. So, within the first | ||
| // 500ms the heartbeatStartedCount should be LEQ to the number of discovered | ||
| // servers. | ||
| time.Sleep(500 * time.Millisecond) | ||
|
|
||
| assert.LessOrEqual(mt, heartbeatStartedCount.Load(), int64(len(servers))) | ||
|
||
| }) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.