Skip to content

Commit

Permalink
Merge pull request #195 from woocommerce/24-08/support-qm-logs
Browse files Browse the repository at this point in the history
Support qm logs
  • Loading branch information
Luc45 authored Sep 18, 2024
2 parents cd7ef2b + 6b9c365 commit 7a6a3fa
Show file tree
Hide file tree
Showing 73 changed files with 2,191 additions and 4,458 deletions.
57 changes: 49 additions & 8 deletions _tests/managed_tests/QITSelfTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@

require_once __DIR__ . '/ProcessManagerFork.php';

// These test types cannot run in parallel.
$tests_based_on_custom_tests = [ 'activation' ];

class Context {
public static $action;
public static $test_types;
public static $running_test_based_on_custom_test;
public static $scenarios;
public static $env_filters;
public static $debug_mode;
Expand All @@ -46,10 +50,21 @@ class Context {
# Comma-separated list of test-types to run, eg: woo-e2e,woo-api
if ( isset( $params[2] ) ) {
Context::$test_types = array_map( 'trim', explode( ',', $params[2] ) );

if ( count( Context::$test_types ) > 1 ) {
foreach ( $tests_based_on_custom_tests as $custom_test ) {
if ( in_array( $custom_test, Context::$test_types, true ) ) {
echo "Cannot run tests based on custom tests in parallel with other tests.\n";
die( 1 );
}
}
}
} else {
Context::$test_types = null;
}

Context::$running_test_based_on_custom_test = ! is_null( Context::$test_types ) && count( array_intersect( Context::$test_types, $tests_based_on_custom_tests ) ) > 0;

# Comma-separated list of scenarios to run, eg: no_op,no_op_php82,delete_products
if ( isset( $params[3] ) ) {
Context::$scenarios = array_map( 'trim', explode( ',', $params[3] ) );
Expand Down Expand Up @@ -111,6 +126,16 @@ class Context {
$test_types = array_filter( $test_types, function ( $test_type_path ) {
return in_array( basename( $test_type_path ), Context::$test_types, true );
} );
} else {
// Remove tests based on custom tests if no specific test type is defined.
$test_types = array_filter( $test_types, function ( $test_type_path ) use ( $tests_based_on_custom_tests ) {
return ! in_array( basename( $test_type_path ), $tests_based_on_custom_tests, true );
} );

// If anything is removed, print what was removed.
if ( count( $test_types ) !== count( get_test_types() ) ) {
$GLOBALS['parallelOutput']->addRawOutput( sprintf( "Skipping tests based on custom tests, which must run in a dedicated process: \n - %s", implode( "\n - ", array_map( 'basename', array_diff( get_test_types(), $test_types ) ) ) ) );
}
}

if ( getenv( 'QIT_SKIP_E2E' ) === 'yes' ) {
Expand All @@ -123,7 +148,7 @@ class Context {
throw new Exception( 'No test types found.' );
}

run_test_runs( generate_test_runs( $test_types ) );
run_test_runs( generate_test_runs( $test_types ), $tests_based_on_custom_tests );
} catch ( \Exception $e ) {
if ( isset( $GLOBALS['parallelOutput'] ) && $GLOBALS['parallelOutput'] instanceof ParallelOutput ) {
$GLOBALS['parallelOutput']->addRawOutput( $e->getMessage() );
Expand Down Expand Up @@ -304,7 +329,7 @@ function copy_task_id_to_process( Process $process_with_task_id, Process $proces
$process_without_task_id->setEnv( array_merge( $process_without_task_id->getEnv(), [ 'qit_task_id' => $process_with_task_id->getEnv()['qit_task_id'] ] ) );
}

function run_test_runs( array $test_runs ) {
function run_test_runs( array $test_runs, $tests_based_on_custom_tests ) {
foreach ( $test_runs as $test_type => &$test_type_test_runs ) {
generate_zips( $test_type_test_runs );
}
Expand All @@ -315,13 +340,11 @@ function run_test_runs( array $test_runs ) {
foreach ( $test_runs as $test_type => &$test_type_test_runs ) {
foreach ( $test_type_test_runs as &$t ) {
$php = ( new PhpExecutableFinder() )->find( false );
$qit = realpath( __DIR__ . '/../../qit' );
$qit = realpath( __DIR__ . '/../../src/qit-cli.php' );
$sut_slug = $t['sut_slug'];

$args = [
$php,
'-d',
'xdebug.mode=off',
// Run QIT with Xdebug disabled to avoid "Max concurrent settings" on PHPStorm from bottlenecking parallelism.
$qit,
"run:$test_type",
Expand All @@ -342,11 +365,23 @@ function run_test_runs( array $test_runs ) {
}

if ( ! empty( $t['wp'] ) ) {
$args[] = "--wordpress_version={$t['wp']}";
if ( in_array( $test_type, $tests_based_on_custom_tests ) ) {
$args[] = "--wp={$t['wp']}";
} else {
$args[] = "--wordpress_version={$t['wp']}";
}
}

if ( ! empty( $t['woo'] ) ) {
$args[] = "--woocommerce_version={$t['woo']}";
if ( in_array( $test_type, $tests_based_on_custom_tests ) ) {
$args[] = "--woo={$t['woo']}";
} else {
$args[] = "--woocommerce_version={$t['woo']}";
}
}

if ( in_array( $test_type, $tests_based_on_custom_tests ) ) {
$args[] = "--no_upload_report";
}

if ( ! empty( $t['features'] ) ) {
Expand Down Expand Up @@ -429,7 +464,9 @@ function run_test_runs( array $test_runs ) {
$json_buffer = [];
$failed_tests = [];

$qit_run_processes_manager->runParallel( $qit_run_processes, 20, 10000, function ( string $type, string $out, Process $process ) use ( &$failed_tests, &$json_buffer ) {
$max_parallel = Context::$running_test_based_on_custom_test ? 1 : 20;

$qit_run_processes_manager->runParallel( $qit_run_processes, $max_parallel, 10000, function ( string $type, string $out, Process $process ) use ( &$failed_tests, &$json_buffer ) {
/*
* Callback function for handling process output.
* Outputs are chunked to 16kb, requiring special handling for large JSON outputs.
Expand Down Expand Up @@ -561,6 +598,9 @@ function handle_qit_response( Process $qit_process, string $out, array &$failed_
}

$phpunit_process = new Process( $args );
$phpunit_process->setTimeout(1200);
$phpunit_process->setIdleTimeout(1200);


copy_task_id_to_process( $qit_process, $phpunit_process );

Expand All @@ -571,6 +611,7 @@ function handle_qit_response( Process $qit_process, string $out, array &$failed_
$GLOBALS['parallelOutput']->processOutputCallback( $phpunit_process->getOutput(), $phpunit_process );
} catch ( ProcessFailedException $e ) {
$failed_tests[] = $e;
$GLOBALS['parallelOutput']->processOutputCallback( $phpunit_process->getOutput(), $phpunit_process );
} finally {
$qit_process->setEnv( array_merge( $qit_process->getEnv(), [ 'QIT_RAN_TEST' => true, ] ) );
}
Expand Down
2 changes: 1 addition & 1 deletion _tests/managed_tests/activation/generic/env.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
return [
'php' => '7.4',
'wp' => 'rc',
'woo' => 'rc,stable',
'woo' => 'rc',
];
6 changes: 0 additions & 6 deletions _tests/managed_tests/activation/genericphp74wp62/env.php

This file was deleted.

This file was deleted.

This file was deleted.

6 changes: 0 additions & 6 deletions _tests/managed_tests/activation/php81/env.php

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion _tests/managed_tests/activation/php82/env.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
return [
'php' => '8.2',
'wp' => 'rc',
'woo' => 'rc,stable',
'woo' => 'rc',
];
Loading

0 comments on commit 7a6a3fa

Please sign in to comment.