Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify OpenQA::WebAPI::Controller::Admin::Needle and enhance tests #2825

Merged
merged 3 commits into from Mar 21, 2020

Conversation

okurz
Copy link
Member

@okurz okurz commented Mar 11, 2020

@okurz okurz force-pushed the enhance/needle_admin_view branch from 38f63bc to 84deae9 Compare March 11, 2020 18:50
lib/OpenQA/WebAPI/Controller/Admin/Needle.pm Outdated Show resolved Hide resolved
lib/OpenQA/WebAPI/Controller/Admin/Needle.pm Outdated Show resolved Hide resolved
$dir = {
real_path => $dir_real_path,
real_path_id => $real_path_id,
};
Copy link
Contributor

Choose a reason for hiding this comment

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

this value should be stored in $paths and used for next search.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we do this correctly because $dir is a reference to an element within $paths.

Copy link
Contributor

Choose a reason for hiding this comment

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

if I did a test about this correctly, the $dir is an undef in this else block, so the $dir = {} is not added into $paths

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you have an idea how to test this better? The automatic test is passed and also NYTProf shows the same amount of readlink calls.

Copy link
Contributor

Choose a reason for hiding this comment

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

I did the test in my local test environment. I added some log message in the else block and found the $paths was always empty.
In my test, the picture1 shows that, if we use $dir->{}, the realpath will be called 25 times. If we add the value to $paths->{$dir_path} = {} directly, the realpath will be called 1 time. BTW, the needle page loads 25 needles at one time and all of them are belong to one needle directory which is a symlink.
picture1
picture2

Copy link
Member Author

Choose a reason for hiding this comment

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

I managed to come up to this story. Thanks for sharing your information. This helps as reference.

I gathered coverage from runs of t/ui/21-admin-needles.t and found 5 vs. 18 calls of reallink in case of my "broken" code and the fixed code.

I pushed the fix.

@okurz okurz force-pushed the enhance/needle_admin_view branch from 84deae9 to 6b52365 Compare March 12, 2020 07:45
return \@data;
my $needle_dirs = $self->schema->resultset('NeedleDirs');
my $needles = $self->schema->resultset('Needles');
my %paths = {};
Copy link
Contributor

@Amrysliu Amrysliu Mar 13, 2020

Choose a reason for hiding this comment

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

maybe this hash should be written my %paths = ();

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, just write it as my %paths; without any assignment. There's no such thing as an uninitialized hash in Perl; you always get an empty/default-initialized one.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

When running tests on a pristine working copy the '$needle_dir' did not
exist failing the test. This commit ensures the directory tree to exist
and also simplifies the content writing.
When the Selenium error handler catches errors it can be repeated a
thousand time polluting the console scrollback buffer so that the root
cause problem can not be found. This commit changes the call from "fail"
to "BAIL_OUT" to abort the test run early.

So instead of this:

```
not ok 1 - executeScript: unexpected alert open: {Alert text : DataTables warning: table id=needles - Ajax error. For more information about this error, please see http://datatables.net/tn/7}
…
not ok 998 - executeScript: unexpected alert open: {Alert text : DataTables warning: table id=needles - Ajax error. For more information about this error, please see http://datatables.net/tn/7}
not ok 999 - executeScript: unexpected alert open: {Alert text : DataTables warning: table id=needles - Ajax error. For more information about this error, please see http://datatables.net/tn/7}
```

have this:

```
Bailout called.  Further testing stopped:  executeScript: unexpected alert open: {Alert text : DataTables warning: table id=needles - Ajax error. For more information about this error, please see http://datatables.net/tn/7}
Bail out!  executeScript: unexpected alert open: {Alert text : DataTables warning: table id=needles - Ajax error. For more information about this error, please see http://datatables.net/tn/7}
FAILED--Further testing stopped: executeScript: unexpected alert open: {Alert text : DataTables warning: table id=needles - Ajax error. For more information about this error, please see http://datatables.net/tn/7} at ../lib/OpenQA/SeleniumTest.pm line 107.
```
By pulling out a function we can reduce the length of the "ajax" method
and replace the explicit while loop with a map call which can even be
more efficient.
@okurz okurz force-pushed the enhance/needle_admin_view branch 2 times, most recently from e95de0c to e6651b9 Compare March 21, 2020 14:05
@okurz okurz merged commit d69ed48 into os-autoinst:master Mar 21, 2020
@okurz okurz deleted the enhance/needle_admin_view branch March 21, 2020 20:47
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.

None yet

3 participants