@@ -149,6 +149,64 @@ test_get_servers (void)
149149 mongoc_uri_destroy (uri );
150150}
151151
152+ #define TV_1 \
153+ "{ 'processId': { '$oid': 'AABBAABBAABBAABBAABBAABB' }, 'counter': 1 }"
154+ #define TV_2 \
155+ "{ 'processId': { '$oid': 'AABBAABBAABBAABBAABBAABB' }, 'counter': 2 }"
156+
157+ void
158+ _topology_changed (const mongoc_apm_topology_changed_t * event )
159+ {
160+ int * num_calls ;
161+
162+ num_calls = (int * ) mongoc_apm_topology_changed_get_context (event );
163+ (* num_calls )++ ;
164+ }
165+
166+ /* Regression test for CDRIVER-3753. */
167+ static void
168+ test_topology_version_equal (void )
169+ {
170+ mongoc_uri_t * uri ;
171+ mongoc_topology_t * topology ;
172+ mongoc_topology_description_t * td ;
173+ mongoc_server_description_t * sd ;
174+ mongoc_apm_callbacks_t * callbacks ;
175+ int num_calls = 0 ;
176+
177+ uri = mongoc_uri_new ("mongodb://host" );
178+ topology = mongoc_topology_new (uri , true /* single-threaded */ );
179+ td = & topology -> description ;
180+
181+ callbacks = mongoc_apm_callbacks_new ();
182+ mongoc_apm_set_topology_changed_cb (callbacks , _topology_changed );
183+ mongoc_topology_set_apm_callbacks (topology , callbacks , & num_calls );
184+
185+ sd = _sd_for_host (td , "host" );
186+ mongoc_topology_description_handle_ismaster (
187+ td ,
188+ sd -> id ,
189+ tmp_bson ("{'ok': 1, 'topologyVersion': " TV_2 " }" ),
190+ 100 ,
191+ NULL );
192+
193+ ASSERT_CMPINT (num_calls , = = , 1 );
194+
195+ /* The subsequent ismaster has a topologyVersion that compares less, so the
196+ * ismaster skips. */
197+ mongoc_topology_description_handle_ismaster (
198+ td ,
199+ sd -> id ,
200+ tmp_bson ("{'ok': 1, 'topologyVersion': " TV_1 " }" ),
201+ 100 ,
202+ NULL );
203+
204+ ASSERT_CMPINT (num_calls , = = , 1 );
205+
206+ mongoc_apm_callbacks_destroy (callbacks );
207+ mongoc_topology_destroy (topology );
208+ mongoc_uri_destroy (uri );
209+ }
152210
153211void
154212test_topology_description_install (TestSuite * suite )
@@ -160,4 +218,7 @@ test_topology_description_install (TestSuite *suite)
160218 "/TopologyDescription/readable_writable/pooled" ,
161219 test_has_readable_writable_server_pooled );
162220 TestSuite_Add (suite , "/TopologyDescription/get_servers" , test_get_servers );
221+ TestSuite_Add (suite ,
222+ "/TopologyDescription/topology_version_equal" ,
223+ test_topology_version_equal );
163224}
0 commit comments