Skip to content

Reporting script.#14

Merged
danielbachhuber merged 11 commits intomasterfrom
report
Jul 26, 2017
Merged

Reporting script.#14
danielbachhuber merged 11 commits intomasterfrom
report

Conversation

@octalmage
Copy link
Copy Markdown
Collaborator

This PR includes the reporting script. It downloads the junit.xml results using rsync, gets the SVN revision, then processes and uploads the junit.xml as json.

Things that still need to be done:

  • Handling errors like we do failures and adding them to the JSON.
  • Authentication and attaching the results to a host. One idea: If we use application passwords, the username/password would be tied to the host which we could then attach to the results on the API side.
  • Capturing anything else we want to be submitted.

The json only includes the failures and it looks something like this:

{
	"tests": "96",
	"failures": "5",
	"errors": "0",
	"testsuites": {
		"Tests_Meta": {
			"name": "Tests_Meta",
			"tests": "18",
			"failures": "1",
			"errors": "0",
			"testcases": {
				"test_user_metadata_not_exists": {
					"name": "test_user_metadata_not_exists",
					"failure": "Tests_Meta::test_user_metadata_not_existsnFailed asserting that 8 matches expected 2.nn/home/public/test/tests/phpunit/tests/meta.php:149n"
				}
			}
		},
		"Tests_Meta_DeleteMetadata": {
			"name": "Tests_Meta_DeleteMetadata",
			"tests": "8",
			"failures": "4",
			"errors": "0",
			"testcases": {
				"test_with_falsey_meta_value_should_not_delete_all_meta": {
					"name": "test_with_falsey_meta_value_should_not_delete_all_meta",
					"failure": "Tests_Meta_DeleteMetadata::test_with_falsey_meta_value_should_not_delete_all_metanFailed asserting that two arrays are equal.n--- Expectedn+++ Actualn@@ @@n Array (n 0 => '0'n- 1 => '1'n- 2 => '2'n+ 1 => '0'n+ 2 => '1'n+ 3 => '2'n+ 4 => '2'n )nn/home/public/test/tests/phpunit/includes/testcase.php:514n/home/public/test/tests/phpunit/tests/meta/deleteMetadata.php:43n"
				},
				"test_meta_value_should_be_ignored_when_empty_string": {
					"name": "test_meta_value_should_be_ignored_when_empty_string",
					"failure": "Tests_Meta_DeleteMetadata::test_meta_value_should_be_ignored_when_empty_stringnFailed asserting that two arrays are equal.n--- Expectedn+++ Actualn@@ @@n Array (n 0 => ''n 1 => '0'n- 2 => '1'n- 3 => '2'n+ 2 => '0'n+ 3 => '0'n+ 4 => '1'n+ 5 => '1'n+ 6 => '2'n+ 7 => '2'n+ 8 => '2'n )nn/home/public/test/tests/phpunit/includes/testcase.php:514n/home/public/test/tests/phpunit/tests/meta/deleteMetadata.php:62n"
				},
				"test_meta_value_should_be_ignored_when_null": {
					"name": "test_meta_value_should_be_ignored_when_null",
					"failure": "Tests_Meta_DeleteMetadata::test_meta_value_should_be_ignored_when_nullnFailed asserting that two arrays are equal.n--- Expectedn+++ Actualn@@ @@n Array (n 0 => ''n- 1 => '0'n- 2 => '1'n- 3 => '2'n+ 1 => ''n+ 2 => '0'n+ 3 => '0'n+ 4 => '0'n+ 5 => '0'n+ 6 => '1'n+ 7 => '1'n+ 8 => '1'n+ 9 => '2'n+ 10 => '2'n+ 11 => '2'n+ 12 => '2'n )nn/home/public/test/tests/phpunit/includes/testcase.php:514n/home/public/test/tests/phpunit/tests/meta/deleteMetadata.php:78n"
				},
				"test_meta_value_should_be_ignored_when_false": {
					"name": "test_meta_value_should_be_ignored_when_false",
					"failure": "Tests_Meta_DeleteMetadata::test_meta_value_should_be_ignored_when_falsenFailed asserting that two arrays are equal.n--- Expectedn+++ Actualn@@ @@n Array (n 0 => ''n- 1 => '0'n- 2 => '1'n- 3 => '2'n+ 1 => ''n+ 2 => ''n+ 3 => '0'n+ 4 => '0'n+ 5 => '0'n+ 6 => '0'n+ 7 => '0'n+ 8 => '1'n+ 9 => '1'n+ 10 => '1'n+ 11 => '1'n+ 12 => '2'n+ 13 => '2'n+ 14 => '2'n+ 15 => '2'n+ 16 => '2'n )nn/home/public/test/tests/phpunit/includes/testcase.php:514n/home/public/test/tests/phpunit/tests/meta/deleteMetadata.php:94n"
				}
			}
		},
		"Tests_Meta_Query": {
			"name": "Tests_Meta_Query",
			"tests": "36",
			"failures": "0",
			"errors": "0",
			"testcases": []
		},
		"Tests_Meta_Register_Meta": {
			"name": "Tests_Meta_Register_Meta",
			"tests": "25",
			"failures": "0",
			"errors": "0",
			"testcases": []
		},
		"Tests_Meta_Slashes": {
			"name": "Tests_Meta_Slashes",
			"tests": "7",
			"failures": "0",
			"errors": "0",
			"testcases": []
		},
		"Tests_Meta_UpdateMetadata": {
			"name": "Tests_Meta_UpdateMetadata",
			"tests": "2",
			"failures": "0",
			"errors": "0",
			"testcases": []
		}
	}
}

