Uploaded image for project: 'Ratis'
  1. Ratis
  2. RATIS-1203

Fix flaky tests caused by retryCache in TestRetryCacheMetrics.java

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • None
    • 2.0.0
    • server
    • None

    Description

      • Issue:
        • The method testRetryCacheEntryCount in TestRetryCacheMetrics.java class is flaky. Everytime when we trigger testRetryCacheHitMissCount method before testRetryCacheEntryCount, the testRetryCacheEntryCount will failed with error message: 
          [ERROR] test1RetryCacheEntryCount(org.apache.ratis.server.impl.TestRetryCacheMetrics)  Time elapsed: 0.004 s  <<< FAILURE!
          java.lang.AssertionError: expected:<1> but was:<0>
          
      • Root cause:
        • The root cause is that the variable retryCache in this class is only initialized once in @BeforeClass, and cleared only at the end of the testRetryCacheEntryCount method. But, the testRetryCacheHitMissCount doesn't clear it.
        • So, when testRetryCacheHitMissCount is triggered before testRetryCacheEntryCount, the line checkEntryCount(0); within testRetryCacheEntryCount will failed.
      • Solution:
        • Added an @After method in order to tear down retryCache after each test.
          @After
          public void tearDown() {
              retryCache.close();
              checkEntryCount(0);
          }      
        • Deleted 2 lines of code in testRetryCacheEntryCount to avoid duplication.
          retryCache.close();
          checkEntryCount(0);
          

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              KellyShao KellyShao
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 50m
                  50m