@@ -22,34 +22,51 @@ func TestSDAMProse(t *testing.T) {
22
22
mt := mtest .New (t )
23
23
defer mt .Close ()
24
24
25
- lowHeartbeatFrequency := 50 * time .Millisecond
26
- heartbeatFrequencyClientOpts := options .Client ().
27
- SetHeartbeatInterval (lowHeartbeatFrequency )
28
- heartbeatFrequencyMtOpts := mtest .NewOptions ().
29
- ClientOptions (heartbeatFrequencyClientOpts ).
25
+ // Server limits non-streaming heartbeats and explicit server transition checks to at most one
26
+ // per 500ms. Set the test interval to 500ms to minimize the difference between the behavior of
27
+ // streaming and non-streaming heartbeat intervals.
28
+ heartbeatInterval := 500 * time .Millisecond
29
+ heartbeatIntervalClientOpts := options .Client ().
30
+ SetHeartbeatInterval (heartbeatInterval )
31
+ heartbeatIntervalMtOpts := mtest .NewOptions ().
32
+ ClientOptions (heartbeatIntervalClientOpts ).
30
33
CreateCollection (false ).
31
34
ClientType (mtest .Proxy )
32
- mt .RunOpts ("heartbeats processed more frequently" , heartbeatFrequencyMtOpts , func (mt * mtest.T ) {
33
- // Test that lowering heartbeat frequency to 50ms causes the client to process heartbeats more frequently.
35
+ mt .RunOpts ("heartbeats processed more frequently" , heartbeatIntervalMtOpts , func (mt * mtest.T ) {
36
+ // Test that setting heartbeat interval to 500ms causes the client to process heartbeats
37
+ // approximately every 500ms instead of the default 10s. Note that a Client doesn't
38
+ // guarantee that it will process heartbeats exactly every 500ms, just that it will wait at
39
+ // least 500ms between heartbeats (and should process heartbeats more frequently for shorter
40
+ // interval settings).
34
41
//
35
- // In X ms, tests on 4.4+ should process at least numberOfNodes * (1 + X/frequency + X/frequency) hello
36
- // responses:
37
- // Each node should process 1 normal response (connection handshake) + X/frequency awaitable responses.
38
- // Each node should also process X/frequency RTT hello responses.
42
+ // For number of nodes N, interval I, and duration D, a Client should process at most X
43
+ // operations:
39
44
//
40
- // Tests on < 4.4 should process at least numberOfNodes * X/frequency messages.
45
+ // X = (N * (1 handshake + D/I heartbeats + D/I RTTs))
46
+ //
47
+ // Assert that a Client processes the expected number of operations for heartbeats sent at
48
+ // an interval between I and 2*I to account for different actual heartbeat intervals under
49
+ // different runtime conditions.
50
+
51
+ duration := 2 * time .Second
41
52
42
53
numNodes := len (options .Client ().ApplyURI (mtest .ClusterURI ()).Hosts )
43
- timeDuration := 250 * time .Millisecond
44
- numExpectedResponses := numNodes * int (timeDuration / lowHeartbeatFrequency )
45
- if mtest .CompareServerVersions (mtest .ServerVersion (), "4.4" ) >= 0 {
46
- numExpectedResponses = numNodes * (2 * int (timeDuration / lowHeartbeatFrequency ) + 1 )
47
- }
54
+ maxExpected := numNodes * (1 + 2 * int (duration / heartbeatInterval ))
55
+ minExpected := numNodes * (1 + 2 * int (duration / (heartbeatInterval * 2 )))
48
56
49
- time .Sleep (timeDuration + 50 * time . Millisecond )
57
+ time .Sleep (duration )
50
58
messages := mt .GetProxiedMessages ()
51
- assert .True (mt , len (messages ) >= numExpectedResponses , "expected at least %d responses, got %d" ,
52
- numExpectedResponses , len (messages ))
59
+ assert .True (
60
+ mt ,
61
+ len (messages ) >= minExpected && len (messages ) <= maxExpected ,
62
+ "expected number of messages to be in range [%d, %d], got %d" +
63
+ " (num nodes = %d, duration = %v, interval = %v)" ,
64
+ minExpected ,
65
+ maxExpected ,
66
+ len (messages ),
67
+ numNodes ,
68
+ duration ,
69
+ heartbeatInterval )
53
70
})
54
71
55
72
mt .RunOpts ("rtt tests" , noClientOpts , func (mt * mtest.T ) {
0 commit comments