/** check the normal scenario works */
 @Test(timeout = 1000)
 public void basic() {
   // should work
   MockedRequestHandler newSessionRequest = GridHelper.createNewSessionHandler(registry, ff);
   newSessionRequest.process();
   TestSession s = newSessionRequest.getSession();
   assertNotNull(s);
   registry.terminate(s, SessionTerminationReason.CLIENT_STOPPED_SESSION);
   assertEquals(0, registry.getNewSessionRequestCount());
 }
  /**
   * check that a crashes during the new session request handling doesn't result in a corrupted
   * state
   */
  @Test(timeout = 1000)
  public void requestIsremovedFromTheQeueAfterItcrashes() throws InterruptedException {
    // should work
    try {
      SeleniumBasedRequest newSession =
          GridHelper.createNewSessionRequest(registry, SeleniumProtocol.WebDriver, ff);
      MockedRequestHandler newSessionRequest =
          new MockedBuggyNewSessionRequestHandler(newSession, null, registry);
      newSessionRequest.process();
    } catch (RuntimeException e) {
      System.out.println(e.getMessage());
    }

    assertEquals(0, registry.getNewSessionRequestCount());
  }
Esempio n. 3
0
  @Test(timeout = 10000)
  public void method() throws InterruptedException {

    final List<TestSession> sessions = new CopyOnWriteArrayList<TestSession>();

    for (int i = 0; i < MAX; i++) {
      new Thread(
              new Runnable() { // Thread safety reviewed
                public void run() {
                  RequestHandler newSessionRequest =
                      GridHelper.createNewSessionHandler(registry, ie);
                  newSessionRequest.process();
                  TestSession session = newSessionRequest.getSession();
                  inc();
                  sessions.add(session);
                }
              })
          .start();
    }

    for (int i = 0; i < MAX; i++) {
      new Thread(
              new Runnable() { // Thread safety reviewed
                public void run() {
                  RequestHandler newSessionRequest =
                      GridHelper.createNewSessionHandler(registry, ff);
                  newSessionRequest.process();
                  TestSession session = newSessionRequest.getSession();
                  inc();
                  sessions.add(session);
                }
              })
          .start();
    }

    // 2 run on the hub.
    while (registry.getActiveSessions().size() != 2) {
      Thread.sleep(50);
    }

    // while the rest waits.
    while (registry.getNewSessionRequestCount() != 18) {
      Thread.sleep(50);
    }

    int stopped = 0;
    // all the tests ran via the registry.
    while (stopped < 2 * MAX) {
      for (TestSession session : sessions) {
        RequestHandler stopSessionRequest = GridHelper.createStopSessionHandler(registry, session);
        stopSessionRequest.process();
        stopped++;
        sessions.remove(session);
      }
    }
    // all request got the stop session request
    assertEquals(2 * MAX, stopped);
    // nothing left waiting
    assertEquals(0, registry.getNewSessionRequestCount());

    // nothing active. Waiting in case a stopSessionRequest.process() isn't finish. It's async.
    while (registry.getActiveSessions().size() != 0) {
      Thread.sleep(10);
    }
    assertEquals(0, registry.getActiveSessions().size());

    // everything was started.
    assertEquals(2 * MAX, ran);
  }