Uploaded image for project: 'HBase'
  1. HBase
  2. HBASE-4712

Document rules for writing tests

    XMLWordPrintableJSON

    Details

    • Type: Task
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 0.92.0
    • Fix Version/s: 0.94.0
    • Component/s: test
    • Labels:
      None
    • Hadoop Flags:
      Reviewed

      Description

      We saw that some tests could be improved. Documenting the general rules could help.

      Proposal:
      HBase tests are divided in three categories: small, medium and large, with corresponding JUnit categories: SmallTest, MediumTest, LargeTest
      Small tests are executed in parallel in a shared JVM. They must last less than 15 seconds. They must NOT use a cluster.
      Medium tests are executed in separate JVM. They must last less than 50 seconds. They can use a cluster. They must not fail occasionally.

      Small and medium tests must not need more than 30 minutes to run altogether.
      Small and medium tests should be executed by the developers before submitting a patch.

      Large tests are everything else. They are typically integration tests, non-regression tests for specific bugs, timeout tests, performance tests.

      Tests rules & hints are:

      • As most as possible, tests should be written as small tests.
      • All tests should be written to support parallel execution on the same machine, hence should not use shared resources as fixed ports or fixed file names.
      • All tests should be written to be as fast as possible.
      • Tests should not overlog. More than 100 lines/second makes the logs complex to read and use i/o that are hence not available for the other tests.
      • Tests can be written with HBaseTestingUtility . This class offers helper function to create a temp directory and do the cleanup, or to start a cluster.
      • Sleeps:
      • Tests should not do a 'Thread.sleep' without testing an ending condition. This allows understanding what the test is waiting for. Moreover, the test will work whatever the machine performances.
      • Sleep should be minimal to be as fast as possible. Waiting for a variable should be done in a 40ms sleep loop. Waiting for a socket operation should be done in a 200 ms sleep loop.
      • Tests using cluster:
      • Tests using a HRegion do not have to start a cluster: A region can use the local file system.
      • Start/stopping a cluster cost around 10 seconds. They should not be started per test method but per class.
      • Started cluster must be shutdown using HBaseTestingUtility#shutdownMiniCluster, which cleans the directories.
      • As most as possible, tests should use the default settings for the cluster. When they don't, they should document it. This will allow to share the cluster later.

        Attachments

        1. 4712.txt
          16 kB
          Michael Stack
        2. test-doc-cleanup.txt
          2 kB
          Michael Stack

          Issue Links

            Activity

              People

              • Assignee:
                nkeywal Nicolas Liochon
                Reporter:
                nkeywal Nicolas Liochon
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: