You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@uniffle.apache.org by GitBox <gi...@apache.org> on 2022/09/06 11:20:00 UTC

[GitHub] [incubator-uniffle] LuciferYang commented on a diff in pull request #203: [WIP][ISSUE-144] Fix flaky test `RssShuffleUtilsTest#testDestroyDirectByteBuffer`

LuciferYang commented on code in PR #203:
URL: https://github.com/apache/incubator-uniffle/pull/203#discussion_r963585918


##########
common/src/test/java/org/apache/uniffle/common/RssShuffleUtilsTest.java:
##########
@@ -57,9 +60,19 @@ public void testDestroyDirectByteBuffer() throws Exception {
       byteBuffer.put(b);
     }
     byteBuffer.flip();
+
+    // Get valid native pointer through `address` in `DirectByteBuffer`
+    Unsafe unsafe = getUnsafe();
+    long addressInByteBuffer = address(byteBuffer);
+    long originalAddress = unsafe.getAddress(addressInByteBuffer);
+
     RssShuffleUtils.destroyDirectByteBuffer(byteBuffer);
+
     // The memory may not be released fast enough.
-    Thread.sleep(200);
+    // If native pointer changes, `address` in `DirectByteBuffer` is invalid
+    while (unsafe.getAddress(addressInByteBuffer) == originalAddress) {

Review Comment:
   ```java
   /**
        * Fetches a native pointer from a given memory address.  If the address is
        * zero, or does not point into a block obtained from {@link
        * #allocateMemory}, the results are undefined.
        *
        * <p> If the native pointer is less than 64 bits wide, it is extended as
        * an unsigned number to a Java long.  The pointer may be indexed by any
        * given byte offset, simply by adding that offset (as a simple integer) to
        * the long representing the pointer.  The number of bytes actually read
        * from the target address maybe determined by consulting {@link
        * #addressSize}.
        *
        * @see #allocateMemory
        */
       public native long getAddress(long address);
   ```



-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@uniffle.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@uniffle.apache.org
For additional commands, e-mail: issues-help@uniffle.apache.org