report.php Outdated
log_message( 'Error uploading results' );
}

function process( $path )
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we put this in functions.php ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! Wasn't sure if we should put single use functions there, but I'll move it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Sounds good. It probably could use a slightly more verbose name too.

Copy link
Copy Markdown
Member

@danielbachhuber danielbachhuber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few things I noticed

functions.php Outdated
* @return string
*/
function get_wordpress_version( $dir ) {
$wpVersion = file_get_contents( trailingslashit( $dir ) . 'src/wp-includes/version.php' );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we want the actual changeset reported with the WordPress version? While this WordPress version includes a changeset, it doesn't get incremented very often so it's likely to be incorrect.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point, this won't get updated on commit. We get the SVN revision, so we should be able to get the changeset from that. Not sure if this will be actually useful.

report.php Outdated
$junit_location = '-e "ssh ' . $WPT_SSH_OPTIONS . '" ' . escapeshellarg( $WPT_SSH_CONNECT . ':' . $junit_location );
}

$junit_exec = 'rsync -rv ' . $junit_location . ' ./';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we copy this to $WPT_PREPARE_DIR for easy consistency?

report.php Outdated
$results = process_junit_xml( $xml );

$meta = array(
'php_version' => phpversion(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this need to be the phpversion() on the remote filesystem?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it does, we'll need to find a way to get that, probably during the testing process.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in #26 (comment)

The env.json file ends up in the same directory as junit.xml to make it easy to sync over.

report.php Outdated
if ( $success ) {
log_message( 'Results successfully uploaded' );
} else {
log_message( 'Error uploading results' );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use the error_message() helper here?

$WPT_REPORT_API_KEY = getenv( 'WPT_REPORT_API_KEY' );

log_message('Getting SVN Revision');
$rev = exec('git -C ' . escapeshellarg( $WPT_PREPARE_DIR ) . ' log -1 --pretty=%B | grep "git-svn-id:" | cut -d " " -f 2 | cut -d "@" -f 2');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use the perform_operations() helper?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perform_operations doesn't appear to return the output, so we can't get the revision from git.

cleanup.php Outdated
perform_operations( array(
'rm -rf ' . escapeshellarg( $WPT_PREPARE_DIR . '/.git' ),
'rm -r ' . escapeshellarg( $WPT_PREPARE_DIR ),
'rm ./junit.xml',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, we'd put this in the $WPT_PREPARE_DIR to reduce complexity.

composer.json Outdated
"repositories": [
{
"type": "git",
"url": "https://github.com/octalmage/wp-unit-test-api-client-php.git"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this really need to be a separate library, or can we consolidate into this repo?

For simplicity's sake, it'd be better to keep everything together if we can.

@octalmage
Copy link
Copy Markdown
Collaborator Author

@danielbachhuber made the requested changes, and removed the external dependency.

Let me know what you think!

log_message( 'Results successfully uploaded' );
} else {
error_message( 'Error uploading results' );
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be good to enrich this reporting, but it doesn't need to block merge #27

@danielbachhuber danielbachhuber merged commit 41d16fa into master Jul 26, 2017
@danielbachhuber danielbachhuber deleted the report branch July 26, 2017 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants