예제 #1
0
 // Verify that the list of event logs have the specified event type. Print the specified failure
 // message if the
 // assertion on the event type fails.
 public static void verifyEventTypeForEventsLogs(
     List<EventLog> eventLogs, TestNgRunEvent event, String failMessage) {
   for (EventLog eventLog : eventLogs) {
     assertTrue(eventLog.getEvent() == event, failMessage);
   }
 }
예제 #2
0
  public static void verifyParallelSuitesWithUnequalExecutionTimes(
      List<EventLog> suiteLevelEventLogs, int threadPoolSize) {

    Map<String, EventLog> suitesExecuting = new HashMap<>();
    Map<String, EventLog> suitesCompleted = new HashMap<>();

    List<Long> executingSuiteThreadIds = new ArrayList<>();

    if (suiteLevelEventLogs.size() > 2) {
      int offset =
          suiteLevelEventLogs.size() >= 2 * threadPoolSize
              ? threadPoolSize
              : suiteLevelEventLogs.size() / 2;

      List<EventLog> suiteListenerStartEventLogs = suiteLevelEventLogs.subList(0, offset);

      verifyFirstBlockOfSimultaneouslyExecutingSuites(suiteListenerStartEventLogs, threadPoolSize);

      for (EventLog eventLog : suiteListenerStartEventLogs) {
        suitesExecuting.put((String) eventLog.getData(SUITE_NAME), eventLog);
        executingSuiteThreadIds.add(eventLog.getThreadId());
      }

      for (int i = offset; i < suiteLevelEventLogs.size(); i++) {

        EventLog eventLog = suiteLevelEventLogs.get(i);
        String suiteName = (String) eventLog.getData(SUITE_NAME);

        if (eventLog.getEvent() == LISTENER_SUITE_START) {
          if (suitesExecuting.keySet().size() == threadPoolSize) {
            fail(
                "The thread pool size is "
                    + threadPoolSize
                    + ", so there should be no more than "
                    + threadPoolSize
                    + " suites executing at the same time: "
                    + suiteLevelEventLogs);
          }

          assertFalse(
              suitesExecuting.get(suiteName) != null || suitesCompleted.get(suiteName) != null,
              "There should only be one execution of any given suite");
          assertFalse(
              executingSuiteThreadIds.contains(eventLog.getThreadId()),
              "Event logs for currently " + "executing suites should have different thread IDs");

          suitesExecuting.put(suiteName, eventLog);
          executingSuiteThreadIds.add(eventLog.getThreadId());

          if (suitesCompleted.size() > 0) {
            EventLog priorEventLog = suiteLevelEventLogs.get(i - 1);

            assertEquals(
                priorEventLog.getEvent(),
                LISTENER_SUITE_FINISH,
                "When suites are executing in "
                    + "parallel and a new suite begins execution when the active thread count was last "
                    + "known to be equal to the maximum thread pool size, the previously logged suite "
                    + "level event should be a suite listener onFinish event.");
          }
        }

        if (suitesExecuting.keySet().size() < threadPoolSize
            && suiteLevelEventLogs.size() - i + 1 > threadPoolSize) {
          fail(
              "The thread pool size is "
                  + threadPoolSize
                  + ", so there should be at least "
                  + threadPoolSize
                  + " suites executing at the same time unless there are no suites left to "
                  + "queue and the final block of suites is currently in execution: "
                  + suiteLevelEventLogs);
        }

        if (eventLog.getEvent() == LISTENER_SUITE_FINISH) {

          assertTrue(
              suitesExecuting.get(suiteName) != null,
              "Found an event log for a suite listener "
                  + "onFinish event that does not have a corresponding event log for a suite listener "
                  + "onStart event");
          assertTrue(
              suitesExecuting.get(suiteName).getThreadId() == eventLog.getThreadId(),
              "All the "
                  + "suite level event logs for a given suite should have the same thread ID");

          suitesExecuting.remove(suiteName);
          executingSuiteThreadIds.remove(eventLog.getThreadId());
          suitesCompleted.put((String) eventLog.getData(SUITE_NAME), eventLog);
        }
      }
    }
  }