kaisun2000 commented on a change in pull request #1295:
URL: https://github.com/apache/helix/pull/1295#discussion_r483316097
##########
File path:
zookeeper-api/src/test/java/org/apache/helix/zookeeper/impl/client/TestRawZkClient.java
##########
@@ -285,18 +285,26 @@ public void testZkClientMonitor()
Assert.assertTrue(beanServer.isRegistered(idealStatename));
Assert.assertEquals((long) beanServer.getAttribute(name,
"DataChangeEventCounter"), 0);
- Assert.assertEquals((long) beanServer.getAttribute(name,
"StateChangeEventCounter"), 0);
+ Assert.assertEquals((long) beanServer.getAttribute(name,
"StateChangeEventCounter"), 1);
Assert.assertEquals((long) beanServer.getAttribute(name,
"ExpiredSessionCounter"), 0);
Assert.assertEquals((long) beanServer.getAttribute(name,
"OutstandingRequestGauge"), 0);
// account for doAsyncSync()
Assert.assertEquals((long) beanServer.getAttribute(name,
"TotalCallbackCounter"), 1);
- // Test exists
- Assert.assertEquals((long) beanServer.getAttribute(rootname,
"ReadCounter"), 0);
- Assert.assertEquals((long) beanServer.getAttribute(rootname,
"ReadTotalLatencyCounter"), 0);
- Assert.assertEquals((long) beanServer.getAttribute(rootname,
"ReadLatencyGauge.Max"), 0);
- zkClient.exists(TEST_ROOT);
+ // Note, we need to wait here for the reason that doAsyncSync() blocks
only the zkClient event thread. The main
+ // thread of zkClient would issue exits(TEST_ROOT) without blocking. The
return of doAsyncSync() would be asyc
+ // to main thread. doAsyncSync() is a source of 1 read and main thread
exists(TEST_ROOT) would be another.
+ TestHelper.verify(()->{
+ return
((org.apache.helix.zookeeper.zkclient.ZkClient)zkClient).getSyncStatus();
+ }, TestHelper.WAIT_DURATION);
+
Assert.assertEquals((long) beanServer.getAttribute(rootname,
"ReadCounter"), 1);
+ //Assert.assertEquals((long) beanServer.getAttribute(rootname,
"ReadTotalLatencyCounter"), 1);
Review comment:
Unfortunately, you can't or you have race condition in this case, if my
understanding is right. Let me illustrate:
doAsycSync(), when the success code returns, it would increase by read
counter one from the asyncThread in the ZkClient.
Note, the main thread running `zkClient.exist(Test_Root )` would increase
read counter synchronously from main thread.
The problem is that the doAsynSync() increase to read counter is totally
async to the main thread. It is the case that after main thread finish
`zkClient.exist(Test_Root )`, the doAsyncSync() would finish for sure. Recent
github test actually illustrate this point. Previous we don't realize as it did
not happen.
In fact, theoretically, the doAsyncSync() increase can happen a lot later
too.
Let me know if there is other ways you think that we can make the test
stable while also no need to use getSyncStatus().
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]