Skip to content

Cli Application Smoke Test#922

Merged
randomanderson merged 6 commits intomasterfrom
landerson/cli-test
Jul 25, 2019
Merged

Cli Application Smoke Test#922
randomanderson merged 6 commits intomasterfrom
landerson/cli-test

Conversation

@randomanderson
Copy link
Contributor

This adds a smoke test that ensures CLI applications correctly exit when running under the java agent. There are 2 parts:

  1. A simple cli application that quits after a delay
  2. The smoke test that checks to make sure that the cli application exits

I also manually tested and ensured that the test failed when JMXFetch.daemon = false. This was the issue that prompted the creation of the test.

simple cli application and test
@randomanderson randomanderson requested a review from a team as a code owner July 18, 2019 15:21
def conditions = new PollingConditions(timeout: INSTRUMENTATION_DELAY, initialDelay: SHUTDOWN_DELAY)

expect:
serverProcess.isAlive()
Copy link
Contributor

Choose a reason for hiding this comment

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

This is 'racy'. You may want to consider making your test app exist with some 'special' exit code on success and check for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. A correct exit code covers both start and stop of the process.

isAlive() isn't available in JDK7 anyway.


System.out.println("Going to shut down after " + delay + "seconds");

Thread.sleep(delay * 1000);
Copy link
Contributor

Choose a reason for hiding this comment

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

You may want to have some loop with with some @Trace or something to make sure tracer actually gets triggered and all things are initialized.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Testing that traces were written is not quite possible with the current setup of the smoke tests. That said, I added some more to the CliApplication so its closer to the original application that exposed the shutdown issue: making a request using URLConnection then quitting.

Copy link
Contributor

Choose a reason for hiding this comment

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

Testing that traces were written is not quite possible with the current setup of the smoke tests.

You could potentially fire up a server and pass it as an agent url... but maybe not this time :)

@tylerbenson
Copy link
Contributor

Copy link
Member

@labbati labbati left a comment

Choose a reason for hiding this comment

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

Laplie great work on this. Just one comment: can we make sure that when JmxFetch is enabled the process shutsdown? What I observed is that I had to put some sleep (e.g. 5 seconds) in order to make sure that JmxFetch processes that were causing the app to hang were all fired up.

I don't think that there is easy to implement programmatic way to make sure that such processes have actually started, so heuristically sleep for 5 secs should be good.

Also, in your local tests (not in CI) might you make sure that rebasing your test on latest release (so not on master which includes the jmxfetch fix) the test actually fails?

Last but not least, please add the label dev/testing and assign this PR to the next milestone.

@randomanderson randomanderson added this to the 0.31.0 milestone Jul 19, 2019
@randomanderson
Copy link
Contributor Author

randomanderson commented Jul 19, 2019

@tylerbenson Yes commenting out .daemon(true) or setting .daemon(false) in JMXFetch both fail the test.

@labbati
I added a sleep in the CliApplication because (rarely) the test didn't fail when it should. I assume it was because the JMX Processes didn't fire up completely as you mentioned. With the sleep it always failed when it was supposed to.

@randomanderson randomanderson requested a review from labbati July 22, 2019 20:04
Copy link
Member

@labbati labbati left a comment

Choose a reason for hiding this comment

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

Thanks @randomanderson for taking the time to do this extensive testing. It looks good to me 👍

public void makeRequest() {
try {
final URL url = new URL("http://www.example.com/");
final URLConnection connection = url.openConnection();
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't like making actual requests to external URLs for testing. How important is this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not important at all. Originally, I just had a Thread.sleep(). @mar-kolya commented that the application wasn't doing enough so I added the request. The test doesn't rely on the success or failure of the request.

The example gist that first showed the JMXFetch issue had a request to google.com but I don't think was necessary to show the problem.

I'm fine removing the request and going back to only having a sleep.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think I would prefer that. Sorry for the back-and-forth. @mar-kolya you ok with that?

The test still "does something" in that it has a method with a @trace annotation.  Doesn't need to call an external url
@randomanderson randomanderson merged commit b57282d into master Jul 25, 2019
@randomanderson randomanderson deleted the landerson/cli-test branch July 25, 2019 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants