gaoyunhaii commented on a change in pull request #8925: [FLINK-12852][network] 
Fix the deadlock occured when requesting exclusive buffers
URL: https://github.com/apache/flink/pull/8925#discussion_r302078658
 
 

 ##########
 File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/io/network/buffer/NetworkBufferPoolTest.java
 ##########
 @@ -477,4 +477,46 @@ public void go() throws Exception {
                        globalPool.destroy();
                }
        }
+
+       /**
+        * Tests {@link NetworkBufferPool#requestMemorySegments()} and verifies 
it will end exceptionally
+        * when failing to acquire all the segments in the specific timeout.
+        */
+       @Test
+       public void testRequestMemorySegmentsTimeout() throws Exception {
+               final int numBuffers = 10;
+               final int numberOfSegmentsToRequest = 2;
+               final long requestSegmentsTimeoutInMillis = 1000L;
+
+               NetworkBufferPool globalPool = new NetworkBufferPool(
+                               numBuffers,
+                               128,
+                               numberOfSegmentsToRequest,
+                               requestSegmentsTimeoutInMillis);
+
+               BufferPool localBufferPool = globalPool.createBufferPool(0, 
numBuffers);
+               for (int i = 0; i < numBuffers; ++i) {
+                       localBufferPool.requestBuffer();
+               }
+
+               assertEquals(0, 
globalPool.getNumberOfAvailableMemorySegments());
+
+               CheckedThread asyncRequest = new CheckedThread() {
+                       @Override
+                       public void go() throws Exception {
+                               globalPool.requestMemorySegments();
+                       }
+               };
+
+               asyncRequest.start();
+
+               try {
+                       asyncRequest.trySync(requestSegmentsTimeoutInMillis * 
10);
 
 Review comment:
   Agree with that the limit might cause flaky test, and changed to use forever 
sync and detect the exception with `expectedException`.

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


With regards,
Apache Git Services

Reply via email to