void runTests()

in src/main/java/org/apache/sling/testing/teleporter/client/TeleporterHttpClient.java [285:330]


    void runTests(String testSelectionPath, int testReadyTimeoutSeconds) throws MalformedURLException, IOException, MultipleFailureException {
        final String testUrl = baseUrl + "/" + testServletPath + testSelectionPath + ".junit_result";
        log.debug("Running tests: {}", testUrl);
        
        // Wait for non-404 response that signals that test bundle is ready
        final long timeout = System.currentTimeMillis() + (testReadyTimeoutSeconds * 1000L);
        final ExponentialBackoffDelay delay = new ExponentialBackoffDelay(25, 1000);
        while(true) {
            if(getHttpGetStatus(testUrl).getStatus() == 200) {
                break;
            }
            if(System.currentTimeMillis() > timeout) {
                fail("Timeout waiting for test at " + testUrl + " (" + testReadyTimeoutSeconds + " seconds)");
                break;
            }
            delay.waitNextDelay();
        }
        
        final HttpURLConnection c = setHttpTimeouts((HttpURLConnection)new URL(testUrl).openConnection());
        try {
        	setConnectionCredentials(c);
            c.setRequestMethod("POST");
            c.setUseCaches(false);
            c.setDoOutput(true);
            c.setDoInput(true);
            c.setInstanceFollowRedirects(false);
            final int status = c.getResponseCode();
            if(status != 200) {
                throw new IOException("Got status code " + status + " for " + testUrl);
            }
        
            final Result result = (Result)new ObjectInputStream(c.getInputStream()).readObject();
            if(result.getFailureCount() > 0) {
                final List<Throwable> failures = new ArrayList<Throwable>(result.getFailureCount());
                for (Failure f : result.getFailures()) {
                    failures.add(f.getException());
                }
                throw new MultipleFailureException(failures);
            }
            log.debug("POST request to run tests successful at {}", testUrl);
        } catch(ClassNotFoundException e) {
            throw new IOException("Exception reading test results:" + e, e);
        } finally {
            cleanup(c);
        }
    }